Youtube Middle Click Search

Middle clicking the search on youtube opens the results in a new tab

2016-08-01 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name       Youtube Middle Click Search
// @version    1.4.3
// @description  Middle clicking the search on youtube opens the results in a new tab
// @match      *://www.youtube.com/*
// @require https://greasyfork.org/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=122976
// @namespace https://greasyfork.org/users/649
// @grant GM_openInTab
// ==/UserScript==

(function() {
	console.log('started YMCS');
	var processBtn = function(element) {
		console.log('found search button');
		// setup references
		var input = document.querySelector('#masthead-search-term'),
			initSearch = input.value.trim();
		element.onmousedown = function(e) {
			if (e.button === 1) {
				e.preventDefault();
			}
		};
		element.onclick = function(e) {
			e.preventDefault();
			if (input.value.trim() === '' || input.value.trim() === initSearch && e.button !== 1) return false;
			var url = location.origin + '/results?search_query=' + encodeURIComponent(input.value);
			if (e.button === 1) {
				console.log('opening');
				GM_openInTab(url, true);
			} else if(e.button === 0) {
				window.location.href = url;
			}
			return false;
		};
	};

	var processResults = function() {
		var elements = document.querySelectorAll('.gssb_e .gsq_a');
		[].forEach.call(elements, function (element) {
			if (element) {
				element.onmousedown =  function(e) {
					if (e.button === 1) {
						e.preventDefault();
					}
				};
				element.onclick = function(e) {
					var url = location.origin + '/results?search_query=' + encodeURIComponent(element.querySelector('span').textContent);
					if (e.button === 1) {
						console.log('opening');
						GM_openInTab(url, true);
					} else if(e.button === 0) {
						window.location.href = url;
					}
					e.preventDefault();
					return false;
				};
			}
		});
	};

	waitForElems('#search-btn', processBtn, true);
	waitForElems('.gssb_e', function(table) {
		var tick = new MutationObserver(processResults);
		tick.observe(table, { subtree: true, childList: true, attributes: true });
	});
})();