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.
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.
//// Main function.//asyncfunctioncheckTags(content){content.find("span.cuEntry").each(asyncfunction(){constuserNode=$(this).find("a[href*='/User:']")[0];constparseTree=awaitgetParseTree("User:"+userNode.text);if(parseTree!==null){conststatus=tagStatus(parseTree);if('tagType'instatus){$(this).before("<span style=\"background-color:"+status.color+"; border:darkgrey solid 1px; padding:1px;\" title=\""+status.tooltip+"\">"+status.tagType+" </span>");}}});};//// Given a page title (ex: "User:Foo"), return a Promise of a JSON// parse tree.//// On any kind of error, null is returned.//asyncfunctiongetParseTree(pageTitle){try{constpage=await$.get('/api/rest_v1/page/html/'+pageTitle);constjsonText=findSpiTemplate(page);returnJSON.parse(jsonText);}catch(error){returnnull;}};//// Given the parsoid text of a page, find the SPI-related template.//// Page is whatever a '/api/rest_v1/page/html/' API call returns. The// data-mw attribute for the template is returned as a JSON string.//// If the page contains multiple SPI templates, the first one is used.//functionfindSpiTemplate(page){const$html=$($.parseHTML(page));consttemplate=$html.find('[typeof~="mw:Transclusion"]').filter(function(){try{constdata=JSON.parse($(this).attr('data-mw'));returndata["parts"][0]["template"]["target"]["wt"].match(/[sS]ock/);}catch(err){returnfalse;}});returntemplate.attr('data-mw');};//// Handle redirected template names. This is playing whack-a-mole;// it should really be handled on the server side.//functionemulateRedirects(rawTemplateName){switch(rawTemplateName){case'sockmaster':return'sockpuppeteer';default:returnrawTemplateName;}}//// Return an object describing how to style a SPI tag indicator.//// tagType: "M" for a sockmater, "P" for a sockpuppet// color: what color to make the box.// tooltip: a text description of the type of tag//// If there is no SPI tag, an empty object is returned.//functiontagStatus(parseTree){consttemplate=parseTree.parts[0].template;constrawTemplateName=template.target.wt.trim();consttemplateName=emulateRedirects(rawTemplateName).toLowerCase();lettagType=null;lettypeParam=null;if(templateName=='sockpuppeteer'){tagType="M";constparams=template.params;if('1'inparams){typeParam=params[1].wt.trim();}else{typeParam='suspected';}}elseif(templateName=='sock'||templateName=='sockpuppet'){tagType="P";typeParam=template.params[2].wt.trim();}elseif(templateName=='checked sockpuppet'){tagType="P";typeParam='confirmed';}else{return{};}if(typeParam=='suspected'){return{tagType:tagType,color:"#ffffff",tooltip:"suspected"};}if(typeParam=='blocked'){return{tagType:tagType,color:"#ffff66",tooltip:"blocked"};}if(typeParam=='proven'){return{tagType:tagType,color:"#ffcc99",tooltip:"proven"};}if(typeParam=='confirmed'){return{tagType:tagType,color:"#ff3300",tooltip:"confirmed"}}if(typeParam=='banned'){return{tagType:tagType,color:"#7a00ff61",tooltip:"banned"}}return{tagType:tagType,color:"#ffffff",tooltip:"unknown"};}// There's probably a nicer way to do this. The check for mw being undefined// lets us import this file into QUnit for testing.if(typeofmw!=="undefined"){// Cribbed from User:Writ Keeper/Scripts/cuStaleness.jsmw.hook('wikipage.content').add(function(content){consttitleRegex=/Wikipedia:Sockpuppet_investigations\/[^\/]+/;constsandboxRegex=/User:RoySmith\/sandbox/;//only use on a SPI page (or my sandbox for testing)constpageName=mw.config.get("wgPageName");if(titleRegex.test(pageName)||sandboxRegex.test(pageName)){checkTags(content);}});};