User:R3m0t/delaid.js
// for instructions, see User talk:R3m0t/delaid.js
if (typeof alwaysReason == 'undefined') { alwaysReason = false; }
if (typeof altAction == 'undefined') { altAction = 'reason'; }
if (typeof defaultReturn == 'undefined') { defaultReturn = "http://en.wikipedia.org/w/index.php?title=Category:Candidates_for_speedy_deletion&action=purge"; }
/**
- Sets a Cookie with the given name and value.
- name Name of the cookie
- value Value of the cookie
- [expires] Expiration date of the cookie (default: end of current session)
- /
function DAsetCookie(name, value, expires, path) {
document.cookie= "da_" + name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
"; path=/";
}
/**
- Gets the value of the specified cookie.
- name Name of the desired cookie.
- Returns a string containing value of specified cookie,
- or null if cookie does not exist.
- /
function DAgetCookie(name) {
var dc = document.cookie;
var prefix = "da_" + name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}
function DelAidLink() {
if ((DAgetCookie('delaid') != '') && (DAgetCookie('delaid') != '-') && ((DAgetCookie('delaid') + '!') != 'null!') && (document.title == "Confirm deletion - Wikipedia, the free encyclopedia")) {
if (document.getElementById("wpReason").value == '') {
document.getElementById("wpReason").value = DAgetCookie('delaid') + ' || Deletion aided with delaid';
} else {
document.getElementById("wpReason").value = DAgetCookie('delaid') + ' || ' + document.getElementById("wpReason").value;
}
DAsetCookie('delaid', '-');
document.forms[0].wpConfirmB.click();
} else if ((DAgetCookie('delaid') == '-') && (document.title == "Action complete - Wikipedia, the free encyclopedia")) {
DAsetCookie('delaid', '');
go = DAgetCookie('returnpage');
if (go == null) { go = defaultReturn; }
document.location.href = go;
} else {
var link = document.createElement('a');
link.href = 'javascript:DelAid()';
link.title = 'Speedy puff!';
link.accessKey = '`';
link.appendChild(document.createTextNode('Speedy'));
var li = document.createElement('li');
li.appendChild(link);
document.getElementById("p-tb").getElementsByTagName('ul')[0].appendChild(li);
}
}
function DelAid() {
insertion = document.getElementById("contentSub");
objt = document.createElement("div");
objt.innerHTML = '
G1 Patent nonsense | G3 Vandalism | G4 Previously deleted | G7 Author\'s request | G8 Talk pages |
A1 No context | A3 No content | A7 Unremarkable people | I1 Redundant | I5 Copyrighted |
A2 Foreign language (copied) | A5 Transwikied | I2 Corrupt | G2 Test pages | G5 Banned user |
G10 Attack pages | I3 Bad license | I4 No license | G6 House keeping | G11 Advertising |
R1 Broken redirect | R2 To userspace | R3 Unlikely typo | U1 Owner\'s request | U2 No such user |
C1 Empty category | C2 Renamed | C3 Templated | G12 Copyvio | Visit Home |
T1 Inflammatory | WP:PROD | Enter reason |
insertion.parentNode.insertBefore(objt, insertion);
}
function DelAidDo(msg, ev) {
hasAlt = ev.altKey;
if (msg == '-') {
if (hasAlt) {
DAsetCookie('returnpage', document.location.href);
alert("Delaid home set to " + document.location.href);
} else {
go = DAgetCookie('returnpage');
if (go == null) { go = defaultReturn; }
document.location.href = go;
}
return;
}
if ((alwaysReason || (hasAlt && (altAction == "reason")) || (msg == '')) && !(hasAlt && (altAction == "noreason"))) {
addition = prompt('Reason','');
if (!addition) { return; }
if (addition != '') {
msg = msg + ' (' + addition + ')';
}
}
DAsetCookie('delaid', msg);
if (!document.getElementById("ca-delete")) {
document.location.href = "http://en.wikipedia.org/w/index.php?action=delete&title=" + escape(document.getElementsByTagName('h1')[0].firstChild.nodeValue);
}
document.location.href = document.getElementById("ca-delete").firstChild.href;
}
if (window.addEventListener) window.addEventListener("load",DelAidLink,false);
else if (window.attachEvent) window.attachEvent("onload",DelAidLink);