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
6
votes
3 answers

Javascript: keydown event not firing

I am writing a userscript with the following code: (function() { 'use strict'; window.addEventListener("keydown", arrows, false); function arrows(e) { debugger; switch(e.keycode) { case 37: alert("Left");…
Griffin Young
  • 223
  • 1
  • 4
  • 11
6
votes
2 answers

How does GM_getTab(cb) work?

There does not appear to be any information on how these functions work. I presume these are Tampermonkey exclusive functions? It looks like they are designed to allow communication between currently running Tampermonkey scripts; An alternative to…
Jonathon
  • 2,571
  • 5
  • 28
  • 49
6
votes
0 answers

How do I inject a userscript into a site that uses CSP?

I'm currently in the process of writing a userscript for a certain website. What I'm trying to accomplish requires access to the content scope with the page variables and functions. Standard operating procedure for that sort of thing seems to be a…
a cat
  • 654
  • 1
  • 10
  • 17
6
votes
2 answers

Can I have access to anonymous function variables in a userscript?

I'm looking for modify a javascript game with an userscript. The problem is that all the game code is wrapped with a anonymous function like this (function () { "use strict"; var js = 'test'; })(); Can I have access to a JS variable with my…
A. Joahny
  • 301
  • 2
  • 14
6
votes
1 answer

Why is script.onload not working in a Chrome userscript?

I want to load another script file, in a site, using a userscript. But, the js.onload event doesn't work correctly. The userscript file: // ==UserScript== // @name Code highlight // @description Test // @include …
chunterg
  • 128
  • 1
  • 1
  • 9
6
votes
1 answer

Embed favicon using a userscript

I have a tiny script designed to change the favicon on Google Music from the Play Store icon to something actually recognizable as Music related: // ==UserScript== // @name Update Google Music Favicon // @version 1.0 // @description…
powerj1984
  • 2,216
  • 1
  • 22
  • 34
6
votes
1 answer

Chrome userscript fires on all pages despite @match and @include settings

I use match to restrict my script to work only one domain but chrome runs it in every domain. I tried @include and @match and it says "Access your data on all websites" when I try to install it and it runs it in all websites. How can I restrict…
Someone
  • 728
  • 2
  • 12
  • 23
6
votes
1 answer

how to use stylish userscript or javascript to remove this html element?

on a website i visit, i want to remove an ad-link from the page by writing script. how would i remove the ad page element? I guess the best way would be using javascript, and using a tampermonkey chrome extension to run the script.…
arboles
  • 1,321
  • 4
  • 20
  • 39
6
votes
2 answers

Refactoring a userscript to use javascript modules

I'm working on a userscript - in particular this userscript - which has been designed to encapsulate functionality in modules. In order to be able to do some automated testing I would like to split the modules into their own files and use node.js's…
cat dad
  • 218
  • 4
  • 12
6
votes
1 answer

How to compile a Google Chrome extension out of code I found at userscripts.org?

I came across this userscript which works in Google Chrome. I want to use it as Google Chrome extension as this will give me experience to convert many other codes from userscripts to Google Chrome Extensions. Can someone give me a step by step…
6
votes
2 answers

Add parameters to the URL (redirect) via a Greasemonkey/Tampermonkey/Userscript

I'd like to write a Greasemonkey/userscript that automatically adds .compact to URLs starting with https://pay.reddit.com/ so It automatically redirects me to the mobile version. I've been looking at similar userscripts, particularly this one:…
mp04
  • 160
  • 1
  • 1
  • 6
6
votes
2 answers

Chrome userscript error: "Unsafe JavaScript attempt to access frame"

// the iframe of the div I need to access var iframe = document.getElementsByTagName("iframe")[2]; var innerDoc = iframe.contentDocument || iframe.contentWindow.document; // resize 'player' in the iframe innerDoc.getElementById('player').width =…
yellow-saint
  • 884
  • 2
  • 13
  • 37
5
votes
5 answers

disable onclick ads with a content-script in Google Chrome

There are some video streaming sites that pop up an ad anytime you click anywhere on the page. The problem is, you have to click on the page to press play! So I was thinking of making a UserScript that disables the script that does this. The only…
Zayats
  • 281
  • 1
  • 4
  • 15
5
votes
1 answer

Chrome: Auto-run for Javascript code?

Does anybody know if there is some way to run a piece of Javascript code for each page that loads in a browser? Sort of like inserting