How to edit a Userscript

Userscript Managers allow you to edit installed Userscript and save them to see them action the next time you reload the page.

This is specially useful if you want to test something out on an existing Userscript or want to learn from it!

Just keep in mind Userscript Managers may automatically update the installed Userscripts if there’s a more recent version on where they we downloaded from. Some Userscript Managers perform these update checks on a daily basis by default.

This How to starts from an already existing Userscript. You may refer to https://jaus.atlassian.net/wiki/spaces/JAUS/pages/393370 if you’re yet to install a Userscript or ….

All screenshots here were taken from Violentmonkey + Chrome + Windows.

 

Editing a Userscript’s source code

1) Access the Userscript Manager

On your browser window, click on the “extensions icon” and then click on the Userscript Manager:

Violentmonkey in Chrome extensions menu
Violentmonkey in Chrome’s extensions menu

2) Open the Userscript Manager Dashboard

Once you clicked on the Userscript Manager, select the option that opens the Dashboard:

3) Edit a Userscript

In the Dashboard, click on the source code icon “</>" of the Userscript of your choice:

4) Have fun!

The Userscript Manager will then open the Userscript’s source code:

You may edit it at will and save it. The changes will automatically take effect once you reload the respective page that the Userscript executes on. This can be done even in multi tabs: keep the Userscript source code open in a tab and keep reloading the page in another tab to see the changes right then.

Discarding the changes

An easy way to discard changes made to a Userscript through the Userscript Manager is to force the Userscript to update.

We do this by editing the @version metadata line to something like “0.0.0” and requesting the Userscript Manager to check for updates in all scripts:

You’ll see the script will show as “Script updated.” message and it’s version will get back to the one available at the location from where you installed it.

Preventing Userscript updates

In some cases you may not want to have a Userscript automatically updated.

Like editing the Userscript @version to 0.0.0 forces it to update, setting the version to a ridiculous high number, like 1000.0.0 has the opposite effect: the Userscript Manager understands you version is more recent than the repository's and doesn't update it.

Making a local copy of the Userscript

If you want to build upon an existing Userscript, you may make a copy of it.

1) Open the Userscript’s source code and copy it

2) Go back to the Dashboard and click on the add Userscript then select “New”:

3) On the source code panel that opens, replace everything that’s in there by the copied source code:

4) Edit the metadata block so the Userscript Manager handles the Userscript correctly:

// ==UserScript== // @name Choose a name for the Userscript // @namespace Namespace is just a group for the Userscripts. Can type anything here. // @version 1.0.0 // @author Your name. It shows up on the Script's header. // @description Some longer text but not too long. // @homepage URL of the Userscript/project. This line can be entirely removed. // @supportURL Can also be removed. // @license CC-BY-SA-4.0; https://creativecommons.org/licenses/by-sa/4.0/ // @match The regular expression that tells the Userscript Manager in which pages the Userscript should be executed. // @grant Import components. // @downloadURL You may delete this line // @updateURL This too. // ==/UserScript==

Refer to https://violentmonkey.github.io/api/metadata-block/ for a comprehensive list of metadata tags.

This is how the above will look in several Dashboard layouts of Violentmonkey: