Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
Line 2:
$(document).ready(function () {
console.log("Script started");
if ((mw.config.get('wgNamespaceNumber') !== 0 && mw.config.get('wgPageName') !== 'User:Polygnotus/dupreftest') || mw.config.get('wgAction') !== 'view') {
console.log("Not the correct page or action, script terminated");
return;
}
console.log("Page title:", document.title);
console.log("URL:", window.___location.href);
function findNextReflistDiv(element) {
let nextElement = element.nextElementSibling;
while (nextElement) {
if (nextElement.tagName.toLowerCase() === 'div' && nextElement.classList.contains('reflist')) {
return nextElement;
}
nextElement = nextElement.nextElementSibling;
}
return null;
}
const referencesHeader = document.querySelector("h2#References");
if (!referencesHeader) {
console.log("References heading not found, script terminated");
return;
}
const containerDiv = referencesHeader.closest("div");
if (!containerDiv) {
console.log("Container div not found, script terminated");
return;
}
const reflistDiv = findNextReflistDiv(containerDiv);
if (!reflistDiv) {
console.log("Reflist div not found, script terminated");
return;
}
const referencesList = reflistDiv.querySelector('ol.references');
if (!referencesList) {
console.log("ol.references not found within reflist div");
return;
}
const style = document.createElement('style');
style.textContent = `
Line 25 ⟶ 54:
`;
document.head.appendChild(style);
let newParagraph = document.createElement("p");
newParagraph.style.color = "red";
function addDuplicateCitationsTemplate() {
console.log("Adding duplicate citations template");
Line 48 ⟶ 76:
var content = page.revisions[0].slots.main.content;
var newContent = '{{Duplicate citations}}\n' + content;
let summary = '+{{Duplicate citations}}';
if (duplicateInfo.length > 0) {
Line 63 ⟶ 89:
}
return api.postWithToken('csrf', {
action: 'edit',
Line 72 ⟶ 97:
}).then(function() {
mw.notify('Successfully added the Duplicate citations template!');
___location.reload();
}).catch(function(error) {
Line 82 ⟶ 106:
function getDuplicateInfo() {
console.log("Getting duplicate info");
const referenceItems = referencesList.querySelectorAll('li');
Line 112 ⟶ 114:
referenceItems.forEach((item, index) => {
const refNumber = index + 1;
console.log(`Processing reference item ${refNumber}`);
const span = item.querySelector('span.reference-text');
Line 161 ⟶ 163:
console.log("Duplicate sets:", duplicates);
return duplicates;
}
Line 234 ⟶ 173:
if (document.querySelector('table.box-Duplicated_citations') === null) {
const editSections =
editSections.forEach(editSection => {
Line 278 ⟶ 217:
paragraphInfo.appendChild(link);
link.addEventListener('mouseover', () => {
refs.forEach(ref => {
Line 301 ⟶ 239:
});
link.addEventListener('click', () => {
document.querySelectorAll('.duplicate-citation-clicked').forEach(el => {
el.classList.remove('duplicate-citation-clicked');
});
refs.forEach(ref => {
const citationElement = document.getElementById(`cite_note-${ref}`);
Line 314 ⟶ 249:
}
});
});
Line 327 ⟶ 261:
console.log("Appending duplicate list to page");
} else {
console.log("No duplicates found");
|