User:Polygnotus/DuplicateReferences.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(15 intermediate revisions by the same user not shown)
Line 103:
var page = data.query.pages[0];
var content = page.revisions[0].slots.main.content;
 
// Define the templates to check for
const templatesToCheck = [
'{{short description',
'{{DISPLAYTITLE',
'{{Lowercase title',
'{{Italic title',
'{{about',
'{{redirect',
'{{Distinguish',
'{{for'
];
 
// Find the position to insert the new template
let insertPosition = 0;
let lines = content.split('\n');
for (let i = 0; i < lines.length; i++) {
let line = lines[i].trim().toLowerCase();
if (templatesToCheck.some(template => line.startsWith(template.toLowerCase()))) {
insertPosition = i + 1;
} else if (line && !line.startsWith('{{') && !line.startsWith('__')) {
break;
}
}
 
// Create the reason string
let reason = '[[User:Polygnotus/DuplicateReferences|DuplicateReferences]] script detected:<br>\n\n';
if (duplicateInfo.length > 0) {
duplicateInfo.forEach((info) => {
reason += `* ${info.url} (refs: ${info.refs.map(r => r.number).join(', ')})<br>\n\n`;
});
}
 
// InsertCreate the new template with the reasonto parameterinsert
lines.splice(insertPosition,const 0,templateToInsert = `{{Duplicated citations|reason=${reason}${dateParam}}}\n`);
 
var newContent = lines.join('\n');
// FindUse the positionMorebits to inserthandle the newtemplate templateinsertion
const wikitextPage = new Morebits.wikitext.page(content);
let insertPosition = 0;
// Define templates that should come before the duplicated citations template
const templatesToCheckprecedingTemplates = [
'{{short description',
'displaytitle',
'{{Lowercaselowercase title',
'{{DISPLAYTITLEitalic title',
'{{about',
'{{redirect',
'distinguish',
// Define the templates to check 'for',
'{{ItalicFeatured titlelist',
'Featured article',
'{{DistinguishGood article',
} 'Other uses',
'{{forRedirect2',
'Use mdy insertPosition = i + 1;dates',
'Use dmy break;dates',
'Use American English',
'Use British English'
];
 
// Insert the template after the specified templates
// The third parameter is flags (default 'i' for case-insensitive)
// The fourth parameter can include pre-template content like HTML comments
wikitextPage.insertAfterTemplates(templateToInsert, precedingTemplates, 'i', ['<!--[\\s\\S]*?-->']);
}
var newContent = lineswikitextPage.joingetText('\n');
 
let summary = `Tagged [[WP:DUPREF|duplicate citations]] using [[User:Polygnotus/DuplicateReferences|DuplicateReferences]] +{{Duplicated citations|reason=${reason}${dateParam}}}`;
 
return api.postWithToken('csrf', {
Line 273 ⟶ 279:
!url.includes("wikipedia.org") &&
!url.includes("_(identifier)") && // Templates like ISBN and ISSN and OCLC and S2CID contain (identifier)
!url.startsWith("https://search.worldcat.org/") && // |issn= parameter in cite news
!url.startsWith("https://www.bbc.co.uk/news/live/") && // live articles get frequent updates
!url.startsWith("https://www.aljazeera.com/news/liveblog/") &&
Line 279 ⟶ 286:
!url.startsWith("https://www.nytimes.com/live/") &&
!url.startsWith("https://edition.cnn.com/world/live-news/") &&
!url.startsWith("https://www.timesofisrael.com/liveblog") &&
!url.startsWith("https://www.france24.com/en/live-news/") &&
!url.startsWith("https://books.google.com/") && //may be 2 different pages of the same book
!url.startsWith("https://archive.org/details/isbn_")