User:MC10/stubtagtab.js: Difference between revisions

Content deleted Content added
add loading message
only add stub menu if not added already
 
(8 intermediate revisions by the same user not shown)
Line 7:
function stubTagTab() {
var $h, $hb, $newa,
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']; // 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',
$h = $("<div></div>");
'History', 'Leisure', 'Military and weaponry', 'Organizations', 'People',
$h.css({
'Religion, mythology, faiths, and beliefs', 'Science', 'Sports', 'Technology', 'Transport',
"color": "#000000",
"background-color": "#fff8f8" 'Miscellaneous'];
$h = $("<div></div>", { "id": "stubtagtab" });
});
$h .css({
"color": "#000000",
"background-color": "#fff8f8"
});
for (var i = 0; i < a.length; i++) {
$newa = $("<a href=\"#\"></a>");
$newa.click(function (e) {
if (e.preventDefault) e.preventDefault();
if (e.returnValue) e.returnValue = false;
stubTagMenu($(this).text());
});
$newa.text(a[i]);
$h.append($newa);
if ((i + 1) < a.length) {
$h.append(" &bull; ");
});
}
$("#contentSub").append($h);
 
$hb = $("<div></div>");, {
$hb.css({ "color": "#000000",
"background-color": "#000000fffff8",
"background-color": "#fffff8" });
});
$hb.attr("id", "stubtagmenu");
$("#contentSub").append($hb);
Line 39 ⟶ 42:
var $parseData = $(data.parse.text["*"]);
$parseData.find("a").each(function () {
var $link = $(this).attr("href"),
index = $link.indexOf("Template:");
if (index === -1) {
$(this).attr({
Line 51 ⟶ 54:
});
} 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);
}
 
function stubTagMenuFail() {
$("#stubtagmenu").html("Failed to load stub tags.");
}
 
Line 66 ⟶ 74:
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",
success: stubTagMenuRender,
error: stubTagMenuFail
});
}
 
$(function () {
if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view" && document.getElementById("ca-edit")) {
&& $("#ca-edit").length !== 0) {
var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
$(portletLink).click(function (e) {
if (e.preventDefault) e.preventDefault();
if (e!$("#stubtagtab").returnValuelength) e.returnValue = false;{
stubTagTab();
}
});
}
if (___location.href.indexOf("&autoaddstubtag=") !== -1 && document.getElementById$('"#wpTextbox1'").length !== null0) {
var x = decodeURIComponent(___location.href.split("&autoaddstubtag=")[1]);
if (x.indexOf("-stub") === -1) x += "-stub";{
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]]