Jump to content
Wikipedia The Free Encyclopedia

User:Splarka/oldafd.js

From Wikipedia, the free encyclopedia
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This user script seems to have a documentation page at User:Splarka/oldafd.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
 /* AFD age detector, version [0.0.2a]
 Originally from: http://en.wikipedia.org/wiki/User:Splarka/oldafd.js

 Notes:
 * Stuff
 */

 if(mw.config.get('wgCurRevisionId')!=0&&mw.config.get('wgNamespaceNumber')==4&&(mw.config.get('wgPageName').indexOf('_for_deletion/')!=-1||mw.config.get('wgPageName').indexOf('_for_discussion/')!=-1))addOnloadHook(function(){
 varurl=mw.config.get('wgScriptPath')+'/api.php?maxage=3600&smaxage=3600&action=query&indexpageids&prop=revisions&rvdir=newer&rvlimit=1&rvprop=timestamp|comment|user&format=json&callback=ageCheckAFDCB&pageids='+mw.config.get('wgArticleId');
 mw.loader.load(url);
 });

 functionageCheckAFDCB(obj){
 varsub=document.getElementById('contentSub')||document.getElementById('topbar');
 vardiv=document.createElement('div');
 sub.appendChild(div);
 if(!obj['query']||!obj['query']['pages']||obj['query']['pages'].length==0||!obj['query']['pageids']||obj['query']['pageids'].length==0||obj['error']){
 div.appendChild(document.createTextNode('Api error in AFD Age Detector.'));
 return;
 }
 varid=obj['query']['pageids'][0];
 varpage=obj['query']['pages'][id];
 varrev=page['revisions'][0];
 if(!rev||!rev['timestamp']||!rev['user'])return

 varnow=newDate();
 vartsd=newDate();
 tsd.setISO8601(rev['timestamp']);
 vartimesince=Math.floor((now-tsd)/1000);
 if(timesince=='')timesince=-1
 varrevinfo='Page created: '+duration(timesince)+' ago by '+rev['user'];
 if(rev['comment'])div.setAttribute('title',rev['comment'])
 if(!rev['comment']||rev['comment'].indexOf('Created')==-1)div.style.color='#ff0000'
 div.appendChild(document.createTextNode(revinfo+'.'));
 if(timesince>604800)appendCSS('body {background:#ffaaff !important;}')
 }

 functionduration(input,depth){
 varnum=input;
 varout='';
 vars=num%60;num=Math.floor(num/60);
 varm=num%60;num=Math.floor(num/60);
 varh=num%24;num=Math.floor(num/24);
 vard=num%7;num=Math.floor(num/7);
 varw=num%52;num=Math.floor(num/52);
 vary=num
 if(y>0)out+=y+'yrs '
 if(y+w>0)out+=w+'wks '
 if(y+w+d>0)out+=d+'days '
 if(y+w+d+h>0)out+=h+'hrs '
 if(y+w+d+h+m>0)out+=m+'mins '
 out+=s+'secs';
 if(depth&&depth<out.split(' ').length){
 out=out.split(' ').slice(0,depth).join(' ');
 }
 returnout;
 }

 //ISO 8601 date module by Paul Sowden, licensed under AFL.
 Date.prototype.setISO8601=function(string){
 if(!string)return
 varregexp='([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?';
 vard=string.match(newRegExp(regexp));
 if(d.length<1)return
 varoffset=0;
 vardate=newDate(d[1],0,1);
 if(d[3])date.setMonth(d[3]-1)
 if(d[5])date.setDate(d[5])
 if(d[7])date.setHours(d[7])
 if(d[8])date.setMinutes(d[8])
 if(d[10])date.setSeconds(d[10])
 if(d[12])date.setMilliseconds(Number('0.'+d[12])*1000)
 if(d[14]){
 offset=(Number(d[16])*60)+Number(d[17]);
 offset*=((d[15]=='-')?1:-1);
 }
 offset-=date.getTimezoneOffset();
 time=(Number(date)+(offset*60*1000));
 this.setTime(Number(time));
 }

AltStyle によって変換されたページ (->オリジナル) /