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.
mw.loader.using(['mediawiki.util'],function(){$(document).ready(function(){if((mw.config.get('wgNamespaceNumber')!==0&&mw.config.get('wgPageName')!=='User:Polygnotus/dupreftest')||mw.config.get('wgAction')!=='view'){return;}letreferencesHeading=document.getElementById("References");if(!referencesHeading){return;}conststyle=document.createElement('style');style.textContent=` li:target { border: 1px dotted red; padding: 2px; background-color: #ffcccc !important;} .duplicate-citation-highlight { background-color: #ffe6e6; } .duplicate-citation-hover { background-color: #ffcccc; } .duplicate-citation-clicked { border: 1px dotted red; padding: 2px; background-color: #ffe6e6; } .grouped-references { margin-left: 20px; } .grouped-references-toggle { cursor: pointer; color: blue; } .grouped-references-content { display: none; } .grouped-references-content.expanded { display: block; } `;document.head.appendChild(style);letparentDiv=referencesHeading.closest("div");letnewParagraph=document.createElement("p");newParagraph.style.color="red";functionaddDuplicateCitationsTemplate(){// ... (unchanged)}functiongetDuplicateInfo(){// ... (unchanged)}functioncalculateSimilarity(str1,str2){// ... (unchanged)}functioneditDistance(s1,s2){// ... (unchanged)}functiongetAllVisibleText(element){// ... (unchanged)}functionextractVisibleText(htmlString){// ... (unchanged)}functioncheckDuplicateReferenceLinks(){constreferenceSpans=document.querySelectorAll('span.reference-text');consturlMap=newMap();constduplicates=newMap();constcontentMap=newMap();lettotalLinks=0;// Create a map of cite_note ids to their correct reference numbersconstciteNoteMap=newMap();document.querySelectorAll('.reference').forEach(ref=>{constlink=ref.querySelector('a');if(link){constlinkHref=link.getAttribute('href');if(linkHref){constciteNoteId=linkHref.substring(1);// Remove the leading '#'constrefNumber=citeNoteId.split('-').pop();citeNoteMap.set(citeNoteId,refNumber);}}});referenceSpans.forEach((span)=>{// ... (unchanged code for processing each reference)});if(duplicates.size>0||Array.from(contentMap.values()).some(group=>group.length>1)){if(document.querySelector('table.box-Duplicated_citations')===null){// ... (unchanged code for adding the template link)}// Group and collapse duplicate referencesgroupAndCollapseDuplicates(duplicates,contentMap);// Display information about duplicatesdisplayDuplicateInfo(duplicates,contentMap);parentDiv.after(newParagraph);}}functiongroupAndCollapseDuplicates(duplicates,contentMap){constreferencesSection=document.querySelector('ol.references');if(!referencesSection)return;// Process URL-based duplicatesduplicates.forEach((refInfo,url)=>{if(refInfo.length>1){constgroupContainer=document.createElement('li');groupContainer.className='grouped-references';consttoggle=document.createElement('span');toggle.className='grouped-references-toggle';toggle.textContent=`[+] ${refInfo.length} references to ${url}`;groupContainer.appendChild(toggle);constcontent=document.createElement('ol');content.className='grouped-references-content';refInfo.forEach(ref=>{constoriginalRef=document.getElementById(ref.citeNote);if(originalRef){content.appendChild(originalRef.cloneNode(true));originalRef.remove();}});groupContainer.appendChild(content);toggle.addEventListener('click',()=>{content.classList.toggle('expanded');toggle.textContent=content.classList.contains('expanded')?`[-] ${refInfo.length} references to ${url}`:`[+] ${refInfo.length} references to ${url}`;});referencesSection.appendChild(groupContainer);}});// Process content-based duplicatescontentMap.forEach((group,content)=>{if(group.length>1){constgroupContainer=document.createElement('li');groupContainer.className='grouped-references';consttoggle=document.createElement('span');toggle.className='grouped-references-toggle';toggle.textContent=`[+] ${group.length} similar references`;groupContainer.appendChild(toggle);constcontentDiv=document.createElement('ol');contentDiv.className='grouped-references-content';group.forEach(ref=>{constoriginalRef=document.getElementById(ref.citeNote);if(originalRef){contentDiv.appendChild(originalRef.cloneNode(true));originalRef.remove();}});groupContainer.appendChild(contentDiv);toggle.addEventListener('click',()=>{contentDiv.classList.toggle('expanded');toggle.textContent=contentDiv.classList.contains('expanded')?`[-] ${group.length} similar references`:`[+] ${group.length} similar references`;});referencesSection.appendChild(groupContainer);}});}functiondisplayDuplicateInfo(duplicates,contentMap){// ... (unchanged code for displaying duplicate information)}checkDuplicateReferenceLinks();});});