Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't rename or create more than one custom userscript script in Tampermonkey

I am currently trying to create 3 userscripts in Tampermonkey for separate pages. Using the GUI, I can click on "Add a new script", however every time I save after making changes, it re-saves over the top of 'My Fancy New Userscript' and there doesn't seem to be any way of renaming the scripts.

Perhaps I am missing something?:)

like image 898
robmunro Avatar asked May 10 '13 00:05

robmunro


People also ask

Do Greasemonkey scripts work in Tampermonkey?

Tampermonkey. Tampermonkey is one of the most popular browser extensions with over 10 million users. Tampermonkey is used to run so-called userscripts (sometimes also called Greasemonkey scripts) on websites.

How do I create a Tampermonkey script?

Tampermonkey has it's own built-in editor. Just hit the Tampermonkey button and select Dashboard. To get a new script, hit the little + tab in the upper right. You'll get a nice template with an IIFE (Immediately Invoked Function Expression) that you should put all your code in to avoid global namespace pollution.


1 Answers

The name is set by the @name directive. In Tampermonkey, there can never be more than one script with the same @name1.

Changing the name


In fact, you should examine and change, or delete, every one of the default @ directives with each new script. Most of that is clutter (most of the time), and it's poor practice to have a script run on every page like @match http://*/* specifies.

A good starter template is:

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @match    http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

Where you change the @name and @match(es) for every script.

This template also uses jQuery from the local disk (which you will want to do for any serious scripting), and is fully compatible with Greasemonkey.




1 This is actually a bit of a bug. Tampermonkey should follow the Greasemonkey model, where it's the @name + @namespace combination that has to be unique.

like image 172
Brock Adams Avatar answered Oct 11 '22 03:10

Brock Adams