Youtube Middle Click Search

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

اعتبارا من 28-10-2015. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name       Youtube Middle Click Search
// @version    1.3.5
// @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=22195
// @namespace https://greasyfork.org/users/649
// @grant GM_openInTab
// ==/UserScript==
console.log('started YMCS');
var process = function(element) {
  console.log('found search button');
  // setup references
  var oldButton = document.querySelector("#search-btn"),
      button = document.createElement('button'),
      input = document.querySelector('#masthead-search-term'),
      initSearch = input.value.trim();
  // imitate old button style
  button.appendChild(oldButton.firstChild.cloneNode(true));
  button.firstChild.style.margin = '0 25px';
  button.style.padding = '0';
  button.className = oldButton.className;
  button.setAttribute('type', 'button');
  // insert new button and remove old
  oldButton.parentNode.insertBefore(button, oldButton);
  oldButton.remove();
  // bind events
  button.addEventListener('mousedown', function(e) {
    if(e.button === 1) {
      e.preventDefault();
    }
  }, false);
  document.addEventListener('click', function(e) {
    if(button.isEqualNode(e.target)) {
      e.preventDefault();
      if (input.value.trim() === '' || (input.value.trim() === initSearch && e.button !== 2)) return false;
      var url = '/results?search_query=' + encodeURIComponent(input.value);
      if(e.button === 1) {
        console.log('opening');
        GM_openInTab(url, false);
      }	else if(e.button === 0) {
        window.location.href = url;
      }
      return false;
    }
  });
};

waitForElems('#search-btn', process, true);