User:Mike.lifeguard/Gadget-autodel.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:Mike.lifeguard/Gadget-autodel. |
- Report page listing warnings and errors.
// Outline for an automatic delete link generator.
// Not highly tested. Started by Splarka @ test.wikipedia
// Written for & maintained by Mike_lifeguard @ en.wikibooks
//GO IF contribs or log or newpages or [article AND (submit|view|purge)]
if ("Contributions Whatlinkshere Log Prefixindex Newpages".indexOf(wgCanonicalSpecialPageName) != -1 || (wgIsArticle == true && (wgAction == "submit" || wgAction == "view" || wgAction == "purge")))
$(document).ready(function() {
mw.util.addPortletLink('p-cactions', 'javascript:deleteLinkify()', 'AutoDelete', 'ca-dellink', 'generate deletion links');
});
function deleteLinkify() {
var reason = prompt('Enter default delete reason', 'per [[COM:SPEEDY]]');
if (!reason) return;
var arp = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace(/\$1/, '');
var arp2 = (arp.indexOf('//') == 0) ? document.location.protocol + arp : null; // Protocol relative wgServer?
$('#bodyContent a').each(function() {
if (this.href.indexOf(arp) == 0 || arp2 && this.href.indexOf(arp2) == 0) {
if (this.href.indexOf('action=delete') == -1 && this.href.indexOf('/Special:') == -1) {
this.href += '?action=delete&submitdelete=true&deletetalkalso=true&wpReason=' + encodeURIComponent(reason);
this.innerHTML += ' (delete)';
}
}
});
}
if (queryString('submitdelete') == 'true') $(document).ready(function() {
var sub = (document.getElementById('wpConfirmB')) ? document.getElementById('wpConfirmB') : document.getElementById('mw-filedelete-submit')
if (document.getElementById('ca-talk').className.indexOf('new') == -1 && queryString('deletetalkalso') == 'true' && (wgNamespaceNumber % 2 == 0)) {
//if the talk tab is redlinked and this is the first time 'round AND this is not a talk page then:
sub.action += '&deletetalk=true&wpReason=' + queryString('wpReason');
}
sub.click();
})
if (wgAction == 'delete' && queryString('deletetalk') == 'true') $(document).ready(function() {
var url = document.getElementById('ca-talk').getElementsByTagName('a')[0].href + '?action=delete&submitdelete=true&wpReason=' + queryString('wpReason');
document.location.href = url;
})
function queryString(p) {
var re = RegExp('[&?]' + p + '=([^&]*)');
var matches;
if (matches = re.exec(document.location)) {
try {
return decodeURI(matches[1]);
} catch(e) {
}
}
return null;
}