User:Hilst/Scripts/scriptManager
Description | Selectively run your scripts on the fly |
---|---|
Author(s) | Hilst, based on code by MusikAnimal |
Status | Stable |
First released | May 1, 2023 |
Updated | July 20, 2024 |
Browsers | Any |
Skins | User:Eejit43/skin-support |
Source | User:Hilst/Scripts/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[a] and/or being ran in it's entirety. This is especially a problem with slower connection speeds and internet plans with limited data.[b]
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.
This script is a modified version of MusikAnimal's scriptManager. It adds support for more skins and uses mw:Bubble notifications to indicate that a script was enabled successfully.
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:Hilst/Scripts/scriptManager.js'); // Backlink: [[User:Hilst/Scripts/scriptManager.js]]
Or to use scriptManager on all Wikimedia projects add the following to meta:Special:MyPage/global.js:
// Linkback: [[:w:en:User:Hilst/Scripts/scriptManager]]
importScriptURI('//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Hilst/Scripts/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:Hilst/Scripts/scriptManager.js'); // Backlink: [[User:Hilst/Scripts/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:Hilst/Scripts/scriptManager.js'); // Backlink: [[User:Hilst/Scripts/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:
window.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:
window.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:Hilst/Scripts/scriptManager.js'); // Backlink: [[User:Hilst/Scripts/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. Or alternatively, contact User:MusikAnimal, who created the original script this is based on.