A module for adding styles to pages.
npm install --save userstyle
# or
yarn add userstylefunction addStyleSheet(stylesheet: string): HTMLStyleElementAdd the string as a stylesheet to the current page and return the style element.
function createClassname(): stringCreate a unique CSS classname starting with userstyle-.
function addClassRule(classname: string, declaration: string | Partial<CSSStyleDeclaration>): HTMLStyleElementAdd the CSS declaration with classname as a style sheet to the current page and return the style element.
function bindClassToSelector(classname: string, selector: () => Iterable<Element>): () => voidAutomatically toggle the classname to elements by the selector function, also for new elements that attach in future. Return the unbind function to stop.
Elements that no longer match will remove the classname. Calling the unbind function will remove the classname.
function bindStyleToSelector(declaration: string | Partial<CSSStyleDeclaration>, selector: () => Iterable<Element>): () => voidEquivalent to:
const classname = createClassname()
addClassRule(classname, declaration)
return bindClassToSelector(classname, selector)