User:Waggers/WagTools/projecttag.js

// if (document.URL == 'http://en.wikipedia.org/wiki/User:Waggers/WagTools/projecttag') { addOnloadHook(func_loadProjectTagWagTool); } function func_loadProjectTagWagTool { var op = " The tool is active. "; op = op + "Category:  "; op = op + "Tag: "; op = op + "Continue from: "; op = op + "

"; op = op + " ";  document.getElementById('bodyContent').innerHTML = document.getElementById('bodyContent').innerHTML + op;  a.send(null); } function makelist {  alert('running');  //var artbox = document.getElementById("artbox");  var oRequest = new XMLHttpRequest;  var catbox = document.getElementById("catbox");  var cattext = document.getElementById("catbox").value;  var confrombox = document.getElementById("confrom");  var confromtext = confrombox.value;  var sURL  = "http://en.wikipedia.org/w/api.php?action=query&rawcontinue=&list=categorymembers&cmtitle=Category:" + cattext + "&format=json";  if (confromtext != "")  {      sURL = sURL + "&cmcontinue=" + confromtext;  }  oRequest.open("GET",sURL,false);  oRequest.setRequestHeader("User-Agent",navigator.userAgent);  oRequest.send(null)  if (oRequest.status==200) var contact = (oRequest.responseText);  else alert("Error executing XMLHttpRequest call to receive category listing."); var p = eval('(' + contact + ')'); for (var i=0; i<p.query.categorymembers.length; i++) {   var newtitle = p.query.categorymembers[i].title; if (newtitle.substr(0,5) != "Talk:") { newtitle = "Talk:" + newtitle; } //artbox.appendItem( newtitle, newtitle ); var op = " " + newtitle + " "; document.getElementById('bodyContent').innerHTML = document.getElementById('bodyContent').innerHTML + op; boxclick(newtitle); } confrombox.value = p['query-continue'].categorymembers.cmcontinue; } function next { } function boxclick(atitle) { var oRequest = new XMLHttpRequest; //var wURL = "http://en.wikipedia.org/w/index.php?title=" + artbox.selectedItem.value + "&action=edit"; //b.loadURI(wURL); //get edit token var tURL = "http://en.wikipedia.org/w/api.php?action=query&prop=info|revisions&intoken=edit&titles=" + atitle + "&format=json"; oRequest.open("GET",tURL,false); oRequest.setRequestHeader("User-Agent",navigator.userAgent); oRequest.send(null); if (oRequest.status==200) var contact = (oRequest.responseText); else alert("Error getting edit token."); //alert(contact); var pah = contact.indexOf("starttimestamp"); var starttimestamp = contact.substring(pah+17,pah+37); //alert(starttimestamp); pah = contact.indexOf("edittoken"); var edittoken = contact.substring(pah+12,contact.indexOf("+\\",pah)); //alert(edittoken); // var p = eval('(' + contact + ')'); //alert(p.query.pages.length); // var starttimestamp = p.query.pages.page.starttimestamp; // var edittoken = p.query.pages.page.edittoken; // var mURL = "http://en.wikipedia.org/w/index.php?title=" + atitle + "&action=raw"; var mRequest = new XMLHttpRequest; mRequest.open("GET",mURL,false); mRequest.setRequestHeader("User-Agent",navigator.userAgent); mRequest.send(null); if (mRequest.status==200) var z = (mRequest.responseText); else var z = ""; //alert(z); if (z.indexOf()+2; }   if (y == -1) { y = x; }    z = z.substr(0,y) + '\n' + z.substr(y);  } else {     var op = " Adding project tag to top of page, above first heading (if a heading exists). ";     y = z.indexOf('==');     if (y == -1)     {  z = z +;     } else {        z = z.substr(0,y) + '\n' + z.substr(y);     }  } document.getElementById('bodyContent').innerHTML = document.getElementById('bodyContent').innerHTML + op; //alert (z); //  var poststring = "title=" + artbox.selectedItem.value; //  poststring = poststring + "&wpDiff=true"; //  poststring = poststring + "&wpTextbox1=" + z; //  poststring = poststring + "&wpSummary='Added project tag using WagTools'"; //  poststring = poststring + "&wpStarttime  = " + starttimestamp; //  poststring = poststring + "&wpEditToken  = " + edittoken; //  alert(poststring); //  poststring = formatPOSTdata(poststring); // alert(poststring); // var wURL = "http://en.wikipedia.org/w/index.php?action=submit&title=" + artbox.selectedItem.value; // b.loadURI(wURL, "", poststring); // b.loadURIWithFlags(wURL,"" ,"" ,"", poststring ); // b.loadURI(wURL); // var tb1= b.contentDocument.getElementById("wpTextbox1"); // var diffbutton= b.contentDocument.getElementById("wpDiff"); // var wpSummary= b.contentDocument.getElementById("wpSummary"); // alert("working"); // tb1.value=z; // wpSummary.value = "Project tagging using WagTools"; // alert("ready"); //diffbutton.submit; } function formatPOSTdata(dataString) { //var dataString = "name1=data1&name2=data2"; // POST method requests must wrap the encoded text in a MIME // stream const Cc = Components.classes; const Ci = Components.interfaces; var stringStream = Cc["@mozilla.org/io/string-input-stream;1"]. createInstance(Ci.nsIStringInputStream); if ("data" in stringStream) // Gecko 1.9 or newer stringStream.data = dataString; else // 1.8 or older stringStream.setData(dataString, dataString.length); var postData = Cc["@mozilla.org/network/mime-input-stream;1"]. createInstance(Ci.nsIMIMEInputStream); postData.addHeader("Content-Type", "application/x-www-form-urlencoded"); postData.addContentLength = true; postData.setData(stringStream); // postData is ready to be used as aPostData argument return postData; } //