User script
scriptManager.js
Annotated screenshot of the scriptManager portal in the sidebar
DescriptionSelectively run your scripts on the fly
Author(s)MusikAnimal
StatusStable
UpdatedNovember 16, 2014; 9 years ago (2014-11-16)
BrowsersAny
SkinsVector-2022, Vector, monobook
SourceUser:MusikAnimal/scriptManager.js

scriptManager is a script for users who use a lot of scripts. It allows you to selectively run scripts on the fly, rather than having every script ran on every page. Even if you don't use some given script, it's still being downloaded by your browser[1] and/or being ran in it's entirety. This is especially a problem with slower connection speeds and internet plans with limited data.[2]

When enabled, a new heading, "Enable scripts", will show up on your side bar. Under it will be the list of scripts you've added to scriptManager. From there, simply click on whatever script you want to enable.

Use cases

edit

An example is the ArticleInfo gadget. This awesome script is ran on every page, making an AJAX call to gather data about the page such as the number of users watching it, pageviews over the past 30 days, and other cool stuff. Some pages you don't really care what the stats are... and you're making unnecessary AJAX calls. So if you add it to scriptManager, the script will only be ran when you tell it to.

Another example is the AfC script. The "review" link only shows up on AfC submission pages, but the script is still loaded in its entirety on every page. No need for that, add it to scriptManager and enable it only when you need it.

Setup

edit

Setup may require some basic JavaScript knowledge. However, if you follow these instructions carefully, it should work fine.

Step 1: Add scriptManager

edit

First add scriptManager to your skin's JS file (such as vector.js), or to your common.js to enable scriptManager on all skins:

importScript('User:MusikAnimal/scriptManager.js'); // Backlink: [[User:MusikAnimal/scriptManager.js]]

Or to use scriptManager on all Wikimedia projects add the following to meta:Special:MyPage/global.js:

// Linkback: [[:w:en:User:MusikAnimal/scriptManager]]
mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:MusikAnimal/scriptManager.js');

Step 2: Comment out other scripts

edit

Any scripts you want to be handled with scriptManager must no longer be imported, as that will be done by scriptManager. You can simply comment out those lines of code by adding two forward slashes at the beginning of that line. Here I have my old common.js and my new one.

Before:

mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hedonil/XTools/XTools.js&action=raw&ctype=text/javascript');
importScript('MediaWiki:Gadget-afchelper.js');
importScript('User:Ohconfucius/script/MOSNUM dates.js'); // Backlink: [[User:Ohconfucius/script/MOSNUM dates.js]]
importScript('User:MusikAnimal/importWatchlist.js'); // Backlink: [[User:MusikAnimal/importWatchlist.js]]

importScript('User:MusikAnimal/scriptManager.js'); // Backlink: [[User:MusikAnimal/scriptManager.js]]

After:

// mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hedonil/XTools/XTools.js&action=raw&ctype=text/javascript');
// importScript('MediaWiki:Gadget-afchelper.js');
// importScript('User:Ohconfucius/script/MOSNUM dates.js'); // Backlink: [[User:Ohconfucius/script/MOSNUM dates.js]]
// importScript('User:MusikAnimal/importWatchlist.js'); // Backlink: [[User:MusikAnimal/importWatchlist.js]]

importScript('User:MusikAnimal/scriptManager.js'); // Backlink: [[User:MusikAnimal/scriptManager.js]]

It is recommended you keep any "backlinks" of scripts that you are using. Those let the author know how many people are using their script.

Step 3: Add scripts to scriptManager

edit

Here it is important that you get the syntax right. To add scripts to scriptManager, we will use the full URL of where the script is located (because some scripts are on different wikis). The syntax is as follows:

scriptsToManage = {
  "name of script" : "//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=Script.js",
  "name of script2" : "//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=Script2.js"
}

replacing name of script with the name of the script (you can name it whatever you want), en.wikipedia.org with the corresponding project if it's not enwiki, and Script.js with the location of the script on that project. This variable definition needs to go at the top of the JS file. Also note that this is a comma-separated list, so each entry should have a comma at the end except the last entry.

So, the above example of xtools, AfC helper, MOSNUM dates, and importWatchlist would look like this:

scriptsToManage = {
  "xtools" : "//meta.wikimedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Hedonil/XTools/XTools.js",
  "AfC helper" : "//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-afchelper.js",
  "MOSNUM dates" : "//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Ohconfucius/script/MOSNUM dates.js",
  "importWatchlist" : "//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:MusikAnimal/importWatchlist.js"
}

// mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hedonil/XTools/XTools.js&action=raw&ctype=text/javascript');
// importScript('MediaWiki:Gadget-afchelper.js');
// importScript('User:Ohconfucius/script/MOSNUM dates.js'); // Backlink: [[User:Ohconfucius/script/MOSNUM dates.js]]
// importScript('User:MusikAnimal/importWatchlist.js'); // Backlink: [[User:MusikAnimal/importWatchlist.js]]

importScript('User:MusikAnimal/scriptManager.js'); // Backlink: [[User:MusikAnimal/scriptManager.js]]

NOTE: All gadgets available in your preferences can be added to scriptManager. You'll need to disable the gadget, and instead add the source URL to scriptManager. Each gadget lives in the MediaWiki namespace. For a full list, see Special:Gadgets. Each gadget listed will have a link to the source.

Help

edit

If you need help, just contact me. I'm an interface admin and can edit your JS files, and I'm more than happy to set up scriptManager for you if you'd like.

Notes

edit
  1. ^ Technically, it might be cached, but often the script itself is still ran, which has it's toll on page load time just as downloading the script would.
  2. ^ Many scripts make AJAX calls behind the scenes.