User:MC10/stubtagtab.js: Difference between revisions

Content deleted Content added
 
"modernize" code
Line 3:
// ([[User:ais523/stubtagtab2.js]])
// <source lang="javascript">
addOnloadHook$(function () {
if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view") {
if (document.getElementById("ca-edit")) mw.util.addPortletLink('p-cactions', 'javascript:stubtagtab()', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
}
if (___location.href.indexOf("&autoaddstubtag=") !== -1 && document.getElementById('wpTextbox1') != null) {
var x = decodeURIComponent(___location.href.split("&autoaddstubtag=")[1]);
if (x.indexOf("-stub") === -1) x += "-stub";
document.getElementById('wpTextbox1').value += "\n{" + "{" + x + "}}"; // add to the end of the article
document.getElementById('wpSummary').value = "Tagging with {" + "{" + x + "}} using [[WP:US/S|user scripts]]";
document.getElementById('wpPreview').click();
Line 26:
i++;
}
h += "</div><div id='stubtagmenudiv' style='color: #000000; background-color: #fffff8;'></div>";
document.getElementById("contentSub").innerHTML = h;
}
 
function stubtagmenurender(adata) {
var s = a.responseTextdata.split('<text xml:space="preserve">')[1].split("</text>")[0];
if (a.responseText.indexOf("<text") == -1) {
document.getElementById('stubtagmenudiv').innerHTML = "<i>Loading (progress:" + a.readyState + "), please wait...</i>";
return;
}
var s = a.responseText.split('<text xml:space="preserve">')[1].split("</text>")[0];
s = s.split("&lt;").join("<").split("&gt;").join(">");
s = s.split("&quot;").join('"').split("&amp;").join('&');
Line 48 ⟶ 44:
 
function stubtagmenu(x) {
// Fetch the relevant subpage of the WikiProject
$.ajax({
var a = sajax_init_object();
a url: mw.openconfig.get('GET', "wgServer") + mw.config.get("wgScriptPath") + '/api.php?action=parse&prop=text&text=' + encodeURIComponent('__NOTOC____NOEDITSECTION__{{Wikipedia:WikiProject Stub sorting/Stub types/' + x + '}}') + '&format=xml');,
dataType: "text", // "xml"
a.onreadystatechange = function () {
success: stubtagmenurender(a)
};
a.send('');
}
 
function stubtagwith(x) {
if (x == null || x === "") return;
___location.href = mw.config.get("wgServer") + mw.config.get("wgScript") + "?title=" + encodeURIComponent(mw.config.get("wgPageName")) + "&action=edit&autoaddstubtag=" + encodeURIComponent(x);
}