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
168
votes
5 answers

Manually adding a Userscript to Google Chrome

Instead of "installing" User-Scripts I found many tutorials on the web to add it manually. All of them told me to do the same steps: Make the directory C:\Users\Blabla\AppData\Local\Google\Chrome\User Data\Default\User Scripts Place a .js file…
YMMD
  • 3,730
  • 2
  • 32
  • 43
164
votes
5 answers

Using ECMAScript 6

I'm looking for a way to run ECMAScript 6 code in my browser's console but most browsers don't support functionality that I'm looking for. For example Firefox is the only browser that supports arrow functions. Is there a way (extension, userscript,…
Spedwards
  • 4,167
  • 16
  • 49
  • 106
161
votes
11 answers

How can I use jQuery in Greasemonkey scripts in Google Chrome?

As some of you may know, Google Chrome has put some severe limitation on Greasemonkey scripts. Chromium does not support @require, @resource, unsafeWindow, GM_registerMenuCommand, GM_setValue, or GM_getValue. Without require, I can't find a way to…
Alekc
  • 4,682
  • 6
  • 32
  • 35
150
votes
14 answers

Stop an input field in a form from being submitted

I'm writing some javascript (a greasemonkey/userscript) that will insert some input fields into a form on a website. The thing is, I don't want those input fields to affect the form in any way, I don't want them to be submitted when the form is…
Acorn
  • 49,061
  • 27
  • 133
  • 172
126
votes
8 answers

Uncaught ReferenceError: function is not defined with onclick

I'm trying to make a userscript for a website to add custom emotes. However, I've been getting a lot of errors. Here is the function: function saveEmotes() { removeLineBreaks(); EmoteNameLines = EmoteName.value.split("\n"); EmoteURLLines…
ECMAScript
  • 4,439
  • 4
  • 21
  • 29
91
votes
3 answers

Is there any way of passing additional data via custom events?

I need to pass data between two autonomic user scripts - ideally without touching the unsafeWindow object - and I thought using custom events would be the way to go. I thought of something like this (let us disregard the MSIE model for the purpose…
Witiko
  • 3,167
  • 3
  • 25
  • 43
90
votes
4 answers

What is the Greasemonkey namespace needed for?

I'm learning how to use Greasemonkey, and was wondering what the @namespace metadata id is for. Does it have to be a web address? Or can it be a folder/directory on my computer? Does it even need to be filled in?
Nope
  • 34,682
  • 42
  • 94
  • 119
72
votes
14 answers

Removing an anonymous event listener

Is there anyway to remove an event listener added like this: element.addEventListener(event, function(){/* do work here */}, false); Without replacing the element?
erikvold
  • 15,988
  • 11
  • 54
  • 98
71
votes
5 answers

Include all pages in tampermonkey(userscript)

I have to include all sites in tampermonkey..this is the script that i have to run // ==UserScript== // @name Phishing Blockz // @namespace http://use.i.E.your.homepage/ // @version 0.1 // @description Phishing block based on hyperlinks //…
user1972757
  • 721
  • 1
  • 5
  • 6
69
votes
3 answers

Simulating a mousedown, click, mouseup sequence in Tampermonkey?

I would like to simulate a whole click not just document.getElementsByClassName()[0].click(); How do I do that? Search results all seem to be about handling such events, not triggering them.
67
votes
2 answers

How to change a class CSS with a Greasemonkey/Tampermonkey script?

I'm trying to set the background image of the body, but only where it uses the class banner_url. The HTML is as follows: Basically, I would like to force the page to use…
Xeo
  • 831
  • 2
  • 10
  • 14
60
votes
2 answers

What is the difference between @include and @match in userscripts?

The GreaseSpot page on metadata blocks says that the two are very similar but @match "sets more strict rules on what the * character means." GreaseSpot then proceeds to teach using @include, but Chrome examples like this generally seem to use…
WBT
  • 2,249
  • 3
  • 28
  • 40
60
votes
2 answers

Greasemonkey/ Tampermonkey @match for a page with parameters

I'm working on a script that must be executed in a certain page, depending on the parameters it has. The URL is like this: http://example.com/page.php?key1=value1&key2=value2&... And I need to match it when page.php has the key1=value1 among its…
noquierouser
  • 963
  • 2
  • 11
  • 25
56
votes
1 answer

Why is usage of the downloadURL & updateURL keys called unusual and how do they work?

I was reading GM's wiki to determine the difference between @downloadURL & @updateURL (which I didn't). But what confused me even more that both are unadvised: It is unusual to specify this value. Most scripts should omit it. I'm surprised by that…
ZeroUnderscoreOu
  • 679
  • 1
  • 5
  • 11
45
votes
4 answers

Injecting JS functions into the page from a Greasemonkey script on Chrome

I have a Greasemonkey script that works just fine in Firefox and Opera. I struggle with getting it to work in Chrome, however. The problem is injecting a function into the page that can be invoked by code from the page. Here's what I'm doing so…
1
2 3
86 87