https://github.com/blackglory/userstyle
🌲 A module for adding styles to pages.
https://github.com/blackglory/userstyle
browser library npm-package typescript
Last synced: 9 days ago
JSON representation
🌲 A module for adding styles to pages.
- Host: GitHub
- URL: https://github.com/blackglory/userstyle
- Owner: BlackGlory
- License: mit
- Created: 2020-06-24T15:07:30.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-06-11T06:57:21.000Z (about 3 years ago)
- Last Synced: 2025-09-28T18:38:46.595Z (9 months ago)
- Topics: browser, library, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/userstyle
- Size: 483 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# userstyle
A module for adding styles to pages.
## Install
```sh
npm install --save userstyle
# or
yarn add userstyle
```
## API
### addStyleSheet
```ts
function addStyleSheet(stylesheet: string): HTMLStyleElement
```
Add the string as a stylesheet to the current page and return the style element.
### createClassname
```ts
function createClassname(): string
```
Create a unique CSS classname starting with `userstyle-`.
### addClassRule
```ts
function addClassRule(classname: string, declaration: string | Partial): HTMLStyleElement
```
Add the CSS declaration with classname as a style sheet to the current page and return the style element.
### bindClassToSelector
```ts
function bindClassToSelector(classname: string, selector: () => Iterable): () => void
```
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.
### bindStyleToSelector
```ts
function bindStyleToSelector(declaration: string | Partial, selector: () => Iterable): () => void
```
Equivalent to:
```ts
const classname = createClassname()
addClassRule(classname, declaration)
return bindClassToSelector(classname, selector)
```