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

Content deleted Content added
m Bold and italics supported by default.
mNo edit summary
Line 22:
this.insert(number - 1);
}
else if(e.ctrlKey && (e.key == "i" || e.key == "b"))
{
this.insert(e.key);
Line 29:
// Load user's settings.
var page url := `/wiki/User:${mw.config.get("wgUserName")}/InsertShortcutsSettings.js?action=raw`, dataType : "text";
$.ajax(
this.getWikitext(page, wikitext =>
{
{
url : `/wiki/User:${mw.config.get("wgUserName")}/InsertShortcutsSettings.js?action=raw`, dataType : "text"
if(wikitext.startsWith("!!REDIRECT"))
})
{
.fail(result => { mw.notify("Failed to load your settings: " + result, "error"); })
var project = wikitext.split(" ")[1];
.done(text =>
this.getWikitext(page, wikitext =>
{
{
// Remove escaped newlines. Split into tags.
// Remove escaped newlines. Split into tags.
this.inserts = text.replace(/\\\n/g, "").split("\n");
this.inserts = wikitext.replace(/\\\n/g, "").split("\n");
});
{
}, null, null, `https://${project}.org/w/api.php`);
}
else
{
// Remove escaped newlines. Split into tags.
this.inserts = textwikitext.replace(/\\\n/g, "").split("\n");
}
});
},
Line 67 ⟶ 76:
txtarea.selectionStart = end;
txtarea.selectionEnd = end;
},
getWikitext: function(sTitles, fDone, fFail=null, fThen=null, href=null)
{
var settings =
{
"action": "query",
"prop": "revisions",
"rvprop": "content",
"rvslots": "main",
"rvlimit": 1,
"titles": sTitles
};
var api = href === null ? new mw.Api() : new mw.ForeignApi(href);
api.get(settings)
.done(data =>
{
var wikitext = [];
for(var id in data.query.pages)
{
wikitext.push(data.query.pages[id].revisions[0].slots.main['*']);
}
if(wikitext.length == 1)
{
fDone(wikitext[0]);
}
else
{
fDone(wikitext);
}
}).fail(fFail).then(fThen);
}
};