User:Ais523/watchlistei.js

// // Watchlist export/import (User:ais523/watchlistei.js), by User:ais523.

// To use this script, visit Special:Watchlist and follow the new links for 'import' or 'export' // there. The exported watchlist can be copy/pasted into the edit box for import, and is also legal // (but somewhat obfuscated) wikitext for use with Special:Recentchangeslinked. Doesn't work in // Internet Explorer, does work in Firefox 1, I haven't checked other browsers.

// To install this script, the easiest way is to type User:ais523/watchlistei.js at the // bottom of Special:Mypage/monobook.js, and bypass your cache (Ctrl-F5 in Firefox for Windows).

// Each line of an exported watchlist is in the form // *urlencodedpagename

// Note that this feature is now part of the software, making this script redundant.

if(navigator.userAgent.indexOf("MSIE")==-1) // fail gracefully in IE { // AJAX var wleiwpajax; // From WP:US mainpage (wpajax renamed to wleiwpajax) wleiwpajax={ download:function(bundle) { // mandatory: bundle.url // optional: bundle.onSuccess (xmlhttprequest, bundle) // optional: bundle.onFailure (xmlhttprequest, bundle) // optional: bundle.otherStuff OK too, passed to onSuccess and onFailure var x = window.XMLHttpRequest ? new XMLHttpRequest : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false; if (x) { x.onreadystatechange=function { x.readyState==4 && wleiwpajax.downloadComplete(x,bundle); };                       x.open("HEAD",bundle.url,true); x.send(null); }               return x;        },

downloadComplete:function(x,bundle) { x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true ) || ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText)); } };

var wleiRunOnce=1; // Links to export and import $(function{ if(wgPageName=="Special:Watchlist"&&location.href.indexOf("list/")==-1&&wleiRunOnce)  {    wleiRunOnce=0;    var t=document.getElementById('bodyContent').getElementsByTagName('hr')[0];    var n=document.createElement("p");    t.parentNode.replaceChild(n,t);    n.innerHTML="You can also export this watchlist or import pages from an exported watchlist. ";  } });

var wleiExRunOnce=1; // Exporting: producing the list $(function{ if(location.href.indexOf("Special:Watchlist/edit?ais523wlei=export")!=-1&&wleiExRunOnce)  {    wleiExRunOnce=0;    var a=document.getElementById('bodyContent').getElementsByTagName('input');    var b=new Array;    b[0]=" Exported watchlist: \n ";    var i=0;    while(i \n"+      "Import watchlist \n"+      "Pages not yet processed: 0, retrying: 0 "+      "(total retries: 0 , 4 retries max per page allowed), "+      "succeeded: 0 , failed: 0 . \n"+      "Return to watchlist.\n ";  } });

function wleiImport { var a=document.getElementById('watchlistImport').value.split('\r').join('\n').split('\n'); var i=a.length; while(i--) {   var m=a[i].match(/^\** *\[\[(.*)\]\] *$/); if(m!=undefined&&m[1]!=undefined&&m[1]!="") {     watchPageUsingAJAX(m[1]); document.getElementById('wlein').innerHTML= 1+new Number(document.getElementById('wlein').innerHTML); } } }

function wleiSuccess(a,b) { document.getElementById('wleis').innerHTML= 1+new Number(document.getElementById('wleis').innerHTML); if(b.isRetrying) {   document.getElementById('wleif').innerHTML= new Number(document.getElementById('wleif').innerHTML)-1; } else {   document.getElementById('wlein').innerHTML= new Number(document.getElementById('wlein').innerHTML)-1; } } function wleiFailure(a,b) { if(!b.isRetrying) {   document.getElementById('wleif').innerHTML= 1+new Number(document.getElementById('wleif').innerHTML); document.getElementById('wlein').innerHTML= new Number(document.getElementById('wlein').innerHTML)-1; } b.isRetrying++; if(b.isRetrying<5) {   document.getElementById('wleir').innerHTML= 1+new Number(document.getElementById('wleir').innerHTML); window.setTimeout(function{wleiwpajax.download(b);},a.getResponseHeader('Retry-After')*1000); } else {   document.getElementById('wleif').innerHTML= new Number(document.getElementById('wleif').innerHTML)-1; document.getElementById('wleic').innerHTML= new Number(document.getElementById('wleic').innerHTML)+1; if(document.getElementById('faillist').innerHTML=='') document.getElementById('faillist').innerHTML='Failed:'; document.getElementById('faillist').innerHTML+= ' *'+b.urlencodedpagename+''; } return 1; }

function watchPageUsingAJAX(urlencodedpagename) { wleiwpajax.download({url:'http://en.wikipedia.org/w/index.php?title='+urlencodedpagename+    '&action=watch&maxlag=5', onSuccess:wleiSuccess, onFailure:wleiFailure, isRetrying:0,    urlencodedpagename:urlencodedpagename}); } } // //