User:ZeroOne/monobook.js

importScript('User:Matthew_Yeager/renderboard.js');

importScript('User:Drilnoth/codefixer.js'); //See User:Drilnoth/codefixer.js/doc for details

// User:Lupin/popups.js - please include this line

mw.loader.load(

'https://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'

+ '&action=raw&ctype=text/javascript&dontcountme=s');

//

var linkColor = "#002BB8";

var linkLead = '';

var asTalkPage; //"as" to reduce name conflict - wikicode of talkpage

var talkpagehtml; //html of talkpage

var categoryText = null; //result of query.php request

var existingTemplateCodeArray; //those on the talk page

var TemplateArray = new Array();

var templateSelect;

var prioritySelect;

var bioWorkGroupSelect;

var livingSelect;

var milHistTaskForceSelect;

var livingArray = ["", "yes", "no"];

var priorityArray = ["", "Low", "Mid", "High", "Top"];

var bioWorkGroupArray = ["", "a&e-work-group", "british-royalty", "military-work-group", "musician-work-group", "politician-work-group", "royalty-work-group", "s&a-work-group", "sports-work-group"];

var milHistTaskForceArray = ["", "———General","Aviation-task-force","Historiography-task-force","Maritime-task-force","Memorials-task-force","Science-task-force","Technology-task-force","Weaponry-task-force","———Nations/Regions","African-task-force","Australian-task-force","Balkan-task-force","British-task-force","Canadian-task-force","Chinese-task-force","Dutch-task-force","French-task-force","German-task-force","Indian-task-force","Italian-task-force","Japanese-task-force","Korean-task-force","New-Zealand-task-force","Nordic-task-force","Polish-task-force","Russian-task-force","Spanish-task-force","US-task-force","———Periods/Conflicts","Ancient-Near-Eastern-task-force","Classical-task-force","Medieval-task-force","Early-Modern-task-force","Napoleonic-task-force","ACW-task-force","WWI-task-force","WWII-task-force"];

var templateArray = ["WPBiography", "Album", "Cvgproj", "Physics", "WikiProject China", "WikiProject Finland", "WPMILHIST", "WikiProject College football", "WPAstronomy", "Visual arts", "WikiProject France", "WikiProject Rugby union", "Film", "WikiProject Russia", "WPAVIATION", "WikiProject Germany", "WPSchools", "Ethnic groups", "WikiProject Saints", "WikiProject Wales", "WPTyneandWear", "WikiProject Oklahoma", "Environment", "LGBTProject", "WPLinux", "WPE", "TelevisionWikiProject"];

var templateCodeArray = ["{{WPBiography\r\n|small = \r\n|living = \r\n|class = \r\n|priority = \r\n|needs-infobox = \r\n|listas = \r\n|needs-photo = \r\n}}",

"{{Album\r\n|class=\r\n|importance=\r\n|attention=\r\n|needs-infobox=\r\n}}",

"{{Cvgproj|class=|importance=}}",

"{{Physics|class=|importance=}}",

"{{WikiProject China\r\n|class=\r\n|importance=}}",

"{{WikiProject Finland|class=|importance=}}",

"{{WPMILHIST\r\n|small=\r\n|nested=\r\n|class=\r\n|auto=\r\n|attention=\r\n|needs-infobox=\r\n|B-Class-1=\r\n|B-Class-2=\r\n|B-Class-3=\r\n|B-Class-4=\r\n|B-Class-5=\r\n}}",

"{{WikiProject College football|class=|importance=}}",

"{{WPAstronomy|class=}}",

"{{Visual arts\r\n|cat =\r\n|class =\r\n}}",

"{{WikiProject France\r\n|small=\r\n|class= \r\n|importance=\r\n|attention=\r\n|peer-review= \r\n|old-peer-review=\r\n}}",

"{{WikiProject Rugby union|class=|importance=}}",

"{{Film|class=|importance=}}",

"{{WikiProject Russia|class=|importance=}}",

"{{WPAVIATION\r\n|class=\r\n|Aircraft-project=\r\n|Airports-project=\r\n|Airlines-project=\r\n|Rotorcraft-task-force=\r\n|Gliding-project=\r\n|Red-Bull-project=\r\n|Defunct-Airlines-project=\r\n}}",

"{{WikiProject Germany|class=|importance=}}",

"{{WPSchools|class=|importance=}}",

"{{Ethnic groups|class=|importance=}}",

"{{WikiProject Saints\r\n|class=\r\n|importance=\r\n|needs-infobox=\r\n}}",

"{{WikiProject Wales|class=|importance=}}",

"{{WPTyneandWear|class=|importance=}}",

"{{WikiProject Oklahoma|class=|importance=}}",

"{{Environment|class=|importance=}}",

"{{LGBTProject|class=}}",

"{{WPLinux|class=}}",

"{{WPE|class=|importance=}}",

"{{TelevisionWikiProject\r\n|class=\r\n|importance=\r\n|type=\r\n|needs-infobox=}}"];

function aTemplate() {

this.name = "";

this.code = "";

this.existsGrade = "";

}

function TemplateSort(a,b) {

if ( a.name > b.name ) return 1

else if ( a.name < b.name ) return -1

else return 0;

}

addOnloadHook(begin);

function begin() {

if ( mw.config.get('wgNamespaceNumber')==0 && !location.pathname.match('/w/index.php') ) {

if ( Cookie.read("wpasStatus") >= "1" || Cookie.read("wpasStatus") === null ) {

if ( document.getElementById("ca-talk").className == "new" ) {

asTalkPage = "";

update("#000000", "An " + linkLead + "unassessed article", "");

}

else {

var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=Talk:" + encodeURIComponent(mw.config.get('wgTitle')) + "&action=raw";

loadTalkPageRaw(url);

}

}

else if (Cookie.read("wpasStatus") == "0" && !document.getElementById("siteSub").innerHTML.match(writeActivations()) ) {

document.getElementById("siteSub").innerHTML += writeActivations();

}

}

}

function loadTalkPageRaw(url) {

if (window.XMLHttpRequest) { // branch for native XMLHttpRequest object

var tpreq = new XMLHttpRequest();

}

else if (window.ActiveXObject) { // branch for IE/Windows ActiveX version

var tpreq = new ActiveXObject("Microsoft.XMLHTTP");

}

if (tpreq) {

tpreq.onreadystatechange = function () {

if (tpreq.readyState==4) {

// if "OK"

if (tpreq.status==200) {

getAssessment(tpreq);

}

}

};

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

tpreq.send("");

}

}

function getAssessment(myreq)

{

asTalkPage = myreq.responseText;

var otherInfo = "";

if ( asTalkPage.match( /\{\{ganominee/i ) ) {

otherInfo='. Currently a Good Article candidate.';

}

else if ( asTalkPage.match(/\{\{fac/i ) ) {

otherInfo='. Currently a Featured Article candidate.';

}

else if (asTalkPage.match(/\{\{peerreview}/i ) ) {

otherInfo='. Currently in peer review.';

}

if ( document.getElementById("featured-star") ) {

if (document.body.innerHTML.match('

update("#0066CC", 'A Featured List', "");

}

else {

update("#0066CC", 'A Featured Article', "");

}

}

else if ( asTalkPage.match(/class *= *a/i) ) { update("#007BFF", "An " + linkLead + "A-class article", otherInfo);}

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

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

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

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

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

}

function update(color, slogan, info) {

if ( typeof document.getElementsByTagName("h1")[0] != "undefined" ) { // see WPdiff:114016002

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 + writeActivations();

if ( Cookie.read("wpasStatus") == "2" || Cookie.read("wpasStatus") === null) {

if ( typeof defaultProject != "undefined" && typeof assessmentMyProjects == "undefined") { // compat. until user variables chg

assessmentMyProjects = [defaultProject];

}

if (typeof assessmentMyProjects != "undefined") {

for (y = 0; y < assessmentMyProjects.length ; y++) {

for (j = 0; j < templateArray.length ; j++) {

if ( assessmentMyProjects[y] == templateArray[j] ) {

myTemplate = new aTemplate();

myTemplate.name = templateArray[j];

myTemplate.code = templateCodeArray[j];

TemplateArray.push(myTemplate);

}

}

}

}

existingTemplateCodeArray = getTemplatesOnTalkPage();

for (y = 0; y < existingTemplateCodeArray.length ; y++) {

//existingTemplateCodeArray[y].match(/\{\{ *([^\|}]+) *[\|}]/);

//var theMatch = RegExp.$1;

z = 0;

notFound = true;

while (z < TemplateArray.length && notFound ) {

if ( existingTemplateCodeArray[y].name == TemplateArray[z].name ) {

TemplateArray[z] = existingTemplateCodeArray[y];

notFound = false;

}

z++;

}

if ( notFound ) {

TemplateArray.push(existingTemplateCodeArray[y]);

}

}

TemplateArray.sort(TemplateSort);

templateSelect = document.createElement("select");

for (x = 0; x < TemplateArray.length ; x++) {

templateSelect.options[x] = new Option(TemplateArray[x].name, TemplateArray[x].name);

if (TemplateArray[x].existsGrade != "") {

existingGrade = TemplateArray[x].existsGrade;

templateSelect.options[x].style.backgroundColor = getAssessmentBackgroundColor(existingGrade);

templateSelect.options[x].text += " → " + existingGrade;

}

if ( typeof assessmentMyProjects != "undefined" && TemplateArray[x].name == assessmentMyProjects[0] ) {

templateSelect.selectedIndex = x;

}

}

templateSelect.onchange = projectChange;

projectChange();

}

}

function projectChange() {

var index = templateSelect.selectedIndex;

var templateChoice = templateSelect.options[index].value;

myDiv = document.createElement("div");

myDiv.appendChild(templateSelect);

if ( TemplateArray[index].code.match(/(priority|importance) *=/) ) {

prioritySelect = document.createElement("select");

for (x = 0; x < priorityArray.length ; x++) {

prioritySelect.options[x] = new Option(priorityArray[x], priorityArray[x]);

if (typeof assessmentDefaultPriority != "undefined" && priorityArray[x] == assessmentDefaultPriority ) {

prioritySelect.selectedIndex = x;

}

}

myDiv.appendChild(prioritySelect);

}

if ( "WPBiography" == templateChoice ) {

bioWorkGroupSelect = document.createElement("select");

for (x = 0; x < bioWorkGroupArray.length ; x++) {

bioWorkGroupSelect.options[x] = new Option(bioWorkGroupArray[x], bioWorkGroupArray[x]);

if (typeof assessmentDefaultWorkGroup != "undefined" && bioWorkGroupArray[x] == assessmentDefaultWorkGroup ) {

bioWorkGroupSelect.selectedIndex = x;

}

}

myDiv.appendChild(bioWorkGroupSelect);

livingSelect = document.createElement("select");

var livingFlag = "";

if ( document.body.innerHTML.match("Category:Living_people") ) {

livingFlag = "yes"; }

else if ( document.body.innerHTML.match(/Category:\d+ (BC )?deaths/i) ) {

livingFlag = "no"; }

else if ( typeof assessmentDefaultLiving != "undefined" ) {

livingFlag = assessmentDefaultLiving;

}

for (x = 0; x < livingArray.length ; x++) {

livingSelect.options[x] = new Option(livingArray[x], livingArray[x]);

if ( livingArray[x] == livingFlag) { livingSelect.selectedIndex = x; }

}

myDiv.appendChild(livingSelect);

}

else if ( "WPMILHIST" == templateChoice ) {

milHistTaskForceSelect = document.createElement("select");

for (x = 0; x < milHistTaskForceArray.length ; x++) {

milHistTaskForceSelect.options[x] = new Option(milHistTaskForceArray[x], milHistTaskForceArray[x]);

if (typeof assessmentDefaultMilHistTaskForce != "undefined" && milHistTaskForceArray[x] == assessmentDefaultMilHistTaskForce ) {

milHistTaskForceSelect.selectedIndex = x;

}

}

myDiv.appendChild(milHistTaskForceSelect);

}

writeGradeLinks(templateChoice, myDiv);

if ( document.getElementById("selectionDiv") === null ) { //order of ops is important for IE

document.getElementById("contentSub").appendChild(myDiv)

}

else {

document.getElementById("contentSub").replaceChild(myDiv, document.getElementById("selectionDiv"));

}

myDiv.id = "selectionDiv";

}

function writeGradeLinks(template, theDiv) {

var grades = document.createElement("div");

var count = ( Cookie.read("wpasCount") === null ) ? "0" : Cookie.read("wpasCount") ;

filmGrades = (template=="Film") ? ' • FutureList' : "" ;

grades.innerHTML = '(' + count + ' assessed) StubStartBGAA' + filmGrades;

theDiv.appendChild(grades);

}

function addAssessment(grade) {

template = templateSelect.options[templateSelect.selectedIndex].value;

if (asTalkPage == null) { asTalkPage = "";}

if ( asTalkPage.match(new RegExp("\{\{" + template, "i") ) ) { } // fine

else if ( asTalkPage.match(/((\{\{[^\{}]*}}[ \r\n]*){1,3})/ ) ) // there are templates, but not mine

{ asTalkPage = asTalkPage.replace(RegExp.$1, RegExp.$1 + "\r\n" + TemplateArray[templateSelect.selectedIndex].code ); }

else { asTalkPage = TemplateArray[templateSelect.selectedIndex].code + "\r\n" + asTalkPage; } // no templates, so add before rest of talk page

asTalkPage.match(new RegExp("(\{\{"+template+"[^}]*}})([ \r\n]?)", "i" ) );

var thisTemplateMatch = RegExp.$1;

var newLines = RegExp.$2;

var textToReplace = thisTemplateMatch;

thisTemplateMatch = updateTemplate(thisTemplateMatch, "class", grade);

if (TemplateArray[templateSelect.selectedIndex].code.match(/((priority|importance)) *=/) && prioritySelect.options[prioritySelect.selectedIndex].value != "" ) {

thisTemplateMatch = updateTemplate(thisTemplateMatch, RegExp.$1, prioritySelect.options[prioritySelect.selectedIndex].value );

}

if (template=="WPBiography") {

if ( thisTemplateMatch.match("importance") ) {

thisTemplateMatch = thisTemplateMatch.replace("importance", "priority");

}

if ( bioWorkGroupSelect.options[bioWorkGroupSelect.selectedIndex].value != "" ) {

thisTemplateMatch = updateTemplate(thisTemplateMatch, bioWorkGroupSelect.options[bioWorkGroupSelect.selectedIndex].value, "yes" );

}

if ( livingSelect.options[livingSelect.selectedIndex].value != "" ) {

thisTemplateMatch = updateTemplate(thisTemplateMatch, "living", livingSelect.options[livingSelect.selectedIndex].value );

}

if ( !thisTemplateMatch.match(/listas *= *\w+/i) ) {

if ( mw.config.get('wgTitle').match(/^(\S+)( \w\.)? ?(\S+)?( \(\S+\))?$/) ) {

thisTemplateMatch = updateTemplate(thisTemplateMatch, "listas", ((RegExp.$3 != "") ? RegExp.$3 + ", " : "") + RegExp.$1 + RegExp.$2);

}

else {

var sortKey = getSortKey();

if ( sortKey != null ) {

thisTemplateMatch = updateTemplate(thisTemplateMatch, "listas", sortKey);

}

}

}

}

else if ( template=="WPMILHIST" ) {

thisTemplateMatch = updateTemplate(thisTemplateMatch, milHistTaskForceSelect.options[milHistTaskForceSelect.selectedIndex].value, "yes" );

}

asTalkPage = asTalkPage.replace(textToReplace, thisTemplateMatch + ((newLines == "") ? "\r\n\r\n" : newLines) );

loadTalkPageHTML(grade, mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=Talk:" + encodeURIComponent(mw.config.get('wgTitle')) + "&action=edit");

}

function updateTemplate(templateCode, parameter, val) {

var s = templateCode;

if ( s.match(/\n/) ) { addCr ="\n"; } else {addCr = ""};

if ( s.match(" =") ) { addSp =" = "; } else {addSp = "="};

if ( s.match(new RegExp('(' + parameter + ' *= *[^|}\r\n]*)'))) {

s = s.replace(RegExp.$1, parameter + addSp + val );

}

else {

s = s.replace(/}}/, '|' + parameter + addSp + val + addCr + "}}");

}

return s;

}

function getSortKey() {

loadCategories(mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/query.php?what=categories&titles=" + encodeURIComponent(mw.config.get('wgTitle')) + "&clextended&format=yaml");

if ( categoryText != null && categoryText.match(/sortkey: (.+)[\r\n]/) ) {return RegExp.$1; }

else { return null; }

}

function loadCategories(url) {

if (window.XMLHttpRequest) {

var catReq = new XMLHttpRequest();

}

else if (window.ActiveXObject) {

var catReq = new ActiveXObject("Microsoft.XMLHTTP");

}

if (catReq) {

catReq.onreadystatechange = function () {

if (catReq.readyState==4) {

if (catReq.status==200) {

categoryText = catReq.responseText;

}

}

};

catReq.open("GET", url, false);

catReq.send("");

}

}

function loadTalkPageHTML(grade, url) {

if (window.XMLHttpRequest) {

var tphreq = new XMLHttpRequest();

}

else if (window.ActiveXObject) {

var tphreq = new ActiveXObject("Microsoft.XMLHTTP");

}

if (tphreq) {

tphreq.onreadystatechange = function () {

if (tphreq.readyState==4) {

if (tphreq.status==200) {

postAssessment(grade, tphreq);

}

}

};

tphreq.open("GET", url, true);

tphreq.send("");

}

}

function postAssessment(grade, myreq) {

talkpagehtml = myreq.responseText;

var count = parseInt(Cookie.read("wpasCount"));

Cookie.create("wpasCount", String(count + 1));

var minorEdit = '';

if (typeof assessmentMarkAsMinor != "undefined" ) {

if ( !assessmentMarkAsMinor ) { minorEdit = ""; }

}

else

if ( talkpagehtml.match(/

var editToken = RegExp.$1;

}

if ( talkpagehtml.match(/

var autoSummary = RegExp.$1;

}

if ( talkpagehtml.match(/

var startTime = RegExp.$1;

}

if ( talkpagehtml.match(/

var editTime = RegExp.$1;

}

mydiv = document.createElement("div");

mydiv.innerHTML = '

';

document.body.appendChild(mydiv);

document.editform.wpTextbox1.value = asTalkPage;

document.editform.wpSummary.value = 'Assessed as "' + grade + '" for ' + template + ' via script';

document.editform.submit();

}

function getAssessmentBackgroundColor(grade) {

var s = grade.toLowerCase();

switch (s) {

case "none":

return "#DDD"

break

case "stub":

return "#FCC"

break

case "start":

return "#FC9"

break

case "b":

return "#FF9"

break

case "ga":

return "#9C9"

break

case "a":

return "#CFF"

break

case "fa":

return "#9BE"

break

default:

return ""

}

}

function getTemplatesOnTalkPage() {

var s = asTalkPage;

var a = new Array();

while (s.match(/(\{\{ *([\w\d\.\- ]+)[^\{}]*[^\-]class *= *(\w+)?[^}]*}})/mi) ) {

code = RegExp.$1

name = RegExp.$2.charAt(0).toUpperCase() + RegExp.$2.substring(1);

grade = ( RegExp.$3.length == 1 ? RegExp.$3.toUpperCase() : RegExp.$3 );

t = new aTemplate();

t.name = name.replace(/ +$/, "");

t.code = code;

t.existsGrade = ((grade == "") ? "none" : grade);

a.push(t);

s = s.replace(code, "");

}

return a;

}

function writeActivations() {

return '   [On] • [Hide] • [Off]';

}

function switchActivation(level) {

Cookie.create("wpasStatus", level);

if (level == "2" && document.getElementById("selectionDiv") === null) {

begin();

document.getElementById("selectionDiv").style.display = "block" ;

}

else if ( document.getElementById("selectionDiv") != null && (level == "1" || level == "0" ) ) {

document.getElementById("selectionDiv").style.display = "none";

}

}

var Cookie= { // from http://www.quirksmode.org/js/cookies.html

create: function(name,value,days)

{

var expires;

if (days)

{

var date = new Date();

date.setTime(date.getTime()+(days*24*60*60*1000));

expires = "; expires="+date.toGMTString();

}

else { expires = ""; }

document.cookie = name+"="+value+expires+"; path=/";

},

read: function(name)

{

var nameEQ = name + "=";

var ca = document.cookie.split(';');

for(var i=0;i < ca.length;i++)

{

var c = ca[i];

while (c.charAt(0)==' ') { c = c.substring(1,c.length); }

if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }

}

return null;

},

erase: function(name)

{

Cookie.create(name,"",-1);

}

};

//

importScript('User:AndyZ/peerreviewer.js'); //User:AndyZ/peerreviewer.js