User:MC10/stubtagtab.js: Difference between revisions

Content deleted Content added
 
only add stub menu if not added already
 
(44 intermediate revisions by the same user not shown)
Line 2:
// Enhancements made on requests by [[User:Alai]] and [[User:jj137]].
// ([[User:ais523/stubtagtab2.js]])
// Edited version [[User:MC10/stubtagtab.js]]
// <source lang="javascript">
 
addOnloadHook(function () {
(function ($) { // Wrap with anonymous function
if (wgNamespaceNumber == 0 && wgAction == "view") {
function stubTagTab() {
if (document.getElementById("ca-edit")) addPortletLink('p-cactions', 'javascript:stubtagtab()', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
var $h, $hb, $newa,
// A list of subpages of WikiProject Stub sorting/Stub types/ that are relevant to this
a = ['General', 'Commerce', 'Culture', 'Education', 'Geography', 'Government, law, and politics',
'History', 'Leisure', 'Military and weaponry', 'Organizations', 'People',
'Religion, mythology, faiths, and beliefs', 'Science', 'Sports', 'Technology', 'Transport',
'Miscellaneous'];
$h = $("<div></div>", { "id": "stubtagtab" })
.css({
"color": "#000000",
"background-color": "#fff8f8"
});
for (var i = 0; i < a.length; i++) {
$newa = $("<a href=\"#\"></a>");
$newa.click(function (e) {
e.preventDefault();
stubTagMenu($(this).text());
});
$newa.text(a[i]);
$h.append($newa);
if ((i + 1) < a.length) {
$h.append(" &bull; ");
}
}
$("#contentSub").append($h);
 
$hb = $("<div></div>", {
"color": "#000000",
"background-color": "#fffff8"
});
$hb.attr("id", "stubtagmenu");
$("#contentSub").append($hb);
}
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();
}
});
 
function stubtagtabstubTagMenuRender(data) {
var $parseData = $(data.parse.text["*"]);
var h;
$parseData.find("a").each(function () {
// A list of subpages of WikiProject Stub sorting/Stub types/ that are relevant to this
var link = $(this).attr("href"),
var a = ['Commerce', 'Culture', 'Education', 'Geography', 'Government, law, and politics', 'History', 'Leisure', 'Military and weaponry', 'Miscellaneous', 'Organizations', 'People', 'Religion, mythology, faiths, and beliefs', 'Science', 'Sports', 'Technology', 'Transport'];
index = link.indexOf("Template:");
var i = 0;
if (index === -1) {
h = "<div style='color:#000000; background-color:#fff8f8;'>&bull; ";
$(this).attr({
while (i < a.length) {
h += "<a href='javascript:stubtagmenu(\"" + a[i] + "\");'>" + a[i] + "</a>href": &bull; ";null,
i++; "title": null
});
$(this).css({
"color": "#000000",
"text-decoration": "none"
});
} else {
$(this).attr("href", mw.config.get("wgServer") + mw.config.get("wgScript")
+ "?title=" + encodeURIComponent(mw.config.get("wgPageName"))
+ "&action=edit&autoaddstubtag=" + encodeURIComponent(link.slice(index + 9)));
}
});
$("#stubtagmenu").html($parseData);
}
h += "</div><div id='stubtagmenudiv' style='color:#000000; background-color:#fffff8;'></div>";
document.getElementById("contentSub").innerHTML = h;
}
 
function stubtagmenurenderstubTagMenuFail(a) {
$("#stubtagmenu").html("Failed to load stub tags.");
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('&');
s = s.split('<a href="/wiki/Template:');
var i = s.length;
while (--i) s[i] = s[i].split('" title').join('\');" title');
s = s.join('<a temphref="javascript:stubtagwith(\'');
s = s.split('<a href=').join('<a style="color:#000000;" notanhref=');
s = s.split('<a temphref=').join('<a href=');
document.getElementById('stubtagmenudiv').innerHTML = s;
}
 
function stubtagmenustubTagMenu(xstubType) {
// Add loading message
//Fetch the relevant subpage of the WikiProject
$("#stubtagmenu").html("Loading stub tags, please wait...");
var a = sajax_init_object();
 
a.open('GET', wgServer + wgScriptPath + '/api.php?action=parse&prop=text&text=' + encodeURIComponent('__NOTOC____NOEDITSECTION__{{Wikipedia:WikiProject Stub sorting/Stub types/' + x + '}}') + '&format=xml');
// Fetch the relevant subpage of the WikiProject
a.onreadystatechange = function () {
stubtagmenurender$.ajax(a){
url: mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/api.php?action=parse&prop=text&text=' + encodeURIComponent('__NOTOC____NOEDITSECTION__\{\{Wikipedia:WikiProject Stub sorting/Stub types/' + stubType + '}}') + '&format=json',
};
dataType: "json",
a.send('');
success: stubTagMenuRender,
}
error: stubTagMenuFail
});
}
 
$(function stubtagwith(x) {
if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view"
if (x == null || x == "") return;
&& $("#ca-edit").length !== 0) {
___location.href = wgServer + wgScript + "?title=" + encodeURIComponent(wgPageName) + "&action=edit&autoaddstubtag=" + encodeURIComponent(x);
var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
}
$(portletLink).click(function (e) {
e.preventDefault();
if (!$("#stubtagtab").length) {
stubTagTab();
}
});
}
if (___location.href.indexOf("&autoaddstubtag=") !== -1 && $("#wpTextbox1").length !== 0) {
var x = decodeURIComponent(___location.href.split("&autoaddstubtag=")[1]);
if (x.indexOf("-stub") === -1) {
x += "-stub";
}
$("#wpTextbox1").val($("#wpTextbox1").val() + "\n{" + "{" + x + "}}"); // add to the end of the article
$("#wpSummary").val("Tagging with {" + "{" + x + "}} using [[User:MC10/stubtagtab.js|stubtagtab.js]]");
$("#wpPreview").trigger("click");
}
});
} (jQuery)); // End wrap with anonymous function
 
// </source> <!--[[Category:Wikipedia scripts]]-->