User:Polygnotus/DuplicateReferences.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 73:
 
function getDuplicateInfo() {
const referenceSpansreferencesList = document.querySelectorAllquerySelector('spanol.reference-textreferences');
const referenceItems = referencesList ? Array.from(referencesList.children) : [];
const urlMap = new Map();
const duplicates = [];
 
referenceSpansreferenceItems.forEach((spanitem, index) => {
const refNumber = citeNoteId.split('-').pop()index + 1;
const linkspan = refitem.querySelector('aspan.reference-text');
const links = span.querySelectorAll('a');
const refNumber = span.closest('li')?.id.split('-').pop() || 'Unknown';
 
let validLink = null;
Line 99 ⟶ 101:
const url = validLink.href;
if (urlMap.has(url)) {
urlMap.get(url).push(refNumber.toString());
} else {
urlMap.set(url, [refNumber.toString()]);
}
}
Line 179 ⟶ 181:
 
function checkDuplicateReferenceLinks() {
const referenceSpansreferencesList = document.querySelectorAllquerySelector('spanol.reference-textreferences');
const referenceItems = referencesList ? Array.from(referencesList.children) : [];
const urlMap = new Map();
const duplicates = new Map();
let totalLinks = 0;
referenceSpansreferenceItems.forEach((spanitem, index) => {
// Create a map of cite_note ids to their correct reference numbers
const citeNoteMaprefNumber = newindex Map()+ 1; // Calculate reference number based on position
document const span = item.querySelectorAllquerySelector('span.reference-text').forEach(ref => {;
const link = ref.querySelector('a');
if (link) {
const linkHref = link.getAttribute('href');
if (linkHref) {
const citeNoteId = linkHref.substring(1); // Remove the leading '#'
const refNumber = citeNoteId.split('-').pop();
citeNoteMap.set(citeNoteId, refNumber);
}
}
});
referenceSpans.forEach((span) => {
const links = span.querySelectorAll('a');
const citeNote = span.closest('li')?item.id;
const refNumberrefText = citeNoteMapextractVisibleText(span.get(citeNoteouterHTML) || 'Unknown';
const refText = extractVisibleText(span.outerHTML); // Extract visible text content
let validLink = null;
Line 275 ⟶ 265:
refInfo.forEach((ref, index) => {
iflet (reflink = document.citeNotecreateElement('a') {;
let link.href = document`#${ref.createElement('a')citeNote}`;
link.hreftextContent = `#${ref.citeNote}`refNumber;
paragraphInfo.appendChild(link.textContent = ref.refNumber);
paragraphInfo.appendChild(link);
 
// Highlight only the specific duplicates on hover
link.addEventListener('mouseover', () => {
refInfo.forEach(duplicate => {
const citationElement = document.getElementById(duplicate.citeNote);
if (citationElement) {
if (duplicate.citeNote === ref.citeNote) {
citationElement.classList.add('duplicate-citation-hover');
} else {
citationElement.classList.add('duplicate-citation-highlight');
}
}
});
});
});
link.addEventListener('mouseout', () => {
refInfo.forEach(duplicate => {
const citationElement = document.getElementById(duplicate.citeNote);
if (citationElement) {
citationElement.classList.remove('duplicate-citation-hover');
citationElement.classList.remove('duplicate-citation-highlight');
}
});
});
if (link) { });
 
// Highlight duplicates on click and allow navigation
link.addEventListener('click', () => {
// Remove previous click highlights
document.querySelectorAll('.duplicate-citation-clicked').forEach(el => {
el.classList.remove('duplicate-citation-clicked');
});
// Add new click highlights
refInfo.forEach(duplicate => {
const citationElement = document.getElementById(duplicate.citeNote);
if (citationElement) {
citationElement.classList.add('duplicate-citation-clicked');
}
});
// The default behavior (navigation) will now occur
});
} else { // Add new click highlights
paragraphInforefInfo.appendChildforEach(document.createTextNode(ref.refNumber));duplicate => {
} const citationElement = document.getElementById(duplicate.citeNote);
paragraphInfo.appendChild if (linkcitationElement); {
refInfo citationElement.forEachclassList.add('duplicate => {-citation-clicked');
}
citeNoteMap.set(citeNoteId, refNumber });
// The default behavior (navigation) will now }occur
if (linkHref) { });
// Calculate similarity with the next reference