Feature summary
The concise importScript() has been deprecated, and we are encouraged to replace it with mw.loader.load(). However, consider the following:
importScript('User:Test/Scripts/Script1.js'); vs. mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Test/Scripts/Script1.js&action=raw&ctype=text/javascript');
Note the much longer URL when using mw.loader.load. 4 times as long. Cluttered with reading noise and opportunities to make subtle typos.
I am also concerned about encodeURIComponent() issues. mw.loader.load() appears to handle spaces and double quotes OK, but there may be some other characters that a user might accidentally name their page and type into mw.loader.load() without encoding.
Anyway, I propose that we create a helper function basically identical to importScript() that can be a concise alternative to mw.loader.load for loading user scripts. How about...
mw.loader.importScript(pageName);
Note that importScript() parses wiki shortcuts added to the beginning of it, e.g. the "en" in "en:User:Novem Linguae/Scripts/blahblah.js". Other than that, importScript() is similar to a shorter mw.loader.load().
Use case(s)
Benefits
- More readable
- More concise
- Less error prone
Readability example:
importScript('User:Anne drew Andrew and Drew/SetupAutoArchive.js'); importScript('User:Þjarkur/Highlight homographs in title.js'); importScript('User:Þjarkur/NeverUseMobileVersion.js'); importScript('User:Ahecht/Scripts/pageswap.js'); importScript('User:Ajbura/anrfc-lister.js'); importScript('User:Alexis Jazz/LuckyRename.js'); importScript('User:Ale_jrb/Scripts/csdhelper.js'); importScript('User:Anomie/unsignedhelper.js'); importScript('User:Awesome Aasim/xfdvote.js'); importScript('User:Bellezzasolo/Scripts/arb.js'); importScript('User:Bradv/Scripts/WhatLinksHereSnippets.js'); importScript('User:BrandonXLF/CitationStyleMarker.js'); importScript('User:BrandonXLF/HotDefaultSort.js'); importScript('User:DannyS712/copyvio-check.js'); importScript('User:DannyS712/copyvio-check.js'); importScript('User:DannyS712/DiscussionCloser.js'); importScript('User:DannyS712/Draft no cat.js'); importScript('User:DannyS712/EFFPRH.js'); importScript('User:DannyS712/SATG.js'); importScript('User:Enterprisey/AFCRHS.js'); importScript('User:Enterprisey/cv-revdel.js'); importScript('User:Enterprisey/delsort.js'); importScript('User:Enterprisey/diff-permalink.js'); importScript('User:Enterprisey/easy-brfa.js'); importScript('User:Enterprisey/offset-history-link.js'); importScript('User:Enterprisey/rfa-count-toolbar.js'); importScript('User:Enterprisey/undo-last-edit.js'); importScript('User:Evad37/duplinks-alt.js'); importScript('User:Evad37/MoveToDraft.js'); importScript('User:Evad37/OneClickArchiver.js'); importScript('User:Evad37/rater.js'); importScript('User:GeneralNotability/mark-locked.js'); importScript('User:GorillaWarfare/script/curlies.js'); importScript('User:Jonesey95/refill.js'); importScript('User:JPxG/current-switcher.js'); importScript('User:Kaniivel/RefConsolidate_start.js'); importScript('User:Kephir/gadgets/table-editor.js'); importScript('User:Mr. Stradivarius/gadgets/ConfirmRollback.js'); importScript('User:Nardog/MoveHistory.js'); importScript('User:Novem Linguae/Scripts/AddTaxobox.js'); importScript('User:Novem Linguae/Scripts/CWWEditSummary.js'); importScript('User:Novem Linguae/Scripts/DetectG4G5.js'); importScript('User:Novem Linguae/Scripts/DetectPromo.js'); importScript('User:Novem Linguae/Scripts/GANReviewTool.js'); importScript('User:Novem Linguae/Scripts/TemplateTaxonomyAddCite.js'); importScript('User:Novem Linguae/Scripts/UserRightsDiff.js'); importScript('User:Ohconfucius/script/MOSNUM dates.js'); importScript('User:Pythoncoder/Scripts/voteSymbols.js'); importScript('user:Qwertyytrewqqwerty/DisamAssist.js'); importScript('User:SD0001/DYK-helper.js'); importScript('User:SD0001/GAN-helper.js'); importScript('User:SD0001/StubSorter.js'); importScript('User:Shubinator/DYKcheck.js'); importScript('User:Suffusion of Yellow/filter-highlighter.js'); importScript('User:Suffusion of Yellow/filterNotes.js'); importScript('User:Terasail/COI Request Tool.js'); importScript('User:Terasail/Edit Request Tool.js'); importScript('User:TheTVExpert/rmCloser.js'); importScript('User:Writ Keeper/Scripts/deletionFinder.js');
vs.
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Anne_drew_Andrew_and_Drew/SetupAutoArchive.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Þjarkur/Highlight_homographs_in_title.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Þjarkur/NeverUseMobileVersion.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Ahecht/Scripts/pageswap.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Ajbura/anrfc-lister.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Alexis_Jazz/LuckyRename.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Ale_jrb/Scripts/csdhelper.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Anomie/unsignedhelper.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Awesome_Aasim/xfdvote.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Bellezzasolo/Scripts/arb.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Bradv/Scripts/WhatLinksHereSnippets.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/CitationStyleMarker.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/HotDefaultSort.js&action=raw&ctype=text/javascript'); importScript('User:DannyS712/copyvio-check.js');_ mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:DannyS712/copyvio-check.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:DannyS712/DiscussionCloser.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:DannyS712/Draft_no_cat.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:DannyS712/EFFPRH.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:DannyS712/SATG.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/AFCRHS.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/cv-revdel.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/delsort.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/diff-permalink.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/easy-brfa.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/offset-history-link.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/rfa-count-toolbar.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/undo-last-edit.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Evad37/duplinks-alt.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Evad37/MoveToDraft.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Evad37/OneClickArchiver.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Evad37/rater.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:GeneralNotability/mark-locked.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:GorillaWarfare/script/curlies.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Jonesey95/refill.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:JPxG/current-switcher.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Kaniivel/RefConsolidate_start.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Kephir/gadgets/table-editor.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Mr._Stradivarius/gadgets/ConfirmRollback.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Nardog/MoveHistory.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae/Scripts/AddTaxobox.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae/Scripts/CWWEditSummary.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae/Scripts/DetectG4G5.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae/Scripts/DetectPromo.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae/Scripts/GANReviewTool.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae/Scripts/TemplateTaxonomyAddCite.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae/Scripts/UserRightsDiff.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Ohconfucius/script/MOSNUM_dates.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Pythoncoder/Scripts/voteSymbols.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=user:Qwertyytrewqqwerty/DisamAssist.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:SD0001/DYK-helper.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:SD0001/GAN-helper.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:SD0001/StubSorter.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Shubinator/DYKcheck.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Suffusion_of_Yellow/filter-highlighter.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Suffusion_of_Yellow/filterNotes.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Terasail/COI_Request_Tool.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Terasail/Edit_Request_Tool.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:TheTVExpert/rmCloser.js&action=raw&ctype=text/javascript'); mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Writ_Keeper/Scripts/deletionFinder.js&action=raw&ctype=text/javascript');