User:FlightTime/Strike-blocked.js
Appearance
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 code will be executed when previewing this page.
This user script seems to have a documentation page at User:FlightTime/Strike-blocked.
//If you add this script to your skin.js, it will mark all linked blocked users with a strikethrough, and mark all linked indefinitely blocked users with italics and a strikethrough. // // Installation Method 1: // Add the following line to your skin.js // importScript('User:FlightTime/Mark-blocked.js'); // Linkback: [[User:FlightTime/Mark-blocked.js]] // // Installation Method 2: // Just copy and paste the un-commented part of this page // functionmarkBlocked(container){ varipv6Regex=/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!3円)::|:\b|$))|(?!2円3円)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i; // Collect all the links in the page's content varcontentLinks=$(container).find('a'); varmbTooltip=window.mbTooltip||'; blocked (1ドル) by 2ドル: 3ドル (4ドル ago)'; // Get all aliases for user: & user_talk: varuserNS=[]; for(varnsinmw.config.get('wgNamespaceIds')){ if(mw.config.get('wgNamespaceIds')[ns]==2||mw.config.get('wgNamespaceIds')[ns]==3){ userNS.push(mw.util.escapeRegExp(ns.replace(/_/g,' '))+':'); } } // Let wikis that are importing this script specify the local alias of Special:Contributions if(window.markblocked_contributions===undefined){ window.markblocked_contributions='Special:Contributions'; } // RegExp for all titles that are User:| User_talk: | Special:Contributions/ (for userscripts) varuserTitleRX=newRegExp('^('+userNS.join('|')+'|'+window.markblocked_contributions+'\\/)+([^\\/#]+)$','i'); // RegExp for links // articleRX also matches external links in order to support the noping template vararticleRX=newRegExp(mw.config.get('wgArticlePath').replace('1ドル','')+'([^#]+)'); varscriptRX=newRegExp('^'+mw.config.get('wgScript')+'\\?title=([^#&]+)'); varuserLinks={}; varuser,url,ma,pgTitle; // Find all "user" links and save them in userLinks : { 'users': [<link1>, <link2>, ...], 'user2': [<link3>, <link3>, ...], ... } contentLinks.each(function(i,lnk){ if($(lnk).hasClass("mw-changeslist-date")||$(lnk).parent("span").hasClass("mw-history-undo")||$(lnk).parent("span").hasClass("mw-rollback-link")) { return; } url=$(lnk).attr('href'); if(!url){ return; } if(ma=articleRX.exec(url)){ pgTitle=ma[1]; }elseif(ma=scriptRX.exec(url)){ pgTitle=ma[1]; }else{ return; } pgTitle=decodeURIComponent(pgTitle).replace(/_/g,' '); user=userTitleRX.exec(pgTitle); if(!user){ return; } user=user[2]; if(ipv6Regex.test(user))user=user.toUpperCase(); $(lnk).addClass('userlink'); if(!userLinks[user]){ userLinks[user]=[]; } userLinks[user].push(lnk); }); // Convert users into array varusers=[]; for(varuinuserLinks){ users.push(u); } if(users.length===0){ return; } // API request varserverTime,apiRequests=0; container.addClass('markblocked-loading'); while(users.length>0){ apiRequests++; $.post( mw.util.wikiScript('api')+'?format=json&action=query', { list:'blocks', bklimit:100, bkusers:users.splice(0,50).join('|'), bkprop:'user|by|timestamp|expiry|reason|restrictions' // no need for 'id|flags' }, markLinks ); } return;// the end // Callback: receive data and mark links functionmarkLinks(resp,status,xhr){ serverTime=newDate(xhr.getResponseHeader('Date')); varlist,blk,tip,links,lnk; if(!resp||!(list=resp.query)||!(list=list.blocks)){ return; } for(vari=0;i<list.length;i++){ blk=list[i]; varpartial=blk.restrictions&&!Array.isArray(blk.restrictions);//Partial block if(/^in/.test(blk.expiry)){ clss=partial?'user-blocked-partial':'user-blocked-indef'; blTime=blk.expiry; }else{ clss=partial?'user-blocked-partial':'user-blocked-temp'; blTime=inHours(parseTS(blk.expiry)-parseTS(blk.timestamp)); } tip=mbTooltip; if(partial){ tip=tip.replace('blocked','partially blocked'); } tip=tip.replace('1ドル',blTime) .replace('2ドル',blk.by) .replace('3ドル',blk.reason) .replace('4ドル',inHours(serverTime-parseTS(blk.timestamp))); links=userLinks[blk.user]; for(vark=0;links&&k<links.length;k++){ lnk=$(links[k]); lnk=lnk.addClass(clss); if(window.mbTipBox){ $('<span class=user-blocked-tipbox>#</span>').attr('title',tip).insertBefore(lnk); }else{ lnk.attr('title',lnk.attr('title')+tip); } } } if(--apiRequests===0){// last response container.removeClass('markblocked-loading'); $('#ca-showblocks').parent().remove();// remove added portlet link } } // --------AUX functions // 20081226220605 or 2008年01月26日T06:34:19Z -> date functionparseTS(ts){ varm=ts.replace(/\D/g,'').match(/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/); returnnewDate(Date.UTC(m[1],m[2]-1,m[3],m[4],m[5],m[6])); } functioninHours(ms){// milliseconds -> "2:30" or 5,06d or 21d varmm=Math.floor(ms/60000); if(!mm){ returnMath.floor(ms/1000)+'s'; } varhh=Math.floor(mm/60); mm=mm%60; vardd=Math.floor(hh/24); hh=hh%24; if(dd){ returndd+(dd<10?'.'+zz(hh):'')+'d'; } returnhh+':'+zz(mm); } functionzz(v){// 6 -> '06' if(v<=9){ v='0'+v; } returnv; } }// -- end of main function // Start on some pages switch(mw.config.get('wgAction')){ case'edit': case'submit': break; default:// 'view', 'history', 'purge', ... varmaybeAutostart=$.Deferred(); if(window.mbNoAutoStart){ varportletLink=mw.util.addPortletLink('p-cactions','','XX','ca-showblocks'); $(portletLink).click(function(e){ e.preventDefault(); maybeAutostart.resolve(); }); }else{ maybeAutostart.resolve(); } $.when($.ready,mw.loader.using('mediawiki.util'),maybeAutostart).then(function(){ varfirstTime=true; mw.hook('wikipage.content').add(function(container){ // On the first call after initial page load, container is mw.util.$content // Used to limit mainspace activity to just the diff definitions if(mw.config.get('wgAction')==='view'&&mw.config.get('wgNamespaceNumber')===0){ container=container.find('.diff-title'); } if(firstTime){ firstTime=false; // On page load, also update the namespace tab container=container.add('#ca-nstab-user'); mw.util.addCSS('\ .markblocked-loading a.userlink {opacity:'+(window.mbLoadingOpacity||0.85)+'}\ a.user-blocked-temp {'+(window.mbTempStyle||'opacity: 0.7; text-decoration: line-through')+'}\ a.user-blocked-indef {'+(window.mbIndefStyle||'opacity: 0.4; font-style: italic; text-decoration: line-through')+'}\ a.user-blocked-partial {'+(window.mbPartialStyle||'text-decoration: underline; text-decoration-style: dotted')+'}\ .user-blocked-tipbox {'+(window.mbTipBoxStyle||'font-size:smaller; background:#FFFFF0; border:1px solid #FEA; padding:0 0.3em; color:#AAA')+'}\ '); } markBlocked(container); }); }); }