Jump to content

User:TheInfernoX/FindGeneralSources.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.
/*** Find General Sources ***/

// Imitates adding [[Template:Find general sources]] below the title of the article you are viewing
// Documentation at [[en:w:User:TheInfernoX/FindGeneralSources]]
// User script by [[en:w:User:TheInfernoX]]

$(document).ready(function() {
	let generalStrictSearch = window.generalStrictSearch;
	const pageTitle = mw.config.get('wgTitle').replace(/\s/g, "+"),
		generalSources = document.createElement("div"),
		sourceGenerator = function(link, text){
			const source = document.createElement("a");
			
			source.setAttribute("href", link);
			source.setAttribute("target", "_blank");
			source.appendChild(document.createTextNode(text));
			
			return source;
		};
		
	generalStrictSearch = generalStrictSearch ? "\"" : "";
		
	generalSources.setAttribute("style", "font-size: 92%");
	
	generalSources.appendChild(document.createTextNode("Find sources: "));
	
	generalSources.appendChild(sourceGenerator("https://www.google.com/search?as_eq=wikipedia&q=" + generalStrictSearch + pageTitle + generalStrictSearch, "Google"));
	generalSources.appendChild(document.createTextNode(" ("));
	
	generalSources.appendChild(sourceGenerator("https://www.google.com/search?tbs=bks:1&q=" + generalStrictSearch + pageTitle + generalStrictSearch + "+-wikipedia", "books"));
	generalSources.appendChild(document.createTextNode("・"));
	
	generalSources.appendChild(sourceGenerator("https://www.google.com/search?tbm=nws&q=" + generalStrictSearch + pageTitle + generalStrictSearch + "+-wikipedia&tbs=ar:1", "news"));
	generalSources.appendChild(document.createTextNode("・"));
	
	generalSources.appendChild(sourceGenerator("https://scholar.google.com/scholar?q=" + generalStrictSearch + pageTitle + generalStrictSearch, "scholar"));
	generalSources.appendChild(document.createTextNode("・"));
	
	generalSources.appendChild(sourceGenerator("https://www.google.com/search?safe=off&tbs=sur:fmc&tbm=isch&q=" + generalStrictSearch + pageTitle + generalStrictSearch + "+-site:wikipedia.org+-site:wikimedia.org", "free images"));
	generalSources.appendChild(document.createTextNode("・"));
	
	generalSources.appendChild(sourceGenerator("https://www.google.com/custom?hl=en&cx=007734830908295939403%3Agalkqgoksq0&cof=FORID%3A13%3BAH%3Aleft%3BCX%3AWikipedia%2520Reference%2520Search&q=" + generalStrictSearch + pageTitle + generalStrictSearch, "WP refs"));
	generalSources.appendChild(document.createTextNode(")・"));
	
	generalSources.appendChild(sourceGenerator("https://wiki.riteme.site/wiki/Wikipedia:Free_English_newspaper_sources", "FENS"));
	generalSources.appendChild(document.createTextNode("・"));
	
	generalSources.appendChild(sourceGenerator("https://www.jstor.org/action/doBasicSearch?Query=" + generalStrictSearch + pageTitle + generalStrictSearch + "&acc=on&wc=on", "JSTOR"));
	generalSources.appendChild(document.createTextNode("・"));
	
	generalSources.appendChild(sourceGenerator("https://wikipedialibrary.wmflabs.org/search/?q=" + generalStrictSearch + pageTitle + generalStrictSearch, "TWL"));
	
	$('#siteSub').after(generalSources);
});