User:This, that and the other/afdlog.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:This, that and the other/afdlog. |
// This script is a bookmarklet. You can make it into a
// bookmarklet using http://ted.mielczarek.org/code/mozilla/bookmarklet.html
// and then run the bookmarklet on any WP page.
if (typeof mw === "undefined") {
alert("You must be on a Wikipedia page for this to work.");
return;
}
mw.loader.using(["ext.gadget.Twinkle"], function() {
window.afdlog = {};
window.afdlog.fetchContribs = function(ucstart) {
var api = new Wikipedia.api("action", {
'action': 'query',
'rawcontinue': '',
'list': 'usercontribs',
'uclimit': 500,
'ucuser': wgUserName,
'ucnamespace': 4,
'ucprop': 'title|flags|timestamp',
'ucstart': ucstart
}, window.afdlog.contribsCallback);
api.post();
};
window.afdlog.contribResults = [];
window.afdlog.contribResultsIndex = 0;
window.afdlog.contribsCallback = function(apiResult) {
var $doc = $(apiResult.responseXML);
$doc.find('item[new=""][title^="Wikipedia:Articles for deletion/"]').each(function() {
var $this = $(this);
var ts = new Date($this.attr("timestamp")).toUTCString();
var title = $this.attr("title").substring(32).replace(/ \([0-9]+[nrst][dht] nomination\)$/, "");
if (title.indexOf("Log/2") !== 0) {
window.afdlog.contribResults.push({ ts: ts, title: title, afd: $this.attr("title") });
}
});
var $ctn = $doc.find("query-continue usercontribs");
if ($ctn.length) {
window.afdlog.fetchContribs($ctn.attr("ucstart"));
} else {
window.afdlog.fetchPage();
}
};
window.afdlog.fetchPage = function() {
var sect = window.afdlog.contribResults.slice(window.afdlog.contribResultsIndex, window.afdlog.contribResultsIndex + 19);
var titles = [];
$.each(sect, function(k, v) {
titles.push(v.title);
});
var api = new Wikipedia.api("action", {
'action': 'query',
'prop': 'info',
'titles': titles.join("|")
}, window.afdlog.pageCallback);
api.post();
};
window.afdlog.pageCallback = function(apiResult) {
$(apiResult.responseXML).find("page").each(function() {
var $this = $(this);
var newarr = window.afdlog.contribResults.filter(function(v) {
return v.title === $this.attr("title");
});
newarr[0].exists = $this.attr("missing") !== "";
});
window.afdlog.contribResultsIndex += 20;
if (window.afdlog.contribResultsIndex >= window.afdlog.contribResults.length) {
window.afdlog.$ol.empty();
$.each(window.afdlog.contribResults, function(k, v) {
window.afdlog.$ol.append($('<li>' + v.ts + ': <a href="' + wgArticlePath.replace("$1", v.title) +
'" style="color:' + (v.exists ? '#0645AD' : '#BA0000') + '">' + v.title + '</a> was <a href="' +
wgArticlePath.replace("$1", v.afd) + '" style="color:#0645AD">nominated for AfD</a></li>'));
});
window.afdlog.$ol.css({'margin-left': '10px', 'padding-left': '34px'});
} else {
window.afdlog.fetchPage();
}
};
window.afdlog.$ol = $('<ol>Please wait... (may take several minutes)</ol>');
window.afdlog.$ol.dialog({width: 900, height: 480, title: 'Your AfD nominations'});
window.afdlog.fetchContribs();
});