User:MC10/stubtagtab.js: Difference between revisions

Content deleted Content added
major changes in stubtagtab and stubtagmenurender
only add stub menu if not added already
 
(31 intermediate revisions by the same user not shown)
Line 4:
// Edited version [[User:MC10/stubtagtab.js]]
 
(function stubtagtab($) { // Wrap with anonymous function
function stubTagTab() {
var h, hb, newa;
var $h, $hb, $newa,
// A list of subpages of WikiProject Stub sorting/Stub types/ that are relevant to this
var a = ['General', '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'];,
'Miscellaneous'];
h = $("<div>");
$h = $("<div></div>", { "id": "stubtagtab" })
h.attr({
.css({
style: "color: #000000; background-color: #fff8f8;"
"color": "#000000",
});
"background-color": "#fff8f8"
for (var i = 0; i < a.length; i++) {
newa = $("<a href="#"></a>" });
newa.click(functionfor (evar i = 0; i < a.length; i++) {
e.preventDefault$newa = $("<a href=\"#\"></a>");
stubtagmenu$newa.click(a[i]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);
}
 
function stubTagMenuRender(data) {
var $parseData = $(data.parse.text["*"]);
$parseData.find("a").each(function () {
var link = $(this).attr("href"),
index = link.indexOf("Template:");
if (index === -1) {
$(this).attr({
"href": null,
"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)));
}
});
newa.text$("a[i]#stubtagmenu").html($parseData);
h.append(newa);
if ((i + 1) < a.length) h.append(" &bull; ");
}
hb = $("<div>");
hb.attr({
style: "color: #000000; background-color: #fffff8;"
});
h.after(hb);
$("#contentSub").html(h);
}
 
function stubtagmenurenderstubTagMenuFail(data) {
$("#stubtagmenu").html("Failed to load stub tags.");
var parseData = $(data.parse.text["*"]);
}
parseData.find("a").each(function () {
var link = $(this).attr("href"),
index = link.indexOf("Template:")
if (index === -1) {
$($(this).text()).clone().wrap('<div>').parent().html();
} 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)));
}
});
$('#stubtagmenudiv').html(parseData);
}
 
function stubtagmenustubTagMenu(xstubType) {
// Add loading message
// Fetch the relevant subpage of the WikiProject
$("#stubtagmenu").html("Loading stub tags, please wait...");
$.ajax({
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/' + x + '}}') + '&format=json',
dataType: "json", // "text"
success: stubtagmenurender
});
}
 
// Fetch the relevant subpage of the WikiProject
$(function () {
$.ajax({
if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view") {
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',
if (document.getElementById("ca-edit")) mw.util.addPortletLink('p-cactions', 'javascript:stubtagtab()', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
dataType: "json",
success: stubTagMenuRender,
error: stubTagMenuFail
});
}
 
if (___location.href.indexOf("&autoaddstubtag=") !== -1 && document.getElementById('wpTextbox1') != null) {
$(function () {
var x = decodeURIComponent(___location.href.split("&autoaddstubtag=")[1]);
if (xmw.indexOfconfig.get("-stubwgNamespaceNumber") === -1)0 x&& +mw.config.get("wgAction") === "-stubview";
&& $("#ca-edit").length !== 0) {
document.getElementById('wpTextbox1').value += "\n{" + "{" + x + "}}"; // add to the end of the article
var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
document.getElementById('wpSummary').value = "Tagging with {" + "{" + x + "}} using [[WP:US/S|user scripts]]";
document.getElementById $('wpPreview'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
 
// [[Category:Wikipedia scripts]]