User:JJPMaster/AutoWIGO2.js

//This is an updated version of Nx's AutoWIGO script that accounts for WIGO Corona, WIGO Elections, and the un-existence of WIGO aSK. //

function AutoWIGO { var pollname; var fulload = false; switch(wgPageName) { case "Conservapedia:What_is_going_on_at_CP%3F": pollname="wigo"; break; case "RationalWiki:What_is_going_on_in_the_clogosphere%3F": pollname="clog"; break; case "RationalWiki:What_is_going_on_in_the_blogosphere%3F": pollname="blog"; break; case "RationalWiki:What_is_going_on_with_the_coronavirus%3F": pollname="corona"; break; case "RationalWiki:What_is_going_on_with_the_elections%3F": pollname="elections"; break; case "RationalWiki:What_is_going_on_with_the_world%3F": pollname="world"; break; case "User:JJPMaster/AutoWIGO2.js": pollname="test"; fulload = true; break; case "RationalWiki:To_do_list/Suggestions": pollname="todo"; fulload = true; break; //insert additional polls here: // case "Page name (encoded form, wgPageName)": //     pollname="the poll name used in the wigo tag"; ////optional: load entire page separately, to make section editing work ////     fulload = true; //     break; default: return; } if (fulload) { var req = sajax_init_object; if (!req) return null; req.open("GET", wgServer+wgScriptPath+"/index.php?title="+wgPageName+"&action=raw&ctype=text/javascript&ffcacheworkaround=" + Math.random,false); req.send(null); if (req.status == 200) {     str = req.responseText; } else { return; } } else { if (document.forms['editform'] == null) return; var editarea = document.forms['editform'].elements['wpTextbox1']; var str = editarea.value; } var wigos = str.split(/<\/vote(cp|)>/); if (wigos.length == 0) return; var i; var numbers = []; var j = 0; for (i=0;i"); var pollstart = wigos[i].indexOf("poll="+pollname); var tempi = parseInt(wigos[i].substring(pollstart+5+pollname.length,closetag),10); if (!isNaN(tempi) && (tempi != 0 || temp == "0")) {     numbers[j] = tempi; ++j } }  if (numbers.length > 0) {   var nextnum = Math.max.apply(Math, numbers) + 1; } else { var nextnum = 1; } //add the button if (mw.toolbar) { mw.toolbar.push({       "imageFile": "http://rationalwiki.org/w/images/3/3a/Button_WIGO.png",        "speedTip": "WIGO",        "tagOpen": "",        "tagClose": " ",        "sampleText": "LULZ"    }); } //modify the link in edittools if (etparent = document.getElementById('edittools_wigo')) { var anchors = etparent.getElementsByTagName("a"); var i;   for (i=0;i/,"vote poll=" + pollname + nextnum + ">','"); anchors[i].setAttribute('onclick',attrib); }     if (anchors[i].innerHTML.indexOf("vote nextpoll=") != -1) { anchors[i].innerHTML = anchors[i].innerHTML.replace(/vote nextpoll=/,"vote nextpoll=" + pollname); attrib = anchors[i].getAttribute('onclick'); attrib = attrib.replace(/vote nextpoll=','>/,"vote nextpoll=" + pollname + ">','"); anchors[i].setAttribute('onclick',attrib); } /*     if (anchors[i].innerHTML.indexOf("votecp nextpoll=") != -1) { anchors[i].innerHTML = anchors[i].innerHTML.replace(/votecp nextpoll=/,"votecp nextpoll=" + pollname); attrib = anchors[i].getAttribute('onclick'); attrib = attrib.replace(/votecp nextpoll=/,"votecp nextpoll=" + pollname); anchors[i].setAttribute('onclick',attrib); }*/   }  } }

addOnloadHook(AutoWIGO);

//