Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NotificationsYou must be signed in to change notification settings

HatScripts/userscript-helpers

Repository files navigation

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

ready()

Specify a function to execute when theDOM is fully loaded.

This function is a vanilla JavaScript equivalent tojQuery'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 themetadata 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 toGM_addStyle.

To use it in your userscript, add this line to themetadata 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 themetadata 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 orfalse):

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

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp