Jump to content

User:GeneralNotability/unreliable.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Instructions available at [[User:Headbomb/unreliable]]
// Feel free to request tweaks or additional sources to be covered on the talk page

// Adapted from https://en.wikipedia.org/w/index.php?title=Wikipedia:User_scripts/Requests&diff=939432100&oldid=939403363 by [[User:SD0001]]
// Updated from https://en.wikipedia.org/w/index.php?title=User:Jorm/unreliable.js&oldid=940556311 by [[User:Jorm]]
// Updated from https://en.wikipedia.org/w/index.php?title=User:SD0001/unreliabe.js&oldid=941114456 by [[User:SD0001]]
// Updated from https://en.wikipedia.org/w/index.php?title=User:SD0001/unreliable.js&action=edit by [[User:SD0001]]

// Unreliable websites based on [[WP:RSPSOURCES]] (mostly)
// Unreliable publishers/journals based on [[WP:CITEWATCH]] (mostly)

// \/ regex in links doesn't work as it should, use (%2F|\/) instead
$( function() {

	const rules = [
		{
			comment: 'Blacklisted source',
			regex: /\b(?:test\.blacklist\.org|112\.international|112\.ua|breitbart\.com|city-data\.com|dan-news\.info|examiner\.com|famousbirthdays\.com|globalresearch\.ca|infowars\.com|infowars\.net|infowars\.tv|lenta\.ru|liveleak\.com|lulu\.com|mylife\.com|naturalnews\.com|news-front\.info|newswar\.com|newswars\.com|reunion\.com|rusdialog\.ru|southfront\.org|thepointsguy\.com|topwar\.ru|ukraina\.ru|veteransnewsnow\.com|veteranstoday\.com|zoominfo\.com)/i,
			css:  { "background-color": "#dddddd", "text-decoration":"underline", "text-decoration-style": "wavy", "text-decoration-color": "#cc0000"}
		},

		{
			comment: 'Deprecated source',
			regex: /\b(?:test\.deprecated\.org|campaignlifecoalition\.com|crunchbase\.com|dailycaller\.com|dailymail\.co\.uk|dailymail\.com|hispantv\.com|hispantv\.ir|last\.fm|lifesitenews\.com|mintpressnews\.com|nationalenquirer\.com|newsoftheworld\.co\.uk|nndb\.com|oann\.com|occupydemocrats\.com|rateyourmusic\.com|takimag\.com|telesurenglish\.net|telesurtv\.net|theepochtimes\.com|thegatewaypundit\.com|thesun\.co\.uk|vdare\.com|wnd\.com|worldnetdaily\.com)/i,
			css: { "background-color": "#ffbbbb", "text-decoration":"underline", "text-decoration-style": "wavy"},
		},
	
		{
			comment: 'Misleading journal metric',
			regex: /\b(?:test\.misleading\.org|aeglobalindex\.com|aqcj\.org|arabimpactfactor\.com|citefactor\.org|cosmosimpactfactor\.com|dids\.info|diif\.org|doi-ds\.org|drji\.org|esjindex\.org|generalimpactfactor\.com|globalimpactfactor\.com|gscif\.org|i2or\.com|iarcif\.org|ifsij\.com|iijif\.com|impact-factor\.ru|impactfactorjournals\.com|impactfactorservice\.com|indexcopernicus\.com|infobaseindex\.com|inno-space\.net|internationaljournalimpactfactor\.com|isindexing\.com|isithomsonreuters\.org|israjif\.org|jifactor\.com|jifactor\.org|jourinfo\.com|journal-index\.org|journal-metrics\.com|journalimpactfactor\.co\.in|journalimpactfactor\.co\.in|journalimpactfactor\.in|journalsconsortium\.org|journalsmetrics\.com|jprsimpactfactor\.com|oaji\.net|opqc\.org|prernasociety\.org|pubicon\.org|rjifactor\.com|rootindexing\.com|scienceimpactfactor\.com|scijournal\.org|scijournal\.org|sifactor\.org|sindexs\.org|sjournals\.net|sparcindexing\.org|timpactfactor\.com|uifactor\.org|worldbizins\.org)/i,
			css: { "background-color": "#ffbbbb", "text-decoration":"underline", "text-decoration-style": "wavy"},
		},

		{
			comment: 'Generally unreliable source',	
			regex: /\b(?:test\.generallyunreliable\.org|alternet\.org|amazon\.(com\.br|ca|com\.mx|com|cn|in|co\.jp|sg|com\.tr|ae|fr|de|it|nl|es|co\.uk|com\.au)|amren\.com|ancestry\.com|angelfire\.com|angelfire\.lycos\.com|answers\.com|askubuntu\.com|baike\.baidu\.com|bild\.de|bipartisanreport\.com|bircham\.edu|blogger\.com|bloodandhonourcentral\.co\.uk|bloodandhonourworldwide\.co\.uk|celebritynetworth\.com|centerforfoodsafety\.org|cesnur\.org|cnsnews\.com|coindesk\.com|conservativereview\.com|conservativetribune\.com|cracked\.com|dailykos\.com|dailymotion\.com|dailystar\.co\.uk|dailywire\.com|deanradin\.com|deanradin\.org|discogs\.com|electronicintifada\.net|ewg\.org|explorejournal\.com|express\.co\.uk|facebook\.com|familysearch\.org|fandom\.com|fb\.com|findagrave\.com|findmypast\.co\.uk|foodandwaterwatch\.org|force9\.co\.uk|fwwatch\.org|gawker\.com|geni\.com|geocities\.com|goodreads\.com|guacamoley\.com|heatst\.com|ibtimes\.com|imdb\.com|indiahealthguru\.com|indymedia\.org|instagram\.com|jezebel\.com|lenr-canr\.org|liberty\.edu|linkedin\.com|livejournal\.com|marquiswhoswho\.com|mathoverflow\.net|mediabiasfactcheck\.com|medium\.com|metro\.news|mruniversity\.com|neuroquantology\.com|newenergytimes\.com|onlinegatha\.com|palmerreport\.com|pan-international\.org|patheos\.com|patribotics\.com|pesticideinfo\.org|pinterest\.com|prageru\.com|presstv\.com|prisonplanet\.com|quadrant\.org\.au|quillette\.com|quora\.com|reddit\.com|rootsweb\.com|rt\.com|scribd\.com|sputniknews\.com|stackexchange\.com|stackoverflow\.com|stormfront\.org|telekinesisworld\.com|theblaze\.com|thegwpf\.org|thenewamerican\.com|theonion\.com|thetruthaboutguns\.com|tunefind\.com|tvtropes\.org|twitch\.tv|twitter\.com|urbandictionary\.com|venezuelanalysis\.com|vgchartz\.com|vimeo\.com|vixra\.org|westernjournal\.com|whosampled\.com|wikia\.com|wikia\.org|wikileaks\.org|wonkette\.com|wordpress\.com|worldtruth\.tv|youtube\.com|zerohedge\.com|avn\.org\.au|childrenshealthdefense\.org|cmsri\.org|collective-evolution\.com|davidwolfe\.com|drtenpenny\.com|foodbabe\.com|greenmedinfo\.com|healthnutnews\.com|i-sis\.org|medicalveritas\.com|mercola\.com|modernalternativehealth\.com|modernalternativemama\.com|momsacrossamerica\.com|naturalnews\.com|nvic\.org|organicconsumers\.org|peteevans\.com|realfarmacy\.com|townsendletter\.com|tldp\.com|wddty\.com|sixthtone\.com|thepaper\.cn|flickr\.com|tumblr\.com|souq\.com|coresci\.org|delphiclassics\.com|gsjournal\.net|prespacetime\.com|jcer\.com|dnadecipher\.com|scigod\.com|pinknews\.co\.uk|thecanary\.co)/i,
			css:  { "background-color": "#ffdddd" },
		},
		
		{ 
			comment: 'Generally unreliable source',
			regex: /\b10\.(?:0004|14704)\b/,
			css:  { "background-color": "#ffdddd" },
		},

		{
			comment: 'Wikimedia-related website',
			filter: mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 118,
			regex: /\b(?:test\.wiki\.org|wikidata\.org|wikinews\.org|wikipedia\.org)/i,
			css: { "background-color": "#ffdddd" },
		},

		// Predatory. See [[Special:AbuseFilter/891]], [[WP:CITEWATCH/SETUP]], [[User:JzG/Predatory]] and https://beallslist.net/
		{
			comment: 'Predatory journal',
			regex: /\b(?:test\.predatory\.org|\.iiis\.org|\.ssjournals\.com|academicjournals\.com|academicjournals\.net|academicjournals\.org|academicpub\.org|academicresearchjournals\.org|aiac\.org\.au|aicit\.org|aijcrnet\.com|aijssnet\.com|alliedacademies\.org|arcjournals\.org|ashdin\.com|aspbs\.com|avensonline\.org|biomedres\.info|biopublisher\.ca|bowenpublishing\.com|ccsenet\.org|cennser\.org|clinmedjournals\.org|cluteinstitute\.com|cosmology\.com|cpinet\.info|cscanada\.net|currentpediatrics\.com|davidpublisher\.org|esciencecentral\.org|etpub\.com|eujournal\.org|grdspublishing\.org|growingscience\.com|hanspub\.org|hoajonline\.com|hrmars\.com|iacsit\.org|iamure\.com|idosi\.org|igi-global\.com|iises\.net|iiste\.org|ijarbs\.com|ijastnet\.com|ijbhtnet\.com|ijbssnet\.com|ijddr\.in|ijhssnet\.com|ijllnet\.com|imedpub\.com|informaticsjournals\.com|innspub\.net|intechopen\.com|intechweb\.org|interesjournals\.org|internationaljournalssrg\.org|ispacs\.com|ispub\.com|jalsnet\.com|jaypeebrothers\.com|jaypeejournals\.com|jbepnet\.com|jespnet\.com|journalofcosmology\.com|jpmedpub\.com|julypress\.com|juniperpublishers\.com|kowsarpub\.com|kspjournals\.org|m-hikari\.com|macrothink\.org|mecs-press\.org|medwelljournals\.com|oapublishinglondon\.com|oatext\.com|omicsgroup\.org|omicsonline\.org|oprscience\.org|ospcindia\.org|researchleap\.com|researchpub\.org|sapub\.org|scholink\.org|scialert\.net|scidoc\.org|sciedu\.ca|sciencedomain\.org|sciencedomains\.org|sciencepg\.com|sciencepub\.net|sciencepubco\.com|sciencepublication\.org|sciencepublishinggroup\.com|scientificjournals\.org|sciepub\.com|scipg\.net|scipress\.com|scirp\.org|scitechnol\.com|scopemed\.com|seipub\.org|sersc\.org|sphinxsai\.com|thesai\.org|valleyinternational\.net|waset\.org|witpress\.com|worldsciencepublisher\.org|worldwidejournals\.com|wscholars\.com|wseas\.org|wudpeckerresearchjournals\.org|zantworldpress\.com|zenithresearch.org\.in|oapub\.org|medcraveonline\.com|journalissues.\org|rjlbpcs\.com|cosmosscholars\.com|cibtech\.org|rajpub\.com|cirworld\.com|thescipub\.com|ijirset\.com|ijltet\.org|geneticsmr\.org|ijert\.org|electrochemsci\.org|ijohmn\.com)/i,
			css: { "background-color": "#ffbbbb", "text-decoration":"underline", "text-decoration-style": "wavy"},
		},
		
		{ 
			comment: 'Predatory journal',
			regex: /\b10\.(?:0001|11648|1166|1234|12677|12692|12720|12988|13005|13172|13188|14257|14299|14303|14419|14445|1453|14569|14662|15415|15373|15680|15761|17265|18005|18052|18311|18775|19030|19044|19070|19080|1999|20319|20431|20472|20849|20902|20964|21102|21767|22158|23937|29322|2495|30845|35841|36648|3844|3923|3968|4018|4156|4172|4236|4303|5005|5267|5296|5376|5430|5455|5539|5567|5580|5772|5812|5815|5829|5897|5899|5923|5963|6007|6479|7243|7439|7537|7575|7718|7763|9734|22192|18535|15379|35248|24297|7176|17577|37532|24113)\b/,
			css: { "background-color": "#ffbbbb", "text-decoration":"underline", "text-decoration-style": "wavy"},
		},

		// Sources that traditionally fail [[WP:MEDRS]], but which could be used for other more routine claims
		{
			comment: 'Borderline source, which often (but not always) fails higher sourcing requirements.',
			regex: /\b(?:test\.medrs\.org|benthamopen\.com|f1000\.com|frontiersin\.org|mdpi\.com)/i,
			css: { "background-color": "#fffdd0" }
		},
		{
			comment: 'Borderline source, which often (but not always) fails higher sourcing requirements. For Bentham journals, only those published by Bentham Open are of concern.',
			regex: /\b10\.(?:0002|2174|3389|3390|3410|4089|4175|7490|12688|12703|20944|32545|35995|1016(%2F|\/)j\.chaos\.|1016(%2F|\/)S0960-0779)\b/,
			css:  { "background-color": "#fffdd0" }
		},

		// May or may not contain preprints, predatory, or self-published materials
		{
			comment: 'Preprint or general repository which may or may not contain unpublished/predatory materials',
			regex: /\b(?:test\.warn\.org|academia\.edu|arxiv\.org|biorxiv\.org|chemrxiv\.org|cogprints\.org|citeseerx\.ist\.psu\.edu|cureus\.com|docs\.google\.com|e-century\.org|eartharxiv\.org|figshare\.com|medrxiv\.org|osf\.io\/preprints|peerj\.com\/preprints|psyarxiv\.com|pulsus\.com|researchgate\.net|ssrn\.com|zenodo\.org)/i,
			css: { "background-color": "#fffdd0" },
		},
		{
			comment: 'Preprint or general repository which may or may not contain unpublished/predatory materials',
			regex: /\b10\.(?:0003|1101(%2F|\/)\d+|2139|7287|4066|5281|5604|6084|7759|13140|19144|20935|21282|31219|31220|31221|31222|31223|31224|31225|31226|31227|31228|31229|31230|31231|31232|31233|31234|31235|31236|31237)\b/i,
			css: { "background-color": "#fffdd0" },
		}, 

		// Varies with the contributor or topic
		{
			comment: 'Reliability depends on contributor or topic',
			regex: /\b(?:test\.contributors\.org|aa\.com\.tr|forbes\.com|foxnews\.com|huffpost\.com|infotextmanuscripts\.org)/i,
			css:  { "background-color": "#fffdd0" },
		}
	];
	// Dynamically load a user's custom rules from User:USERNAME/unreliable-rules.js
	mw.loader.getScript('/w/index.php?title=User:' + encodeURIComponent(mw.config.get('wgUserName')) + 
	    '/unreliable-rules.js&action=raw&ctype=text/javascript')
	.fail( function() {
		// Something's gone very wrong
        mw.log.error("Error retrieving your unreliable-rules.js");
        // More detailed error in the console if someone feels nice enough to file a bug report
        console.log("Error getting local unreliable-rules.js: " + e.message);
	})
    .done( function () {
        // Script succeeded. You can use X now.
        if (typeof unreliableCustomRules !== 'undefined') {
            unreliableCustomRules.forEach(customRule => {
                 if (!customRule.comment || !customRule.regex || !customRule.css) {
            	    	console.log("Error parsing custom unreliable links rule: ", rule);
            	    	return;
            	    }
            	    rules.push(customRule);
            	});
            }
    })
    .always( function () {
        $(highlight);	
    });
    
    highlight = function() {
		// 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);
		    		$(link).attr('title', rule.comment);
		    		return false;
			    }
		    });
	    });

	    // Check list items against each regex to catch further reading/bibliography items without links 
	    $('.mw-parser-output ul li, .mw-parser-output ol:not(.references) li, .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);
    				$(li).attr('title', rule.comment);
    				return false;
    			}
    		});
    	});
    };

});