User:MC10/stubtagtab.js: Difference between revisions

Content deleted Content added
change link
wrap with anonymous function
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 = ['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'];
h = $("<div></div>");
h.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.textfor (var i = 0; i < a[.length; i]++); {
h.append( newa = $("<a href=\"#\"></a>");
if ((i + 1) < anewa.lengthclick(function (e) {
h.append(" &bull; " e.preventDefault();
stubTagMenu($(this).text());
}
$("#contentSub").append(h);
 
hb = $("<div></div>");
hb.css({
"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
});
$newa.text(thisa[i]).css({;
"color": "#000000",h.append(newa);
if ((i + 1) "text-decoration":< "none"a.length)
} h.append(" &bull; ");
} 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)));
}
$("#contentSub").append(h);
});
$('#stubtagmenu').html(parseData);
}
 
newahb = $("<a href=\"#\"div></adiv>");
function stubTagMenu(stubType) {
hb.css({
// Fetch the relevant subpage of the WikiProject
"color": "#000000",
$.ajax({
"background-color": "#fffff8"
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", // "text"});
success:hb.attr("id", stubTagMenuRender"stubtagmenu");
$("#contentSub").append(hb);
});
}
}
 
$( function stubTagMenuRender(data) {
var parseData = $(data.parse.text["*"]);
if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view" && document.getElementById("ca-edit")) {
parseData.find("a").each(function () {
var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
var link = $(portletLinkthis).clickattr(function (e"href") {,
e index = link.preventDefaultindexOf("Template:");
stubTagTabif (index === -1); {
var link = $(this).attr("href"),{
"href": null,
"title": null
});
$(this).attrcss({
"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)));
if (index === -1) {}
});
$('#stubtagmenu').html(parseData);
}
 
if (___location.href.indexOf("&autoaddstubtag=") !== -1 && document.getElementById('wpTextbox1') != null) {
function stubTagMenu(stubType) {
var x = decodeURIComponent(___location.href.split("&autoaddstubtag=")[1]);
// Fetch the relevant subpage of the WikiProject
if (x.indexOf("-stub") === -1) x += "-stub";
$.ajax({
document.getElementById('wpTextbox1').value += "\n{" + "{" + x + "}}"; // add to the end of the article
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',
document.getElementById('wpSummary').value = "Tagging with {" + "{" + x + "}} using [[User:MC10/stubtagtab.js|stubtagtab.js]]";
dataType: "json", // "text"
document.getElementById('wpPreview').click();
success: stubTagMenuRender
});
}
 
});
$(function () {
if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wgAction") === "view" && document.getElementById("ca-edit")) {
var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Stub', 'ca-stubtag', 'Add a stub tag to this page', '');
newa $(portletLink).click(function (e) {
e.preventDefault();
stubTagTab();
});
});
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 [[User:MC10/stubtagtab.js|stubtagtab.js]]";
document.getElementById('wpPreview').click();
}
});
} (jQuery)) // End wrap with anonymous function
 
// [[Category:Wikipedia scripts]]