User:Kevinalewis/bioassessmentsave.js

// // the code organization is horribly organized, but at this point--it works! var linkColor = "#002BB8"; var linkLead = ''; var templateSelect; var livingSelect; var prioritySelect; var workgroupSelect; var extraSelect; var talkpage; var talkpagehtml; var templateArray = new Array("WPBiography", "NovelsWikiProject"); var livingArray = new Array("", "|living=yes", "|living=no"); var priorityArray = new Array("", "Low", "Mid", "High", "Top"); var workgroupArray = new Array("", "|a&e-work-group=yes", "|politician-work-group=yes", "|british-royalty=yes", "|royalty-work-group=yes", "|military-work-group=yes", "|sports-work-group=yes", "|s&a-work-group=yes", "|musician-work-group=yes"); var extraArray = new Array("", "|listas=", "|listas=|needs-photo=yes", "|listas=|needs-infobox=yes", "|listas=|needs-infobox=yes|needs-photo=yes", "|needs-infobox=yes", "|needs-photo=yes");

function loadXMLDoc(url) {   // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { var tpreq = new XMLHttpRequest; }   // branch for IE/Windows ActiveX version else if (window.ActiveXObject) { var tpreq = new ActiveXObject("Microsoft.XMLHTTP"); }

if (tpreq) { tpreq.onreadystatechange = function { if (tpreq.readyState==4) { // if "OK" if (tpreq.status==200) { getAssessment(tpreq); }        // else { alert("Problem retrieving data:" + tpreq.statusText); } }     // else { alert("Problem retrieving data:" + tpreq.statusText); } };

tpreq.open("GET", url, true); tpreq.send(""); } }

function loadXMLDoc2(grade, url) // {   // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { var tpreq = new XMLHttpRequest; }   // branch for IE/Windows ActiveX version else if (window.ActiveXObject) { var tpreq = new ActiveXObject("Microsoft.XMLHTTP"); }

if (tpreq) { tpreq.onreadystatechange = function { if (tpreq.readyState==4) { // if "OK" if (tpreq.status==200) { postAssessment(grade, tpreq); }        // else { alert("Problem retrieving data:" + tpreq.statusText); } }     // else { alert("Problem retrieving data:" + tpreq.statusText); } };

tpreq.open("GET", url, true); tpreq.send(""); } }

function getAssessment(myreq) { talkpage = myreq.responseText; var otherInfo = "";

if ( talkpage.match( /\{\{ganominee/i ) ) { otherInfo='. Currently a Good Article candidate.';}

else if ( talkpage.match(/\{\{fac}/i ) ) { otherInfo='. Currently a Featured Article candidate.';}

if ( talkpage.match(/class *= *a/i) ) { update("#66ffff", "An " + linkLead + "A-class article", otherInfo);}

else if ( talkpage.match(/\{\{ga[|}]/i ) || talkpage.match(/currentstatus *= *ga/i) ) { update("#66ff66", 'A Good Article', otherInfo);}

else if ( talkpage.match(/class *= *b/i) ) { update("#c2ff66", "A " + linkLead + "B-class article", otherInfo);}

else if ( talkpage.match(/class *= *c/i) ) { update("#ffff66", "A " + linkLead + "C-class article", otherInfo);}

else if ( talkpage.match(/class *= *start/i) ) { update("#ffaa66", "A " + linkLead + "Start-class article", otherInfo);}

else if ( talkpage.match(/class *= *stub/i) ) { update("#ff6666", "A " + linkLead + "Stub-class article", otherInfo);}

else { update("#000000", "An " + linkLead + "unassessed article", otherInfo);} }

function addAssessment(grade) { template = templateSelect.options[templateSelect.selectedIndex].value; living = livingSelect.options[livingSelect.selectedIndex].value; priority = prioritySelect.options[prioritySelect.selectedIndex].value; workgroup = workgroupSelect.options[workgroupSelect.selectedIndex].value; extra = extraSelect.options[extraSelect.selectedIndex].value; if (talkpage == null) { xxtalkpage = talkpage; talkpage = "";} if ( talkpage.match(new RegExp("(\{\{"+template+"[^}]*)([A-Za-z]*)[^}]*}}", "i" ) ) ) { talkpage = talkpage.replace(RegExp.$1+RegExp.$2, "\r\n{{"+template+living+"|class="+grade+"|priority="+priority+workgroup+extra); } else if ( talkpage.match(new RegExp("(\{\{"+template+" *)([}|] *[^}]*}})", "i" ) ) ) { talkpage = talkpage.replace(RegExp.$1+RegExp.$2, RegExp.$1 + living + "|class=" + grade + "|priority=" + priority + workgroup+extra); } else if ( talkpage.match(/(\{\{[^}]*}})/ ) ) { talkpage = talkpage.replace(RegExp.$1, RegExp.$1 + "\r\n\r\n"); } else { talkpage = "\r\n" + xxtalkpage + talkpage; } loadXMLDoc2(grade, mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=Talk:" + encodeURIComponent(wgTitle) + "&action=edit"); }

function postAssessment(grade, myreq) { talkpagehtml = myreq.responseText; var minorEdit = ''; if (typeof assessmentMarkAsMinor != "undefined" ) { if ( !assessmentMarkAsMinor ) { minorEdit = ""; } } else if ( talkpagehtml.match(/<input type=.hidden. value="([\w\d]+)." name="wpEditToken"/i) ) { var editToken = RegExp.$1; } if ( talkpagehtml.match(/<input name="wpAutoSummary" type="hidden" value="([\w\d]+)"/i) ) { var autoSummary = RegExp.$1; } if ( talkpagehtml.match(/ <input tabindex="2" type="text" value="" name="wpSummary" id="wpSummary" maxlength="200" size="60" />' + minorEdit + '<input id="wpPreview" name="wpPreview" type="submit"/><input type="hidden" value="' + startTime + '" name="wpStarttime" /><input type="hidden" value="' + editTime + '" name="wpEdittime" /><input type="hidden" value="'+ editToken + '\" name="wpEditToken" /><input name="wpAutoSummary" type="hidden" value="' + autoSummary + '" /> '; document.body.appendChild(mydiv); document.editform.elements["wpTextbox1"].value = talkpage; document.editform.elements["wpSummary"].value = 'Assessed WikiProject Biography article (' + grade + ' class)'; document.editform.submit; }

function update(color, slogan, info) { document.getElementsByTagName("h1")[0].style.cssText = "color: " + color + ";"; t = document.getElementById("siteSub").innerHTML; document.getElementById("siteSub").innerHTML = "" + slogan + " " +            t.charAt(0).toLowerCase + t.substring(1) + info; templateSelect = document.createElement("select"); for (x = 0; x < templateArray.sort.length ; x++) { templateSelect.options[x] = new Option(templateArray[x], templateArray[x]); if (typeof defaultProject != "undefined" && templateArray[x] == defaultProject) { var projectIndex = x;   } } if (projectIndex >= 0 ) { templateSelect.selectedIndex = projectIndex; } document.getElementById("contentSub").appendChild(templateSelect); livingSelect = document.createElement("select"); for (x = 0; x < livingArray.sort.length ; x++) { livingSelect.options[x] = new Option(livingArray[x], livingArray[x]); if (typeof defaultLiving != "undefined" && livingArray[x] == defaultLiving) { var livingIndex = x;   } } if (livingIndex >= 0 ) { livingSelect.selectedIndex = livingIndex; } document.getElementById("contentSub").appendChild(livingSelect); prioritySelect = document.createElement("select"); for (x = 0; x < priorityArray.sort.length ; x++) { prioritySelect.options[x] = new Option(priorityArray[x], priorityArray[x]); if (typeof defaultPriority != "undefined" && priorityArray[x] == defaultPriority) { var priorityIndex = x;   } } if (priorityIndex >= 0 ) { prioritySelect.selectedIndex = priorityIndex; } document.getElementById("contentSub").appendChild(prioritySelect); workgroupSelect = document.createElement("select"); for (x = 0; x < workgroupArray.sort.length ; x++) { workgroupSelect.options[x] = new Option(workgroupArray[x], workgroupArray[x]); if (typeof defaultWorkgroup != "undefined" && workgroupArray[x] == defaultWorkgroup) { var workgroupIndex = x;   } } if (workgroupIndex >= 0 ) { workgroupSelect.selectedIndex = workgroupIndex; } document.getElementById("contentSub").appendChild(workgroupSelect); extraSelect = document.createElement("select"); for (x = 0; x < extraArray.sort.length ; x++) { extraSelect.options[x] = new Option(extraArray[x], extraArray[x]); if (typeof defaultExtra != "undefined" && extraArray[x] == defaultExtra) { var extraIndex = x;   } } if (extraIndex >= 0 ) { extraSelect.selectedIndex = extraIndex; } document.getElementById("contentSub").appendChild(extraSelect); var grades = document.createElement("div"); grades.innerHTML = '<a href="javascript:addAssessment(\'Stub\')">Stub</a> <a href="javascript:addAssessment(\'Start\')">Start</a> <a href="javascript:addAssessment(\'C\')">C</a> <a href="javascript:addAssessment(\'B\')">B</a> <a href="javascript:addAssessment(\'GA\')">GA</a> <a href="javascript:addAssessment(\'A\')">A</a>'; document.getElementById("contentSub").appendChild(templateSelect); document.getElementById("contentSub").appendChild(livingSelect); document.getElementById("contentSub").appendChild(prioritySelect); document.getElementById("contentSub").appendChild(workgroupSelect); document.getElementById("contentSub").appendChild(extraSelect); document.getElementById("contentSub").appendChild(grades); }

function begin { if ( wgNamespaceNumber==0 && !location.pathname.match('/w/index.php') ) { if ( document.getElementById("ca-talk").className == "new" ) { update("#000000", "An " + linkLead + "unassessed</a> article", ""); }   else if ( document.getElementById("featured-star") ) {update("#0066CC", 'A <a style="color:' + linkColor + ';" href="/wiki/Wikipedia:Featured Articles">Featured Article</a>', "");} else { var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=Talk:" + encodeURIComponent(wgTitle) + "&action=raw"; loadXMLDoc(url); } } }

addOnloadHook(begin); //