A module for adding styles to pages
npm install userstyleA module for adding styles to pages.
``sh`
npm install --save userstyleor
yarn add userstyle
`ts`
function addStyleSheet(stylesheet: string): HTMLStyleElement
Add the string as a stylesheet to the current page and return the style element.
`ts`
function createClassname(): string
Create a unique CSS classname starting with userstyle-.
`ts`
function addClassRule(classname: string, declaration: string | Partial
Add the CSS declaration with classname as a style sheet to the current page and return the style element.
`ts`
function bindClassToSelector(classname: string, selector: () => Iterable
Automatically 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.
`ts`
function bindStyleToSelector(declaration: string | Partial
Equivalent to:
`ts``
const classname = createClassname()
addClassRule(classname, declaration)
return bindClassToSelector(classname, selector)