User:Headbomb/identifiers.js
Appearance
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. |
Documentation for this user script can be added at User:Headbomb/identifiers. |
// Adapted from [[User:Headbomb/unreliable.js]]
// \/ regex in links doesn't work as it should, use (%2F|\/) instead
$( function() {
const rules = [
// Identifiers
{
regex: /\b(?:arxiv\.org|adsabs\.harvard\.edu|doi\.org|pubmed\.ncbi\.nlm\.nih\.gov|ncbi\.nlm\.nih\.gov(%2F|\/)pubmed|citeseerx\.ist\.psu\.edu|handle\.net|jstor\.org|lccn\.loc\.gov|www\.ams\.org(%2F|\/)mathscinet|mathscinet\.ams\.org(%2F|\/)mathscinet|worldcat\.org|osti\.gov|ssrn\.com|openlibrary\.org|semanticscholar\.org\/CorpusID|zbmath\.org)/,
css: { "background-color": "#eeffee"}
},
// Could probably be converted
{
regex: /\b(?:psycnet.apa.org|ads\.harvard\.edu|bioone\.org|tandfonline\.com|informahealthcare\.com|nature\.com|sciencedirect.com|sciencemag\.org|ieeexplore\.ieee\.org|(%2F|\/)doi(%2F|\/)|10\.\d{4,5})/,
css: { "background-color": "#ffeedd"}
},
//{
// regex: /\b(?:ncbi\.nlm\.nih\.gov(%2F|\/)pmc)/,
// css: { "background-color": "#eeeeff"}
//}
];
// Check each external link on the page against each regex
$('.mw-parser-output a.external').each(function(_, link) {
$.each(rules, function(_, rule) {
if (typeof rule.filter !== 'undefined' && !rule.filter) {
return true;
}
if (rule.regex.test(link.href)) {
$(link).css(rule.css);
return false;
}
});
});
// Check list items against each regex to catch further reading/bibliography items without links
$('.mw-parser-output ul li:not(:has(a)), .mw-parser-output ol:not(.references) li:not(:has(a)), .reference-text:not(:has(a))')
.each(function(_, li) {
$.each(rules, function(_, rule) {
if (typeof rule.filter !== 'undefined' && !rule.filter) {
return true;
}
if (rule.regex.test(li.textContent)) {
$(li).css(rule.css);
return false;
}
});
});
} );