User:AlgaeGraphix/BSiconcheck2.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
Documentation for this user script can be added at User:AlgaeGraphix/BSiconcheck2. |
- Report page listing warnings and errors.
if (wgPageName.search('User:'+wgUserName) != -1) {
mw.util.addPortletLink('p-tb', 'javascript:fileCheck()', 'BS icon check 2', 't-bsicon', 'Check for files', '8', document.getElementById('t-recentchangeslinked'));
};
function fileCheck() {
var start = '';
var filelist = '';
var rightnow = new Date();
var lastdate = new Date();
document.getElementById('t-bsicon').firstChild.firstChild.innerHTML = 'Checking...';
while ((rightnow-lastdate)/86400000<7) {
apicall('action=query&rawcontinue=&list=recentchanges&rcnamespace=6&rclimit=max&rctype=log&rcstart='+start, function(res) {
for (var rc in res.query.recentchanges) {
if (res.query.recentchanges[rc].title.search(/File:bsicon.*?\.svg/i) != -1 && res.query.recentchanges[rc].pageid == '0') {
filelist += '* [[:' + res.query.recentchanges[rc].title + ']]\n';
};
};
start = res['query-continue'].recentchanges.rcstart;
lastdate = new Date(start);
});
};
if (filelist == '') {
filelist = 'No new files.';
};
document.getElementById('t-bsicon').firstChild.firstChild.innerHTML = 'BS icon check 2';
alert(filelist);
};
function apicall(query, callback) {
try {
var xmlRequest = new XMLHttpRequest();
} catch(e) {
try {
var xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
throw "Could not create an XmlHttpRequest";
}
}
}
xmlRequest.open('POST', wgScriptPath+'/api.php', false);
xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlRequest.send(query+'&format=json');
var xmlResponse = new Function("return "+xmlRequest.responseText)();
if (!xmlResponse) {
alert("Couldn't access the API.");
} else {
callback(xmlResponse);
};
};