GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - HatScripts/userscript-helpers: Helper functions for userscripts, bookmarklets, or wherever else you need them

BranchesTags
Open more actions menu

Latest commit

 

History

38 Commits
38 Commits

Folders and files

NameName
Last commit message
Last commit date
docs/ISSUE_TEMPLATE
docs/ISSUE_TEMPLATE
 
 
README.md
README.md
 
 
applyCss.js
applyCss.js
 
 
applyCss.min.js
applyCss.min.js
 
 
ready.js
ready.js
 
 
ready.min.js
ready.min.js
 
 
toggleCss.js
toggleCss.js
 
 
toggleCss.min.js
toggleCss.min.js
 
 

Repository files navigation

Userscript helpers

General helper functions for use in userscripts, bookmarklets, or wherever else you need them.

  • ready() - Specify a function to execute when the DOM is fully loaded.
  • applyCss() - Applies a string of CSS to the document.
  • toggleCss() - Toggles a string of CSS within the document.
  • More to come. Feel free to request a function or create a pull request.

ready()

Specify a function to execute when the DOM is fully loaded.

This function is a vanilla JavaScript equivalent to jQuery's .ready().

This function is useful if you want a part of your code to execute only after the DOM has loaded. If you want your entire script to run after the DOM has loaded, then you should instead use @run-at document-start in your metadata block.

To use it in your userscript, add this line to the metadata block:

// @require https://raw.githubusercontent.com/HatScripts/userscript-helpers/master/ready.min.js

And then call it like so:

ready(() => {
  console.log('DOM is ready')
})

applyCss()

Applies a string of CSS to the document.

This function is intended to be a more robust alternative to GM_addStyle.

To use it in your userscript, add this line to the metadata block:

// @require https://raw.githubusercontent.com/HatScripts/userscript-helpers/master/applyCss.min.js

And then call it like so:

applyCss('body { color: white; background-color: black; } img { border: 0; }')

Or with a multi-line string (ES6+):

applyCss(`
body {
  color: white;
  background-color: black;
}
img {
  border: 0;
}
`)

toggleCss()

Toggles a string of CSS within the document. If the specified CSS has not been applied to the page, it will be, else it will be removed.

To use it in your userscript, add this line to the metadata block:

// @require https://raw.githubusercontent.com/HatScripts/userscript-helpers/master/toggleCss.min.js

And then call it like so:

toggleCss('body { color: white; background-color: black; } img { border: 0; }')

Or with a multi-line string (ES6+):

toggleCss(`
body {
  color: white;
  background-color: black;
}
img {
  border: 0;
}
`)

Or with a second parameter (true or false):

toggleCss('body { color: white; }', true)  // Enables the given CSS
toggleCss('body { color: white; }', false) // Disables the given CSS

About

Helper functions for userscripts, bookmarklets, or wherever else you need them

Topics

bookmarkletdomfunctionshelper-functionsjavascriptuserscriptuserscript-helpersutility-functionvanillavanilla-javascriptvanilla-jsvanillajs

Resources

Readme
Activity

Stars

6 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.