User:Polygnotus/DuplicateReferences.js: Difference between revisions

Content deleted Content added
Created page with '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; } let referencesHeading = document.getElementById("References"); if (!referencesHeading) { return; } const style = document...'
 
highlight on hover
Line 11:
const style = document.createElement('style');
style.textContent = `
li:target { border: 4px dotted red; padding: 2px;}`;
.duplicate-citation { background-color: #ffe6e6; }
.duplicate-citation-highlight { background-color: #ffcccc; }
}`;
document.head.appendChild(style);
Line 40 ⟶ 44:
 
// Create the edit summary
let summary = '+{{Duplicate citations}}';
if (duplicateInfo.length > 0) {
summary += ': ';
duplicateInfo.forEach((info, index) => {
summary += `${info.url} (refs: ${info.refs.mapjoin(ref', => {')})`;
const parts = ref.split if ('index < duplicateInfo.length -' 1); {
return parts[parts.length - 1] summary += '; ';
}).join(', ') })`;
if (index < duplicateInfo.length - 1) { });
summary += '; '; }
}
});
}
 
 
 
// Make the edit
Line 80 ⟶ 79:
referenceSpans.forEach((span) => {
const links = span.querySelectorAll('a');
const refNumber = span.closest('li')?.id.replacesplit('cite_note-', '').pop() || 'Unknown';
 
let validLink = null;
Line 193 ⟶ 192:
if (linkHref) {
const citeNoteId = linkHref.substring(1); // Remove the leading '#'
const refNumber = refciteNoteId.textContent.trimsplit('-').replacepop(/[[\]]/g, '');
citeNoteMap.set(citeNoteId, refNumber);
}
Line 281 ⟶ 280:
link.textContent = ref.refNumber;
paragraphInfo.appendChild(link);
 
// Highlight the duplicate citations in the reference list
const citationElement = document.getElementById(ref.citeNote);
if (citationElement) {
citationElement.classList.add('duplicate-citation');
link.addEventListener('mouseover', () => {
citationElement.classList.add('duplicate-citation-highlight');
});
link.addEventListener('mouseout', () => {
citationElement.classList.remove('duplicate-citation-highlight');
});
}
} else {
paragraphInfo.appendChild(document.createTextNode(ref.refNumber));