User:MordantMaenad/scripts/hotstubcat.js

//

function setupForStubcat { var stubtemp = getElementsByClassName(document.getElementById('bodyContent'),"*","stubtemplate"); if (stubtemp) stubtemp = stubtemp[0]; if (!stubtemp) return false; if (stubtemp.getElementsByTagName("i")[0].innerHTML == "This article is a stub.") { // Uncategorized var stubcatDiv = document.createElement("div"); stubcatDiv.id = "stubcatDiv"; stubcatDiv.style.backgroundColor = "#f9f9f9"; stubcatDiv.style.borderLeft = "1px solid #aaa"; stubcatDiv.style.borderRight = "1px solid #aaa"; stubcatDiv.style.borderBottom = "1px solid #aaa"; stubcatDiv.style.padding = ".3em"; stubcatDiv.style.margin = "0em auto .4em auto"; stubcatDiv.style.textAlign = "center"; stubcatDiv.style.width = "100px"; stubtemp.style.marginBottom = "0"; var cathotlink = document.createElement("span"); cathotlink.innerHTML = "categorize"; cathotlink.onclick = function { var stubcatFormSpan = document.createElement("span"); stubcatFormSpan.id = "stubcatForm"; stubcatFormSpan.innerHTML = " OK Cancel "; document.getElementById("stubcatDiv").innerHTML = ""; document.getElementById("stubcatDiv").style.width = "260px"; document.getElementById("stubcatDiv").appendChild(stubcatFormSpan); }		stubcatDiv.appendChild(cathotlink); stubtemp.parentNode.insertBefore(stubcatDiv, stubtemp.nextSibling); } else { // Already categorized var stubcatDiv = document.createElement("div"); stubcatDiv.id = "stubcatDiv"; stubcatDiv.style.backgroundColor = "#f9f9f9"; stubcatDiv.style.borderLeft = "1px solid #aaa"; stubcatDiv.style.borderRight = "1px solid #aaa"; stubcatDiv.style.borderBottom = "1px solid #aaa"; stubcatDiv.style.padding = ".3em"; stubcatDiv.style.textAlign = "center"; stubcatDiv.style.width = "100px"; stubcatDiv.style.margin = "0em auto .4em auto"; stubtemp.style.marginBottom = "0"; var cathotlink = document.createElement("span"); cathotlink.innerHTML = "change category"; cathotlink.onclick = function { var stubcatFormSpan = document.createElement("span"); stubcatFormSpan.id = "stubcatForm"; stubcatFormSpan.innerHTML = " OK Cancel "; document.getElementById("stubcatDiv").innerHTML = ""; document.getElementById("stubcatDiv").style.width = "260px"; document.getElementById("stubcatDiv").appendChild(stubcatFormSpan); }		stubcatDiv.appendChild(cathotlink); stubtemp.parentNode.insertBefore(stubcatDiv, stubtemp.nextSibling); } } function lookupStubcat { if (document.getElementById("stubcatInput").value != "") { if (window.XMLHttpRequest) { var req = new XMLHttpRequest; } else { var req = new ActiveXObject("Microsoft.XMLHTTP"); }		req.onreadystatechange = function { if (req.readyState == 4 && req.status == 200) { var memberList = []; var jsonOutput = eval('(' + req.responseText + ')'); var cmembers = jsonOutput.query.categorymembers; for (var memberObj in cmembers) { memberList.push(cmembers[memberObj].title); }				var inputted = document.getElementById("stubcatInput").value; var checked = false; var preg = new RegExp("Category:" + inputted + "-related stubs", "i"); for (var member in memberList) { if (memberList[member].match(preg) != null) { document.getElementById("stubcatInput").style.backgroundColor = "#ddeede"; checked = true; }				}				if (!checked) { document.getElementById("stubcatInput").style.backgroundColor = "#f4d2cc"; }			}		}		req.open("GET", wgServer + wgScriptPath + "/api.php?action=query&format=json&list=categorymembers&cmlimit=500&cmtitle=Category:Articles%20needing%20expansion", true); req.send(null); } } function executeStubcat { if (window.XMLHttpRequest) { var req = new XMLHttpRequest; } else { var req = new ActiveXObject("Microsoft.XMLHTTP"); }	req.onreadystatechange = function { if (req.readyState == 4 && req.status == 200) { var inputted = document.getElementById("stubcatInput").value; var curText = req.responseText; curText = curText.replace(//i, ""); 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; }			if (window.XMLHttpRequest) { var exreq = new XMLHttpRequest; } else { var exreq = new ActiveXObject("Microsoft.XMLHTTP"); }			var editToken = encodeURIComponent(gettoken_api); exreq.open("POST", wgServer + wgScriptPath + "/api.php?action=edit&title=" + encodeURIComponent(wgPageName) + "&text=" + encodeURIComponent(curText) + "&token=" + editToken + "&summary=" + encodeURIComponent("added stub type " + inputted + " using HotStubCat"), true); exreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); exreq.send(null); window.location.reload; }	}	req.open("GET", wgServer + wgScriptPath + "/index.php?title=" + wgPageName + "&action=raw", true); req.send(null); }

function executeStubcatChange { if (window.XMLHttpRequest) { var req = new XMLHttpRequest; } else { var req = new ActiveXObject("Microsoft.XMLHTTP"); }	req.onreadystatechange = function { if (req.readyState == 4 && req.status == 200) { var inputted = document.getElementById("stubcatInput").value; var curText = req.responseText; var stLoc = curText.search(/{{stub/i); for (var j = stLoc; j < curText.length; j++) { if (curText.slice(j, j + 2) == "}}") { var newText = curText.slice(stLoc, stLoc + j + 2); alert(newText); var curCat = curText.slice(stLoc + 7, stLoc + 20); alert(curCat); break; }			}			curText = curText.replace(newText, ""); alert(curText); 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; }			if (window.XMLHttpRequest) { var exreq = new XMLHttpRequest; } else { var exreq = new ActiveXObject("Microsoft.XMLHTTP"); }			var editToken = encodeURIComponent(gettoken_api); //exreq.open("POST", wgServer + wgScriptPath + "/api.php?action=edit&title=" + encodeURIComponent(wgPageName) + "&text=" + encodeURIComponent(curText) + "&token=" + editToken + "&summary=" + encodeURIComponent("changed stub type " + curCat + " to " + inputted + " using HotStubCat"), true); //exreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //exreq.send(null); //window.location.reload; }	}	req.open("GET", wgServer + wgScriptPath + "/index.php?title=" + wgPageName + "&action=raw", true); req.send(null); }

function cancelStubcat { document.getElementById("stubcatDiv").parentNode.removeChild(document.getElementById("stubcatDiv")); var stubtemp = getElementsByClassName(document.getElementById('bodyContent'),"*","stubtemplate"); if (stubtemp) stubtemp = stubtemp[0]; if (!stubtemp) return false; if (stubtemp.getElementsByTagName("i")[0].innerHTML == "This article is a stub.") { // Uncategorized var stubcatDiv = document.createElement("div"); stubcatDiv.id = "stubcatDiv"; stubcatDiv.style.backgroundColor = "#f9f9f9"; stubcatDiv.style.borderLeft = "1px solid #aaa"; stubcatDiv.style.borderRight = "1px solid #aaa"; stubcatDiv.style.borderBottom = "1px solid #aaa"; stubcatDiv.style.padding = ".3em"; stubcatDiv.style.margin = "0em auto .4em auto"; stubcatDiv.style.textAlign = "center"; stubcatDiv.style.width = "100px"; stubtemp.style.marginBottom = "0"; var cathotlink = document.createElement("span"); cathotlink.innerHTML = "categorize"; cathotlink.onclick = function { var stubcatFormSpan = document.createElement("span"); stubcatFormSpan.id = "stubcatForm"; stubcatFormSpan.innerHTML = " OK Cancel "; document.getElementById("stubcatDiv").innerHTML = ""; document.getElementById("stubcatDiv").style.width = "260px"; document.getElementById("stubcatDiv").appendChild(stubcatFormSpan); }		stubcatDiv.appendChild(cathotlink); stubtemp.parentNode.insertBefore(stubcatDiv, stubtemp.nextSibling); } else { // Already categorized var stubcatDiv = document.createElement("div"); stubcatDiv.id = "stubcatDiv"; stubcatDiv.style.backgroundColor = "#f9f9f9"; stubcatDiv.style.borderLeft = "1px solid #aaa"; stubcatDiv.style.borderRight = "1px solid #aaa"; stubcatDiv.style.borderBottom = "1px solid #aaa"; stubcatDiv.style.padding = ".3em"; stubcatDiv.style.textAlign = "center"; stubcatDiv.style.width = "100px"; stubcatDiv.style.margin = "0em auto .4em auto"; stubtemp.style.marginBottom = "0"; var cathotlink = document.createElement("span"); cathotlink.innerHTML = "change category</a>"; cathotlink.onclick = function { var stubcatFormSpan = document.createElement("span"); stubcatFormSpan.id = "stubcatForm"; stubcatFormSpan.innerHTML = " <input type='text' onkeyup='lookupStubcat' id='stubcatInput' /><button id='stubcatOK' style='margin-left: .2em;' onclick='executeStubcatChange'>OK <button style='margin-left: .2em;' onclick='cancelStubcat'>Cancel "; document.getElementById("stubcatDiv").innerHTML = ""; document.getElementById("stubcatDiv").style.width = "260px"; document.getElementById("stubcatDiv").appendChild(stubcatFormSpan); }		stubcatDiv.appendChild(cathotlink); stubtemp.parentNode.insertBefore(stubcatDiv, stubtemp.nextSibling); } } addOnloadHook(setupForStubcat);

//