User:Yair rand/superwatchlist2.js

// Interwiki watchlist

mw.config.get('wgPageName') == "Special:Watchlist" && 'localStorage' in window && jQuery(document).ready(function{ var v=document.getElementById("mw-watchlist-options");  var qw, er=['Wikipedia','Wiktionary','Wikibooks','Wikisource','Wikiquote','Wikiversity','Wikinews','Meta-Wiki','Commons','Wikispecies','Mediawiki'], cv, bn, sd;  var wspan;  v.appendChild(newNode('hr'));  v.appendChild(newNode('span', 'Interwiki watchlists: ', wspan = newNode('span'), newNode('a','(+new watchlist)',{href:"#",click:function{ v.lastChild.lastChild.style.display='none'; v.appendChild(newNode('form', 'Language: ',cv=newNode('input',{size:3}), ' Project: ', qw=newNode('select'), newNode('br'), 'Watchlist token ',newNode('small','(can be found be found at ',sd=newNode('a','Special:Preferences',{'href':'/wiki/Special:Preferences#mw-prefsection-watchlist'}),' in the Watchlist section)'),': ',bn=newNode('input'), newNode('input',{'type':'submit','value':'Import watchlist'}),newNode('span',{style:'color:red;'}))).onsubmit = function{ if(!/^[a-z]{2,3}(-?[a-z]{2,3})?$/.test(cv.value) && qw.value <=6 || !bn.value){ bn.parentNode.lastChild.innerHTML = bn.value?"Choose a valid language code.":"Enter watchlist token." return false }       var importedurl=(qw.value > 6?(qw.value==7?"meta.wikimedia":qw.value==8?'commons.wikimedia':qw.value==9?'species.wikimedia':'mediawiki'):cv.value+'.'+er[qw.value].toLowerCase) localStorage['importedwatchlists'+mw.config.get('wgUserName')] = (localStorage['importedwatchlists'+mw.config.get('wgUserName')]?localStorage['importedwatchlists'+mw.config.get('wgUserName')]+"|":"")+importedurl; localStorage['importedwatchlist'+mw.config.get('wgUserName')+importedurl+'token']=bn.value; location.reload return false} for(var i = 0; i < er.length; i++){qw.appendChild(newNode('option',{'value':i},er[i]))}; function df{ if(/^[a-z]{2,3}(-?[a-z]{2,3})?$/.test(cv.value) || qw.value >6){ sd.href = "//"+(qw.value > 6?(qw.value==7?"meta.wikimedia":qw.value==8?'commons.wikimedia':qw.value==9?'species.wikimedia':'mediawiki'):cv.value+'.'+er[qw.value].toLowerCase)+".org/wiki/Special:Preferences#mw-prefsection-watchlist" }     }    cv.onchange=qw.onchange=df }}))) for(var k = localStorage['importedwatchlists'+mw.config.get('wgUserName')]?localStorage['importedwatchlists'+mw.config.get('wgUserName')].split("|"):[], ii=0; ii < k.length; ii++){    function st(rt){      var tkn = localStorage['importedwatchlist'+mw.config.get('wgUserName')+rt+'token'], project = location.protocol+"//"+rt+".org/";      wspan.appendChild(newNode('span',project, ' ', newNode('a','(remove)',{click:function{ localStorage.removeItem('importedwatchlist'+mw.config.get('wgUserName')+rt+'token'); localStorage.removeItem('importedwatchlist'+mw.config.get('wgUserName')+rt+'hidden'); localStorage['importedwatchlists'+mw.config.get('wgUserName')] = localStorage['importedwatchlists'+mw.config.get('wgUserName')].replace(rt,).replace(/(^\||\|\||\|$)/,); location.reload }}),', '))     var d = new Date(new Date-mw.user.options.values.watchlistdays*24*60*60*1000); d = d.getFullYear+'-'+(d.getMonth+1)+'-'+(d.getDate<10?'0'+d.getDate:d.getDate)+"T"+d.toLocaleTimeString+"Z"      JsMwApi(project + "w/api.php")({action:'query',list:'watchlist',wlowner:mw.config.get('wgUserName'),wltoken:tkn, wlexcludeuser:mw.user.options.values.watchlisthideown?mw.config.get('wgUserName'):'Example',wlprop:'title|flags|user|parsedcomment|timestamp|ids|sizes',wllimit:50,wlend:d},function(r){t=r /*       var b=newNode('div',{'style':'display:'+          (localStorage['importedwatchlist'+mw.config.get('wgUserName')+rt+'hidden']?'none;':'block;')          }); var g=r.query.watchlist; for(var i = 0; i < g.length; i++){try{ var zx = newNode('span',{class:'comment'}); zx.innerHTML = g[i].parsedcomment && ' ('+g[i].parsedcomment.replace(/\ href\=\"\//g,' href="'+project)+')'; var date = (new Date(g[i].timestamp)), day = date.getDate, month = date.getMonth, time = g[i].timestamp.match(/\d\d\:\d\d/);time=time&&time[0] var sizediff = g[i].newlen-g[i].oldlen; var table = newNode('table',{'class':'mw-enhanced-rc'},newNode('tbody',newNode('tr',newNode('td',{'class':"mw-enhanced-rc"},newNode('img',{"src":"//bits.wikimedia.org/skins-1.18/common/images/Arr_.png","width":12,"height":12,"alt":" "}), ("new" in g[i]?newNode("abbr",{class:"newpage"},"N"):" "), ("bot" in g[i]?newNode("abbr",{class:"botedit"},"b"):"minor" in g[i]?newNode("abbr",{class:"minoredit"},"m"):" "), "   "+time+" "),newNode('td', newNode('a',g[i].title,{class:'extiw',href:project+"wiki/"+g[i].title}), ' (',           newNode('a','diff',{href:project+"w/index.php?title="+g[i].title+"&curid="+g[i].pageid+"&diff="+g[i].revid}),            ' | ',            newNode('a','hist',{href:project+"w/index.php?title="+g[i].title+"&curid="+g[i].pageid+"&action=history"}),            '). . ',           newNode(Math.abs(sizediff)>500?'strong':'span',{class:'mw-plusminus-'+(sizediff>0?'pos':'neg')},'('+(sizediff>0?"+":"")+sizediff+")"), ' . . ',           newNode('a',{class:'extiw',href:project+"wiki/User:"+g[i].user},g[i].user), ' (',           newNode('a',{class:'extiw',href:project+"wiki/User talk:"+g[i].user},'Talk'),            ' | ',            newNode('a',{class:'extiw',href:project+"wiki/Special:Contributions/"+g[i].user},'contribs'),            ') ', zx           )))) for(var ii = v; ii; ii = ii.nextSibling){ if(ii.nodeName == "H4"){ var hdate = new Date(ii.innerText || ii.textContent); if(hdate.getMonth == month && hdate.getDate == day){ for(ii && ii.nodeName != "DIV"; ii = ii.nextSibling); for(var trs = $(ii).find('tr:first-child'), iii = 0; true; iii++){ if(iii >= trs.length){ trs[iii-1].parentNode.parentNode.parentNode.appendChild(table); break; }                 var tds = trs[iii].getElementsByTagName('td'), td = tds[0].className=='mw-enhanced-rc'?tds[0]:tds[1]; //if( +(((td.innerText || td.textContent).match(/\d/g)||[]).join("")) < time){ try{if((td.innerText || td.textContent).match(/\d\d\:\d\d/)[0] < time){ trs[iii].parentNode.parentNode.parentNode.insertBefore(table, trs[iii].parentNode.parentNode) break; }}catch(a){throw new Error("sploo")} }               break; }             }            if(ii.className == 'printfooter'){ ii.parentNode.insertBefore(newNode("h4", date.getDate+' '+['January','February','March','April','May','June','July','August','September','October','November','December'][date.getMonth]+' '+date.getFullYear), ii); ii.parentNode.insertBefore(newNode('div', table), ii); }           }          }catch(err){window.console&&console.log(err.stack)}} })     }    st(k[ii])    }  })