User:Guywan/Scripts/InsertShortcuts.js: Difference between revisions

Content deleted Content added
mNo edit summary
maintenance: more info wikitext is array. startsWith is a string method.
 
(5 intermediate revisions by 2 users not shown)
Line 30:
// Load user's settings.
var page = `User:${mw.config.get("wgUserName")}/InsertShortcutsSettings.js`;
var loadFrom = window.us_InsertShortcuts_loadFrom === undefined ? null : `https://${us_InsertShortcuts_loadFrom}.org/w/api.php`;
this.getWikitext(page, wikitext =>
{
if(typeof wikitext === 'string' && wikitext.startsWith("!!REDIRECT"))
{
project = wikitext.split(" ")[1];
this.getWikitext(page, wikitext =>
{
// Remove escaped newlines. Escape 'comments'. Split into tags.
this.inserts = wikitext.replace(/\\\n/g, "").replace(/^\/\//gm, "").split("\n");
}, null, null, `https://${project}.org/w/api.php`);
Line 45:
else
{
// Remove escaped newlines. Escape 'comments'. Split into tags.
this.inserts = wikitext.replace(/\\\n/g, "").replace(/^\/\//gm, "").split("\n");
}
}, null, null, loadFrom);
Line 98:
for(var id in data.query.pages)
{
wikitext.push(var revisions = data.query.pages[id].revisions || [0].slots.main['*']);
if(revisions.length) wikitext.push(revisions[0].slots.main['*']);
}