User:Sander Säde/allest.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

//Script to quickly get a list of all WikiProject Estonia articles
addOnloadHook(CollectButton);
function CollectButton() {
   // if ((document.URL.indexOf(':', 8) != -1) && (document.URL.indexOf('Talk:') == -1)) return;
   // if (document.URL.indexOf('/wiki/') == -1) return;
   addPortletLink( chooseBox( 'wpe: AllEst', TwinkleConfig.toolboxButtons ), "javascript:allest()", "wpe: allest", "", "", "");
   }
var allText;
var ahttp_request;
var iTrim;
function allest() {
   allText = "";
   document.getElementById("contentSub").innerHTML = "";
   iTrim = 1;
   getAllText("http://en.wikipedia.org/w/index.php?title=Category:WikiProject_Estonia_articles") }
function getAllText(surl) {
   ahttp_request = sajax_init_object(null);
   ahttp_request.onreadystatechange = aetextReceived;
   ahttp_request.open("GET", surl, true);
   ahttp_request.send(null);
   }
var cnter = 0;
function aetextReceived() {
   if(ahttp_request.readyState != 4) return;
   var pg = ahttp_request.responseText;
   var n = pg.indexOf('/w/index.php?title=Category:WikiProject_Estonia_articles&from=');
   var link = pg.substring(n, pg.indexOf('" title', n));
   allText = pg.substring(pg.search('pages in this section of this category.') + 44, pg.lastIndexOf('previous 200') - iTrim);
   document.getElementById("siteSub").innerHTML = cnter + " WikiProject Estonia articles found";
   iTrim = 157;
   var i = allText.match(/>Talk:/g);
   if (i != null) cnter = cnter + i.length;
   i = allText.match(/>Category talk/g);
   if (i != null) cnter = cnter + i.length;
   allText = allText.replace(/Talk:/g,"");
   allText = allText.replace(/title="Talk:/g,'title="');
   allText = allText.replace(/>Talk:/g,'>');
   document.getElementById("contentSub").innerHTML = document.getElementById("contentSub").innerHTML + allText;
   if (pg.indexOf("<h3>Ü</h3>") == - 1) getAllText("http://en.wikipedia.org" + link.replace('&amp;', '&'));
   else {
      document.getElementById("siteSub").innerHTML = cnter + " WikiProject Estonia articles found";
      updateWPEArticles();
      }
   }
function updateWPEArticles() {
   var xmlhttp = sajax_init_object(null);
   xmlhttp.overrideMimeType('text/xml');
   xmlhttp.open( 'GET' , 'http://en.wikipedia.org/w/index.php?title=User:Sander_S%C3%A4de/WPEarticles&action=submit', true);
   xmlhttp.onreadystatechange = function() {
      if(xmlhttp.readyState != 4) return;
      doUpdateWPEArticles(xmlhttp.responseXML);
      };
   xmlhttp.send(null)}
function doUpdateWPEArticles(pg) {
   form = pg.getElementById('editform');
   if(!form ) return;
   var text = '';
   var ad = document.getElementById("contentSub").getElementsByTagName("a");
   for(i = 0; i < ad.length; i++) {
      text = text + " [[" + ad[i].title + "]]·([[Talk:" + ad[i].title + "|talk]]) | ";
      }
   text = ad.length + " articles found<br/>" + text;
   var summary = 'Updating Estonia-related articles';
   var postData = {
      'wpMinoredit': form.wpMinoredit.checked, 'wpWatchthis': form.wpWatchthis.checked, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': text};
   var xmlhttp = sajax_init_object();
   xmlhttp.overrideMimeType('text/xml');
   xmlhttp.open( 'POST' , "http://en.wikipedia.org/w/index.php?title=User:Sander_S%C3%A4de/WPEarticles&action=submit", true);
   xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
   xmlhttp.onload = function() {
      return;
      }
   xmlhttp.send( QueryString.create(postData));
}