User:Blue/scripts/hotarticlerate.js

// function setupForHAR { if (wgNamespaceNumber == 0 && document.getElementById("ca-talk").getElementsByTagName("a")[0].href.search(/redlink/i) == -1) { if (window.XMLHttpRequest) { var req = new XMLHttpRequest; } else { var req = new ActiveXObject("Microsoft.XMLHTTP"); }		req.onreadystatechange = function { if (req.readyState == 4 && req.status == 200) { if (req.responseText.search(/{{rated/i) == -1) { var ratebutton = document.createElement("a"); ratebutton.title = "Rate this article"; ratebutton.innerHTML = " Rate "; ratebutton.onclick = function { var aform = document.createElement("div"); aform.id = "ratingForm"; var catsOutput = ""; for (var c in wgCategories) { catsOutput += "" + wgCategories[c] + " "; }						catsOutput += " "; aform.innerHTML = "Rate this article Rating: No brainstar Copper Bronze Silver Gold Category: " + catsOutput + " or*  Icon (optional):  Importance: LOW MID HIGH  Comments (optional):  <button onclick='doAR;'>Rate <button onclick='cancelAR;' style='margin-left: 1em;'>Cancel  *If the box has text in it the dropdown option will be discarded "; document.getElementById("content").insertBefore(aform, document.getElementById("bodyContent")); }					var holdingtab = document.createElement("li"); holdingtab.appendChild(ratebutton); document.getElementById("ca-talk").parentNode.appendChild(holdingtab); }			}		}		req.open("GET", wgServer + wgScript + "?title=Talk:" + wgPageName + "&action=raw", false); req.send(null); } else if (wgNamespaceNumber == 0 && document.getElementById("ca-talk").getElementsByTagName("a")[0].href.search(/redlink/i) != -1) { var ratebutton = document.createElement("a"); ratebutton.title = "Rate this article"; ratebutton.innerHTML = " Rate "; ratebutton.onclick = function { var aform = document.createElement("div"); aform.id = "ratingForm"; var catsOutput = "<select id='catInput'>"; for (var c in wgCategories) { catsOutput += "<option value='" + wgCategories[c] + "'>" + wgCategories[c] + " "; }			catsOutput += " "; aform.innerHTML = "<div style='padding: .7em; margin: .4em; border: 1px solid #aaa; background-color: #f5f5f5; width: 500px;'>Rate this article Rating: <select id='ratingInput'><option value='0'>No brainstar <option value='1'>Copper <option value='2'>Bronze <option value='3'>Silver <option value='4'>Gold Category: " + catsOutput + " or* <input type='text' id='catInputText' /> Icon (optional): <input type='text' id='iconInput' /> Importance: <select id='importanceInput'><option value='LOW'>LOW <option value='MID'>MID <option value='HIGH'>HIGH  Comments (optional): <textarea id='commentsInput' width='30' height='30'> <button onclick='doAR;'>Rate <button onclick='cancelAR;' style='margin-left: 1em;'>Cancel  *If the box has text in it the dropdown option will be discarded "; document.getElementById("content").insertBefore(aform, document.getElementById("bodyContent")); }		var holdingtab = document.createElement("li"); holdingtab.appendChild(ratebutton); document.getElementById("ca-talk").parentNode.appendChild(holdingtab); } } function cancelAR { document.getElementById("content").removeChild(document.getElementById("ratingForm")); } function doAR { var rating = document.getElementById("ratingInput").value; if (document.getElementById("catInputText").value != "") { var cat = document.getElementById("catInputText").value; } else { var cat = document.getElementById("catInput").value; }	var icon = document.getElementById("iconInput").value; var imp = document.getElementById("importanceInput").value; var comments = document.getElementById("commentsInput").value; if (window.XMLHttpRequest) { var req = new XMLHttpRequest; } else { var req = new ActiveXObject("Microsoft.XMLHTTP"); }	function gettoken_api { var api = sajax_init_object; api.open('GET', wgServer + wgScriptPath + '/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=Whatever', false); api.send(null); if (api.readyState == 4 && api.status == 200) { var response = eval('(' + api.responseText + ')'); var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken']; }		return token; }	var editToken = encodeURIComponent(gettoken_api); var pr = "\n\n"; function bottest { if (wgUserGroups.indexOf("bot") == -1) { return ""; } else { return "&bot"; }	}	var edittoken = encodeURIComponent(gettoken_api); if (rating == "1") { var ratingurl = ""; } else if (rating == "2") { var ratingurl = ""; } else if (rating == "3") { var ratingurl = ""; } else if (rating == "4") { var ratingurl = ""; } else if (rating == "0") { var ratingurl = "ordinary"; }	// Add rating to talk page req.open("POST", wgServer + wgScriptPath + "/api.php?action=edit" + bottest + "&prependtext=" + encodeURIComponent(pr) + "&title=Talk:" + wgPageName + "&notminor&summary=Added%20article%20rating%20" + encodeURIComponent(ratingurl) + ",%20" + encodeURIComponent("" + imp + "") + "%20using%20HotArticleRate" + "&token=" + edittoken, true) req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(null); // Check whether page has brainstar if (rating != "0") { if (window.XMLHttpRequest) { var preq = new XMLHttpRequest; } else { var preq = new ActiveXObject("Microsoft.XMLHTTP"); }		preq.onreadystatechange = function { if (preq.readyState == 4 && preq.status == 200) { if (preq.responseText.search(/(|||)/i) == -1) { // Add brainstar to page if (window.XMLHttpRequest) { var breq = new XMLHttpRequest; } else { var breq = new ActiveXObject("Microsoft.XMLHTTP"); }					function gettoken_api2 { var api = sajax_init_object; api.open('GET', wgServer + wgScriptPath + '/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=Whatever', false); api.send(null); if (api.readyState == 4 && api.status == 200) { var response = eval('(' + api.responseText + ')'); var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken']; }						return token; }					function bottest2 { if (wgUserGroups.indexOf("bot") == -1) { return ""; } else { return "&bot"; }					}					if (document.getElementById("ratingInput").value == "1") { var brainstar = ""; } else if (document.getElementById("ratingInput").value == "2") { var brainstar = ""; } else if (document.getElementById("ratingInput").value == "3") { var brainstar = ""; } else if (document.getElementById("ratingInput").value == "4") { var brainstar = ""; }					var edittoken2 = encodeURIComponent(gettoken_api2); breq.open("POST", wgServer + wgScriptPath + "/api.php?action=edit" + bottest2 + "&prependtext=" + encodeURIComponent(brainstar) + "&title=" + wgPageName + "&minor&summary=Added%20brainstar%20" + encodeURIComponent(brainstar) + "&token=" + edittoken2, true); breq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); breq.send(null); window.location.reload; } else { window.location.reload; } }		}		preq.open("GET", wgServer + wgScript + "?title=" + wgPageName + "&action=raw", false); preq.send(null); } } addOnloadHook(setupForHAR); //