User:R'n'B/dabcolorizer.min.js

importScript("User:R'n'B/wrappi.js");if(!mw.RnB)mw.RnB={};mw.RnB.titleUrl=function(c){c=mw.util.wikiUrlencode(c);c=c.slice(0,1).toUpperCase+c.slice(1);return c.replace(/%21/g,"!").replace(/%24/g,"$").replace(/%28/g,"(").replace(/%29/g,")").replace(/%2A/g,"*").replace(/%2C/g,",").replace(/%3B/g,";").replace(/%40/g,"@")}; mw.RnB.dabtag={initialize:function{var c=mw.RnB.dabtag;mw.RnB.Wiki?(c.api=new mw.RnB.Wiki,c.api.request({action:"query",rawcontinue:"",prop:"links",titles:"MediaWiki:Disambiguationspage",plnamespace:"10",pllimit:"max"},function(b){var d,a,e;c.dabTemplates=[];for(a in b.query.pages)if(b.query.pages.hasOwnProperty(a))for(d in e=b.query.pages[a],e.links)e.links.hasOwnProperty(d)&&c.dabTemplates.push(e.links[d].title);jQuery(function{var a=document.createElement("div");a.appendChild(document.createTextNode("dabtag: loading")); a.id="colorizerStatus";jQuery("#siteSub").after(a);mw.RnB.statusDiv=jQuery("#colorizerStatus");mw.RnB.statusDiv.css({display:"block","font-size":"92%","font-weight":"normal"});c.api.request(c.params,c.botCallback);mw.RnB.statusDiv.text("dabcolorizer: waiting for data")})})):setTimeout(c.initialize,100)},doHighlighting:function(c){var b='a[href="/wiki/'+mw.RnB.titleUrl(c)+'"]',d='a[href^="/wiki/'+mw.RnB.titleUrl(c)+'#"]';mw.log("Looking for "+b);jQuery(b).add(d).addClass(c.indexOf("(disambiguation)")=== -1?"dabpagelink":"dabpagelink intdablink")},params:{action:"query",rawcontinue:"",generator:"links",prop:"info|revisions|templates",gplnamespace:"0",gpllimit:"max",titles:mw.config.get("wgPageName"),tllimit:"max",redirects:""},pagelinkdata:{},ready:!1,redirectsFromTo:{},redirectsToFrom:{},botCallback:function(c){var b=mw.RnB.dabtag,d,a,e,f,g;if(c.query){f=c["query-continue"];if(b.queryContinue=f){if(f.templates)b.params.tlcontinue=f.templates.tlcontinue,delete b.params.gplcontinue;else if(f.links)delete b.params.tlcontinue, b.params.gplcontinue=f.links.tlcontinue;b.api.request(b.params,b.botCallback)}mw.RnB.statusDiv.text("dabcolorizer: working");d=c.query.redirects;if(d!==void 0)for(a=0;a<d.length;a++)b.redirectsFromTo[d[a].from]=d[a].to,b.redirectsToFrom[d[a].to]=d[a].from;for(e in c.query.pages)if(c.query.pages.hasOwnProperty(e)){a=c.query.pages[e];if(b.pagelinkdata.hasOwnProperty(e)){if(a.hasOwnProperty("templates"))b.pagelinkdata[e].hasOwnProperty("templates")?jQuery.merge(b.pagelinkdata[e].templates,a.templates): b.pagelinkdata[e].templates=a.templates}else b.pagelinkdata[e]=a,mw.log("Saving data for page "+a.title);if(e<0)mw.log("Skipping redlink "+a.title);else if(a.hasOwnProperty("known_dab"))mw.log("Skipping known dab "+a.title);else if(a.hasOwnProperty("templates")){mw.log("Checking templates on page "+a.title);d=!1;for(g=0;g<a.templates.length;g++)if(b.dabTemplates.indexOf(a.templates[g].title)!==-1){d=!0;break}if(d)a.known_dab=!0,b.doHighlighting(a.title),b.redirectsToFrom[a.title]&&b.doHighlighting(b.redirectsToFrom[a.title])}}f? mw.RnB.statusDiv.text("dabcolorizer: waiting for data"):(mw.RnB.statusDiv.text("dabcolorizer: done!"),mw.RnB.statusDiv.fadeOut("slow"))}else{mw.log("Page link query failed!");mw.RnB.statusDiv.fadeOut('slow')}}};mw.RnB.action=mw.config.get("wgAction");(mw.config.get("wgIsArticle")||jQuery("#wikiPreview").length>0)&&mw.RnB.dabtag.initialize;