Alternative search engines 2

Adds search on other sites for google, bing, yandex, nigma, wolfram-alpha and ru-wiki

От 05.04.2015. Виж последната версия.

// ==UserScript==
// @name        Alternative search engines 2
// @description Adds search on other sites for google, bing, yandex, nigma, wolfram-alpha and ru-wiki
// @namespace   2k1dmg@userscript
// @license     GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @version     0.0.2
// @grant       none
// @match       *://www.google.ru/*
// @match       *://www.google.com/*
// @match       *://www.google.by/*
// @match       *://www.google.kz/*
// @match       *://www.google.com.ua/*
// @match       *://www.google.com.tr/*
// @match       *://www.google.am/*
// @match       *://www.google.az/*
// @match       *://www.google.ee/*
// @match       *://www.google.fi/*
// @match       *://www.google.ge/*
// @match       *://www.google.kg/*
// @match       *://www.google.lt/*
// @match       *://www.google.lv/*
// @match       *://www.google.md/*
// @match       *://www.google.tm/*
// @match       *://www.google.co.uz/*
// @match       *://www.google.de/*
// @match       *://www.wolframalpha.com/*
// @match       *://www3.wolframalpha.com/*
// @match       *://yandex.ru/*
// @match       *://nigma.ru/*
// @match       *://www.bing.com/*
// @match       *://ru.wikipedia.org/w/*
// @match       *://nova.rambler.ru/*
// @match       *://rambler.ru/*
// ==/UserScript==

// 2015-04-02

var onDOMLoad = function() {
	var SEARCH_ON = '\u0418\u0441\u043a\u0430\u0442\u044c \u043d\u0430:';
	var POSITION = 'left'; //'left','right'

	var ENGINES = {
		//Yahoo: 'http://search.yahoo.com/search?p=',
		//Baidu: 'http://www.baidu.com/s?wd=',
		 \u042f\u043d\u0434\u0435\u043a\u0441: 'https://yandex.ru/yandsearch?text=',
		Google: 'https://www.google.com/search?q=',
		Bing: 'https://www.bing.com/search?q=',
		WolframAlpha: 'http://www3.wolframalpha.com/input/?i=',
		//Rambler: 'http://nova.rambler.ru/search?query=',
		Nigma: 'http://nigma.ru/?s=',
		//Twitter: 'http://www.twitter.com/search?q=',
		Wikipedia: 'http://ru.wikipedia.org/w/index.php?search=',
	};

	var PLACEHOLDER_SELECTORS = [
		'#resultStats', // google
		'.sb_count', // bing
		'.b-wordstat__text',
		'.searchresults b',
		'#ext_link',
		'.b-global-wrapper',
		'.content__left' // yandex
	].join(',');

	var INPUT_FIELD_SELECTORS = [
		'.lst',
		'.b-form-checkbox__checkbox',
		'#searchText',
		'#gbqfq',
		'#query',
		'#i',
		'#sb_form_q', // bing
		'.b-search-block__form_left_input',
		'#lst-ib', // google
		'.input__control' // yandex
	].join(',');

	var results = document.querySelector(PLACEHOLDER_SELECTORS);
	if (!results) {
		return;
	}

	var div = document.getElementById('oeid');
	if (!div) {
		div = document.createElement('div');
		div.id = 'oeid';
		div.style.display = 'inline-block'
		div.style.paddingRight = '10px';
		div.style.paddingBottom = '3px';
		div.style.color = '#737373';
		div.style.fontFamily = 'Calibri, Sans-serif';
		div.style.fontSize = '11px';
		div.style.textAlign = POSITION;
		div.style.zIndex = '10000';
		results.insertBefore(div, results.firstChild);
	}

	var links = '';
	for (var engine in ENGINES) {
		links = links + ",  <a href=\'javascript:void(0)\' onclick=\"javascript:var q;if((q=document.querySelector(\'" + INPUT_FIELD_SELECTORS + "\')).value.length>0){;window.open(\'" + ENGINES[engine] + "\'+encodeURIComponent(q.value))};\">" + engine + "</a>";
	}

	div.innerHTML = '<b>' + SEARCH_ON + '</b> ' + links.slice(3);
};

document.addEventListener("DOMContentLoaded", function() {
	onDOMLoad();
}, false);

document.addEventListener("DOMNodeInserted", function(event) {
	var node = event.target;
	if (node.querySelector && node.querySelector('#resultStats, .content__left'))
		onDOMLoad();
}, false);