Jump to content

User:Awesome Aasim/searchengine.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.
$(document).ready(function() {
	switch (mw.config.get("skin")) {
		case "timeless": $("#simpleSearch").append('<input type="button" id="googleSearchButton" class="searchButton" title="Search using Google">');
		$("#simpleSearch").append('<input type="button" id="bingSearchButton" class="searchButton" title="Search using Bing">');
		$("#mw-searchButton").css("right", "7.5em");
		$("#searchButton").css("right", "7.5em");
		$("#googleSearchButton").css({
			    position:  "absolute",
			    top: 0,
			    margin: 0,
			    padding: 0,
			    right: "4.5em",
			    width: "2.5em",
			    height: "2.5em",
			    "text-indent": "-99999px",
			    border: "0",
			    "background-color": "transparent",
			    "background-repeat": "no-repeat",
			    "background-image": 'url("https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Google_%22G%22_logo.svg/21px-Google_%22G%22_logo.svg.png")',
			    "background-position": "center 40%",
			    "box-shadow": "none",
			    "cursor": "pointer"
		});
		$("#bingSearchButton").css({
			    position: "absolute",
			    top: 0,
			    margin: 0,
			    padding: 0,
			    right: "1.5em",
			    width: "2.5em",
			    height: "2.5em",
			    "text-indent": "-99999px",
			    border: "0",
			    "background-color": "transparent",
			    "background-repeat": "no-repeat",
			    "background-image": 'url("https://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Bing_Fluent_Logo.svg/15px-Bing_Fluent_Logo.svg.png")',
			    "background-position": "center 40%",
			    "box-shadow": "none",
			    "cursor": "pointer"
		});
		break;
		case "vector": 
		$("#simpleSearch").append('<input type="button" id="googleSearchButton" class="searchButton" title="Search using Google">');
		$("#simpleSearch").append('<input type="button" id="bingSearchButton" class="searchButton" title="Search using Bing">');
		$("#mw-searchButton").css("right", "50px");
		$("#searchButton").css("right", "50px");
		$("#googleSearchButton").css({
		    'background-color': "transparent",
		    position: "absolute",
		    top: '1px',
		    bottom: '1px',
		    right: '30px',
		    'min-width': '12px',
		    width: '1.84615385em',
		    border: 0,
		    padding: 0,
		    cursor: 'pointer',
		    'font-size': '0.8125em',
		    direction: 'ltr',
		    'text-indent': '-99999px',
		    'white-space': 'nowrap',
		    overflow: 'hidden',
		    'z-index': 1,
		    'background-image': 'url("https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Google_%22G%22_logo.svg/15px-Google_%22G%22_logo.svg.png")',
		    'background-position': 'center center',
		    'background-repeat': 'no-repeat'
		});
		$("#bingSearchButton").css({
		    'background-color': "transparent",
		    position: "absolute",
		    top: '1px',
		    bottom: '1px',
		    right: '10px',
		    'min-width': '12px',
		    width: '1.84615385em',
		    border: 0,
		    padding: 0,
		    cursor: 'pointer',
		    'font-size': '0.8125em',
		    direction: 'ltr',
		    'text-indent': '-99999px',
		    'white-space': 'nowrap',
		    overflow: 'hidden',
		    'z-index': 1,
		    'background-image': 'url("https://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Bing_Fluent_Logo.svg/15px-Bing_Fluent_Logo.svg.png")',
		    'background-position': 'center center',
		    'background-repeat': 'no-repeat'
		});
		break;
	}
	$("#googleSearchButton").click(function(e) {
		e.preventDefault();
		window.location.href = "https://www.google.com/search?q=site:" + encodeURI(window.location.host + " " + $("#searchInput").val());
	});
	$("#bingSearchButton").click(function(e) {
		e.preventDefault();
		window.location.href = "https://www.bing.com/search?q=site:" + encodeURI(window.location.host + " " + $("#searchInput").val());
	});
});