Jump to content

User:MindstormsKid/vector.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
MindstormsKid (talk | contribs)
m huh, closures are more useful than i thought
MindstormsKid (talk | contribs)
m i'm an idiot
Line 38: Line 38:
if (afch_accepts.hasOwnProperty(k)) {
if (afch_accepts.hasOwnProperty(k)) {
var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
(function(){ a.onclick = function(){ afc_vote(title, k, afch_accepts[k], "accept"); return false; }; })();
a.onclick = function(){ afc_vote(title, k, afch_accepts[k], "accept"); return false; };
span.appendChild(a);
span.appendChild(a);
}
}
Line 48: Line 48:
if (afch_declines.hasOwnProperty(k)) {
if (afch_declines.hasOwnProperty(k)) {
var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
(function(){ a.onclick = function(){ afc_vote(title, k, "decline - " + afch_declines[k], ""); return false; }; })();
a.onclick = function(){ afc_vote(title, k, "decline - " + afch_declines[k], ""); return false; };
span.appendChild(a);
span.appendChild(a);
}
}
Line 58: Line 58:
if (afch_comments.hasOwnProperty(k)) {
if (afch_comments.hasOwnProperty(k)) {
var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
(function(){ a.onclick = function(){ afc_vote(title, k, afch_accepts[k], "comment"); return false; }; })();
a.onclick = function(){ afc_vote(title, k, afch_comments[k], "comment"); return false; };
span.appendChild(a);
span.appendChild(a);
}
}

Revision as of 21:28, 28 August 2009

// The Articles for Creation Helper
// v1.3 beta
//
// Originally written by [[User:Henrik]] at http://en.wikipedia.org/wiki/User:Henrik/js/afc-helper.js
// Revised by [[User:The Earwig]].
// See http://en.wikipedia.org/wiki/Wikipedia:Articles_for_creation
//
// <pre><nowiki>
 
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Henrik/js/automod.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
afch_accepts = {
	accept: "accepted",
	othertitle: "accepted at another title",
	reason: "accepted with custom reason"
};
afch_declines = {
	exists: "already exists",
	blank: "blank request",
	notarget: "target article does not exist, or was not specified", 
	unlikely: "unlikely search term, or source needed",
	reason: "custom reason"
};
afch_comments = { comment: "adding a comment" };

function afc_helper() {
	if (auto_mod()) { return; }
	
	var titles = document.getElementsByClassName("mw-headline");
	
	for (var i = 0, len = titles.length; i < len; i++) {
		if (titles[i].childNodes[0].nodeValue != "Redirect request: " || /\/wiki\//.test(titles[i].childNodes[1].href)) { continue; }
		(function(){
		var title = titles[i], es = title.parentNode.childNodes[0];
		
		var span = document.createElement("span"); span.setAttribute("id", "afc-helper-accept"); span.setAttribute("style","background-color: #A0FFA0;");
		for (var k in afch_accepts) {
			if (afch_accepts.hasOwnProperty(k)) {
				var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
				a.onclick = function(){ afc_vote(title, k, afch_accepts[k], "accept"); return false; };
				span.appendChild(a);
			}
		}
		es.appendChild(span);
		
		span = document.createElement("span"); span.setAttribute("id", "afc-helper-decline"); span.setAttribute("style","background-color: #ffcece;");
		for (k in afch_declines) {
			if (afch_declines.hasOwnProperty(k)) {
				var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
				a.onclick = function(){ afc_vote(title, k, "decline - " + afch_declines[k], ""); return false; };
				span.appendChild(a);
			}
		}
		es.appendChild(span);
		
		span = document.createElement("span"); span.setAttribute("id", "afc-helper-comment"); span.setAttribute("style","background-color: #ffec83;");
		for (k in afch_comments) {
			if (afch_comments.hasOwnProperty(k)) {
				var a = document.createElement("a"); a.setAttribute("href", "#"); a.innerHTML = "[" + k + "]";
				a.onclick = function(){ afc_vote(title, k, afch_comments[k], "comment"); return false; };
				span.appendChild(a);
			}
		}
		es.appendChild(span);
		})();
	}
}

function afc_vote(title, type, reason, action) {
	var comments, type2 = type, edit_link = title.childNodes[1].href;
	
	var redirOrigin = title.childNodes[1].innerHTML, redirTarget = title.parentNode.nextSibling.nextSibling.childNodes[1].innerHTML;
	
	if (type == "comment") { type2 = window.prompt("Comment:"); }
	
	if (type == "reason" && action == "accept") {
		comments = window.prompt("Reason for accepting:");
		type2 = "accept|" + comments;
	}
	
	if (type == "othertitle") {
		type2 = window.prompt("Other title:");
		redirOrigin = type2;
	}
	
	if (type == "accept") {
		type2 = "";
	}
	
	if (type == "reason" && action == "") {
		comments = window.prompt("Reason for declining:");
		type2 = "decline|" + comments;
	}
	
	if (action == "accept" && (!redirOrigin || !redirTarget)) { return; }
	
	if (action != "comment") {
		var url = edit_link
			+ '&amfind=' + escape("==(.*)==")
			+ '&amreplace=' + escape('$0\n{{subst:afc top|' + action + '}}')
			+ '&amlocal=1'
			+ '&amaddafter=' + escape("\n{{subst:afc redirect|" + type2 + "}} ~~" + "~~\n" + "{{subst:afc b}}")
			+ '&amsummary=' + escape(reason)
			+ '&amautosave=yes';
	} else {
		var url = edit_link
			+ '&amfind=' + escape("==(.*)==")
			+ '&amreplace=' + escape('$0')
			+ '&amlocal=1'
			+ '&amaddafter=' + escape("\n:{{afc comment|1=" + type2 + "}} ~~" + "~~")
			+ '&amsummary=' + escape(reason)
			+ '&amautosave=yes';
	}
	console.log(url);
	if (action == "accept") {
		var url2 = "http://en.wikipedia.org/w/index.php?title=" + escape(redirOrigin)
			+ "&action=edit&amsummary=Created+via+%5B%5BWP:AFC%7CArticles+for+Creation%5D%5D.+%5B%5BWP:AFC%2FR%7CYou+can+help%21%5D%5D&amfind=.*&amlocal=1&amreplace=%23REDIRECT+%5B%5B"
			+ escape(redirTarget) + "%5D%5D+%7B%7BR+from+alternate+name%7D%7D&amautosave=yes";
		var url3 = "http://en.wikipedia.org/w/index.php?title=Talk:" + escape(redirOrigin)
			+ "&action=edit&amsummary=%7B%7Bsubst%3AWPAFC%2Fredirect%7D%7D&amfind=.*&amlocal=1&amreplace=%7B%7Bsubst%3AWPAFC%2Fredirect%7D%7D&amautosave=yes";
		window.open(url2, "afd_helper_vote2");
		window.open(url3, "afd_helper_vote3");
	}
	
	window.location.href = url;
}

addOnloadHook(afc_helper);
 
// </nowiki></pre>