Questions tagged [userscripts]

Use the Tampermonkey tag if running Tampermonkey or Violentmonkey, use the "Greasemonkey-4" tag if running that engine on Firefox. For all other engines, or multi-engine scripts, use the "Userscripts" tag. Userscripts primarily refers to JavaScript extensions for web browsers, used to automate or customize actions, the layout, or other aspects of the user experience.

Userscripts primarily refers to extensions for web browsers. Userscripts can automate or customize actions, and/or they can change the layout or even "mash up" different websites.

Userscripts are commonly installed in browsers using a userscript manager add-on/extension, but some browsers have limited native support.

On most browsers, when using a userscript manager, userscripts have access to an extended API that allows some actions that are not permitted for ordinary JavaScript code running in the page scope. However, that extended API is significantly less powerful than what's available to actual browser extensions.

Userscripts are available in most browsers:

Scripts meant for Greasemonkey or Tampermonkey should be tagged or , instead.
If the userscript is meant to be cross-browser compatible (not always worth the trouble), use both and .

Userscript API changes:
For quite some time, the APIs provided by userscript managers were reasonably cross-compatible. Those APIs were synchronous, with the exception of AJAX calls. However, Greasemonkey 4.X re-wrote the APIs it presents to userscripts such that they were asynchronous, using Promises, which makes scripts using those APIs not backwards/cross-compatible. The Greasemonkey project provides a polyfill which userscripts can @require in order to write scripts using their new APIs which will function in other userscript managers.

Tampermonkey has begun to provide support for these Promise based APIs.

Resources:

1300 questions
7
votes
2 answers

Fixing Gmail's layout with a custom style

I'm trying to make Gmail's new look usable on my small 1024x768 screen - the default layout leaves only a small window for the messages, surrounded by unmoving elements. Scrolling that small window around is massively annoying. I've managed to make…
hmp
  • 941
  • 3
  • 10
  • 27
6
votes
2 answers

How to disable div blocks having a certain id pattern?

I would like to write a greasemonkey script to disable a div on a certain page. On any given load of the page I don't know where in the DOM the div will be but I know it's always called
....
How would I go about…
user63904
6
votes
2 answers

Clicking a button on a page using a Greasemonkey/userscript in Chrome

I'm going to be as absolutely verbose here as possible as I've run into a few solutions that didn't end up panning out. Please keep in mind that I don't know Javascript. I know basic HTML and CSS. I don't have any actual programming background but…
6
votes
0 answers

User's way to disable 'prefers-color-scheme' or Dark Mode?

I've seen a ton of Q&As on this site about how programmers can turn dark mode of their web pages on and off. But how do I, as a user, disable dark mode for my browser? I'm used to having my OS set to a dark theme, but I want my browser's pages to…
Kane Green
  • 71
  • 7
6
votes
3 answers

Method for Debugging Userscripts in Chrome

I've attempted to make some modifications to a userscript to enable it to work under Chrome, but when I drag it into Chrome's window in order to install it, a dialog pops up and says 'Invalid Script Header'. I've tried to use the Developer Tools,…
VxJasonxV
  • 951
  • 11
  • 35
6
votes
2 answers

How to convert a bookmarklet into a Greasemonkey userscript?

Is there a easy way to do this. And is there anything that needs to be changed due to differences in how it is ran?
6
votes
1 answer

Are Chrome user-scripts separated from the global namespace like Greasemonkey scripts?

I know Greasemonkey scripts are automatically wrapped in anonymous functions isolated in some way in order to prevent them conflicting with scripts in the page. Does the same happen with Chrome user-scripts?
Acorn
  • 49,061
  • 27
  • 133
  • 172
6
votes
0 answers

fetch() with 'credentials: true' fails in Tampermonkey userscript in Chrome

The Cookie-header is missing when sending a credentials: true-fetch-request in a Tampermonkey userscript in Chrome even though CORS is configured correctly. What is the problem? Additional information: The same code works as expected in a…
The Wavelength
  • 2,836
  • 2
  • 25
  • 44
6
votes
1 answer

Where does Chrome store userscripts.user.js files on a mac?

i want to know where chrome stores the userscripts that are installed. i couldn't find any answer elsewhere. i'm on a mac.
plastic cloud
  • 241
  • 1
  • 4
  • 12
6
votes
3 answers

Run my JavaScript code on every page on my browser, similar to how a Chrome extension would

I know with Chrome I can use snippets to manually run some JavaScript code on a webpage. But this required manually executing the snippet. Is there a way to have some JavaScript code that my browser (Chrome or Firefox) would load every time I visit…
6
votes
1 answer

How to use service worker in user script

I want to cache specific requests in someone's website, then I find service worker a good choice. But I can't find any approach to inject a service worker by tampermonkey. So is there any hack to do this?
bilabila
  • 973
  • 1
  • 12
  • 18
6
votes
2 answers

Tampermonkey play sound when page changes?

Basically, there is a specific website I visit that I keep a userscript auto-refresh set on a timer. This specific page changes content every now and then upon being refreshed. I want a sound to be played whenever the page gets refreshed and any…
6
votes
0 answers

Is there a way to disable Safari CSP (Content Security Policy) check?

Seems like Safari has a very strong restriction on CSP. For example, on GitHub, most of the userscripts and extension doesn't work because of that. I got a such error from the console. [Error] Refused to execute a script because its hash, its…
6
votes
1 answer

How do I add a userscript installation button to my web page?

I need to host a userscript on an internal company website. How do I build the href so that Greasemonkey will install the userscript when the link is clicked? I tried a simple Install Userscript but Chrome and Firefox simply…
Aaron Mclean
  • 83
  • 1
  • 6
6
votes
1 answer

Prevent caching of @require'd files

I use @require to load a local JavaScript file shared by some of my GreaseMonkey scripts. When I change the file, GreaseMonkey continues to use the original version and does not load the new version. How can I disable the caching of the @required…