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.
//This script uses material from Wikipedia user Ucucha's script "duplinks" ( https://en.wikipedia.org/wiki/User:Ucucha/duplinks.js ), which is released under the Creative Commons Attribution-Share-Alike License 3.0 ( http://creativecommons.org/licenses/by-sa/3.0/ )//See also https://en.wikipedia.org/wiki/User:Ucucha/duplinks for documentation of the original script$(function($){varnamespaceNumber=mw.config.get('wgNamespaceNumber');// only check links in mainspace, and userspace (for userspace drafts), and draftspacevarisCorrectNamespace=namespaceNumber===0||namespaceNumber===2||namespaceNumber===118;if(!isCorrectNamespace){return;}mw.loader.using('mediawiki.util').then(function(){varportletlink=mw.util.addPortletLink('p-tb','#','Highlight duplicate links','ca-findduplicatelinks');$(portletlink).click(function(e){e.preventDefault();// Check if VisualEditor is being used - the element surrounding text is different in VEvarisVisualEditor=window.location.href.search("veaction")>0;// Get the element immediately surrounding the article text.var$content=isVisualEditor?$(".ve-ce-documentNode.ve-ce-branchNode"):$($(".mw-parser-output","#mw-content-text")[0])// Create a separate div to conatin the lead$lead=$("<div id='lead'>").prependTo($content);// Move the elements containing the lead content into this newly-created div$lead.nextAll().each(function(){if(this.nodeName.toLowerCase()=='h2'){// Reached the first heading after the lead.// Returning false breaks out of the jQuery .each() loop earlyreturnfalse;}$lead.append(this);returntrue;});// Objects to keep track of whether we've seen a link before, and which links are duplicatedvarseen={};varduplicated={};varhasDuplicatedLinks=false;// Stylesmw.util.addCSS(".duplicate-link { border: 1px solid red; }\n.duplicated-link { border: 1px dashed green; }");// Detect and mark links which are duplicatesvarfinddups=function(){varhref=this.attributes.href&&this.attributes.href.value;if(href!=undefined&&href.indexOf('#')!=0){if(seen[href]){this.classList.add("duplicate-link");duplicated[href]=true;hasDuplicatedLinks=true;}else{seen[href]=true;}}returntrue;};// Detect and mark the first occurance of duplicated linksvarmarkdups=function(){varhref=this.attributes.href&&this.attributes.href.value;if(href!=undefined&&href.indexOf('#')!=0){if(duplicated[href]){this.classList.add("duplicated-link");duplicated[href]='';}}returntrue;};// Process sections after the leadmw.util.$content.find('p a').not('#lead *, .infobox *, .navbox *').each(finddups);mw.util.$content.find('p a').not('#lead *, .infobox *, .navbox *').each(markdups);// Reset tracking objects, process lead sectionseen={};duplicated={};mw.util.$content.find('#lead p a').not('.infobox *, .navbox *').each(finddups);mw.util.$content.find('#lead p a').not('.infobox *, .navbox *').each(markdups);// Show a notice if no duplicates were foundif(!hasDuplicatedLinks){mw.notify('No duplicated links were detected');}});});});