_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:Yair rand/interwikiwatchlist2.js

In the world of User:Yair rand/interwikiwatchlist2.js, there are endless aspects that deserve to be explored and analyzed carefully. From its origins to its relevance today, User:Yair rand/interwikiwatchlist2.js has been the subject of fascination and debate. In this article you will embark on a journey through the different aspects that make up User:Yair rand/interwikiwatchlist2.js, from its sociocultural implications to its impact on everyday life. Through reflection and deep analysis, you will discover the complexity and importance of User:Yair rand/interwikiwatchlist2.js in the modern world. Get ready to expand your horizons and immerse yourself in a universe of knowledge and discovery!
// newNode from ], JsMwApi from ].
// Previous version (works without enhanced RC) at ].
// To enable, turn on "Enhanced recent changes (requires JavaScript)" 
// in ], and add 
// importScript ("User:Yair rand/interwikiwatchlist2.js"); 
// to ].

// NOTE: this script is buggy and does not work on certain browsers.
function newNode(tagname){
 
  var node = document.createElement(tagname);
 
  for( var i=1;i<arguments.length;i++ ){
 
    if(typeof arguments == 'string'){ //Text
      node.appendChild( document.createTextNode(arguments) );
 
    }else if(typeof arguments == 'object'){ 
 
      if(arguments.nodeName){ //If it is a DOM Node
        node.appendChild(arguments);
 
      }else{ //Attributes (hopefully)
        for(var j in arguments){
          if(j == 'class'){ //Classname different because...
            node.className = arguments;
 
          }else if(j == 'style'){ //Style is special
            node.style.cssText = arguments;
 
          }else if(typeof arguments == 'function'){ //Basic event handlers
            try{ node.addEventListener(j,arguments,false); //W3C
            }catch(e){try{ node.attachEvent('on'+j,arguments,"Language"); //MSIE
            }catch(e){ node=arguments; }}; //Legacy
 
          }else{
            node.setAttribute(j,arguments); //Normal attributes
 
          }
        }
      }
    }
  }
 
  return node;
}

//JsMwApi documentation is at http://en.wiktionary.orghttps://wiki386.com/en/User_talk:Conrad.Irwin/Api.js
function JsMwApi (api_url, request_type) {
 
	if (!api_url) 
	{
		if (typeof(true) === 'undefined' || true == false)
			throw "Local API is not usable.";
 
		api_url = mw.config.get('wgScriptPath') + "/api.php";
	}
 
	if (!request_type)
	{
		if (api_url.indexOf('http://') == 0 || api_url.indexOf('https://') == 0)
			request_type = "remote";
		else
			request_type = "local";
	}
	function call_api (query, callback)
	{
		if(!query || !callback)
			throw "Insufficient parameters for API call";
 
		query = serialise_query(query);
 
		if(request_type == "remote")
			request_remote(api_url, query, callback, call_api.on_error || default_on_error);
		else
			request_local(api_url, query, callback, call_api.on_error || default_on_error);
 
	}
 
	var default_on_error = JsMwApi.prototype.on_error || function (xhr, callback, res)
	{
		if (typeof(console) != 'undefined')
			console.log();
 
		callback(null);
	}
 
	function get_xhr () 
	{
		try{
			return new XMLHttpRequest();
		}catch(e){ try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){ try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			throw "Could not create an XmlHttpRequest";
		}}}
	}
 
	function request_local (url, query, callback, on_error)
	{
		var xhr = get_xhr();
 
		xhr.open('POST', url + '?format=json', true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
		xhr.send(query);
		xhr.onreadystatechange = function ()
		{
			if (xhr.readyState == 4)
			{
				var res;
				if (xhr.status != 200)
					res = {error: {
						code: '_badresponse', 
						info: xhr.status + " " + xhr.statusText
					}};
				else
				{
					try
					{
						res = JSON.parse("("+xhr.responseText+")");
					}
					catch(e)
					{
						res = {error: {
							code: '_badresult',
							info: "The server returned an incorrectly formatted response"
						}};
					}
				}
				if (!res || res.error || res.warnings)
					on_error(xhr, callback, res);
				else
					callback(res);
			}
		}
	}
 
	function request_remote (url, query, callback, on_error)
	{
		if(! window.__JsMwApi__counter)
			window.__JsMwApi__counter = 0;
 
		var cbname = '__JsMwApi__callback' + window.__JsMwApi__counter++; 
 
		window = function (res)
		{
			if (res.error || res.warnings)
				on_error(null, callback, res);
			else
				callback(res);
		}
 
		var script = document.createElement('script');
		script.setAttribute('type', 'text/javascript');
		script.setAttribute('src', url + '?format=json&callback=window.' + cbname + '&' + query);
		document.getElementsByTagName('head').appendChild(script);
	}
 
	function serialise_query (obj)
	{
		var amp = "";
		var out = "";
		if (String(obj) === obj)
		{
			out = obj;
		}
		else if (obj instanceof Array)
		{
			for (var i=0; i < obj.length; i++)
			{
				out += amp + serialise_query(obj);
				amp = (out == '' || out.charAt(out.length-1) == '&') ? '' : '&';
			}
		}
		else if (obj instanceof Object)
		{
			for (var k in obj)
			{
				if (obj === true)
					out += amp + encodeURIComponent(k) + '=1';
				else if (obj === false)
					continue;
				else if (obj instanceof Array)
					out += amp + encodeURIComponent(k) + '=' + encodeURIComponent(obj.join('|'));
				else if (obj instanceof Object)
					throw "API parameters may not be objects";
				else
					out += amp + encodeURIComponent(k) + '=' + encodeURIComponent(obj);
				amp = '&';
			}
		}
		else if (typeof(obj) !== 'undefined' && obj !== null)
		{
			throw "An API query can only be a string or an object";
		}
		return out;
	}
 
	// Make JSON.parse work
	var JSON = (typeof JSON == 'undefined' ? new Object() : JSON);
 
	if (typeof JSON.parse != 'function')
		JSON.parse = function (json) { return eval('(' + json + ')'); };
 
	// Allow .prototype. extensions
	if (JsMwApi.prototype)
	{
		for (var i in JsMwApi.prototype)
		{
			call_api = JsMwApi.prototype;
		}
	}
	return call_api;
}

mw.config.get('wgPageName') == "Special:Watchlist" && 'localStorage' in window && jQuery(document).ready(function(){
  function doubledigits(n){return (+n)<10?'0'+n:''+n}
  var v = document.getElementById("mw-watchlist-options") || $(".mw-specialpage-summary");
  var qw, er=, 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':'https://wiki386.com/en/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(!/^{2,3}(-?{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.toLowerCase());
        localStorage = (localStorage?localStorage+"|":"")+importedurl;
        localStorage=bn.value;
        location.reload();
        return false}
    for(var i = 0; i < er.length; i++){qw.appendChild(newNode('option',{'value':i},er))};
    function df(){
      if(/^{2,3}(-?{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.toLowerCase())+".orghttps://wiki386.com/en/Special:Preferences#mw-prefsection-watchlist";
        }
      }
    cv.onchange=qw.onchange=df;
    }})));
  for(var k = localStorage?localStorage.split("|"):, ii=0; ii < k.length; ii++){
    function st(rt){
      var tkn = localStorage, 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 = localStorage.replace(rt,'').replace(/(^\||\|\||\|$)/,'');
        location.reload()
        }}),', '))
      var d = new Date(+new Date()+new Date().getTimezoneOffset()*60000-mw.user.options.get('watchlistdays')*24*60*60*1000); d = d.getFullYear()+'-'+doubledigits(d.getMonth()+1)+'-'+doubledigits(d.getDate())+"T"+doubledigits(d.getHours())+":"+doubledigits(d.getMinutes())+":"+doubledigits(d.getSeconds())+"Z";
      JsMwApi(project + "w/api.php")({action:'query',list:'watchlist',wlowner:mw.config.get('wgUserName'),wltoken:tkn,
       wlexcludeuser:mw.user.options.get('watchlisthideown')?mw.config.get('wgUserName'):'Example',wlprop:'title|flags|user|parsedcomment|timestamp|ids|sizes',wllimit:500,wlend:d},function(r){
/*
        var b=newNode('div',{'style':'display:'+
          (localStorage?'none;':'block;')
          });
*/
        var g = r && r.query && r.query.watchlist;
        if(!g) g = ;
        for(var i = 0; i < g.length; i++){try{
          var zx = newNode('span',{class:'comment'}); zx.innerHTML = g.parsedcomment && ' ('+g.parsedcomment.replace(/\ href\=\"\//g,' href="'+project)+')';
          var date = (new Date(+new Date(g.timestamp)+new Date().getTimezoneOffset()*60000)), day = date.getDate(), month = date.getMonth(), time = g.timestamp.match(/\d\d\:\d\d/);time=time&&time;
          var sizediff = g.newlen-g.oldlen;
          var table = newNode('table',{'class':'mw-enhanced-rc'},newNode('tbody',newNode('tr',newNode('td',{'class':"mw-enhanced-rc"},newNode('span',{"class":"mw-enhancedchanges-arrow-space"}),
            ("new" in g?newNode("abbr",{class:"newpage"},"N"):" "),
            ("bot" in g?newNode("abbr",{class:"botedit"},"b"):"minor" in g?newNode("abbr",{class:"minoredit"},"m"):" "),
            "       "+time+" "),newNode('td',
            newNode('a',g.title,{class:'extiw',href:project+"wiki/"+g.title}),
            ' (',
            newNode('a','diff',{href:project+"w/index.php?title="+g.title+"&curid="+g.pageid+"&diff="+g.revid}),
            ' | ',
            newNode('a','hist',{href:project+"w/index.php?title="+g.title+"&curid="+g.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.user},g.user),
            ' (',
            newNode('a',{class:'extiw',href:project+"wiki/User talk:"+g.user},'Talk'),
            ' | ',
            newNode('a',{class:'extiw',href:project+"wiki/Special:Contributions/"+g.user},'contribs'),
            ') ',
            zx
            ))));
          for(var ii = $(".mw-changeslist").firstChild; 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.parentNode.parentNode.parentNode.appendChild(table);
                    break;
                    }
                  var tds = trs.getElementsByTagName('td'),
                	td = tds&&tds.className=='mw-enhanced-rc'?tds:tds;
                  //if( +(((td.innerText || td.textContent).match(/\d/g)||).join("")) < time){
                  try{
                  	var match = (td.innerText || td.textContent).match(/\d\d\:\d\d/g);
                  	if( match && match < time){
	                    trs.parentNode.parentNode.parentNode.insertBefore(table, trs.parentNode.parentNode);
	                    break;
                    }}catch(a){
                    	throw new Error( 22, a, trs.parentNode.parentNode );
                	}
                  }
                break;
                }
              }
            if(ii.className == 'printfooter'){
              ii.parentNode.insertBefore(newNode("h4", date.getDate()+' '++' '+date.getFullYear()), ii);
              ii.parentNode.insertBefore(newNode('div', table), ii);
              }
            }
          }catch(err){window.console&&console.log(err.stack)}}
        });
      }
    st(k);
    }
  })