scriptManager.js | |
---|---|
![]() Annotated screenshot of the scriptManager portal in the sidebar | |
Description | Selectively run your scripts on the fly |
Author(s) | MusikAnimal |
Status | Stable |
Updated | November 16, 2014 |
Browser support | Any |
Skin support | Vector-2022, Vector, monobook |
Source | User: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
editAn 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
editSetup may require some basic JavaScript knowledge. However, if you follow these instructions carefully, it should work fine.
Step 1: Add scriptManager
editFirst 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
editAny 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
editHere 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
editIf 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.