Greasy Fork 还支持 简体中文。

Enable Youtube Search Middle Click

does what the name on the tin says

  1. // ==UserScript==
  2. // @name Enable Youtube Search Middle Click
  3. // @namespace http://tampermonkey.net/
  4. // @version 2025-05-09
  5. // @description does what the name on the tin says
  6. // @author Bones
  7. // @match *://*.youtube.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. function setupMiddleClickSearch(buttonElement, searchInputElement) {
  16. buttonElement.addEventListener('mousedown', function(event) {
  17. if (event.button === 1) { // Middle click
  18. event.preventDefault(); // Prevent auto-scroll or other browser behavior
  19.  
  20. const query = searchInputElement.value.trim();
  21. if (query) {
  22. const url = `/results?search_query=${encodeURIComponent(query)}`;
  23. window.open(url, '_blank');
  24. }
  25. }
  26. });
  27. }
  28.  
  29. function setup() {
  30. var button = document.querySelectorAll("yt-searchbox button[class*=SearchButton")[0];
  31. var searchBox = document.querySelectorAll("yt-searchbox form input")[0];
  32. setupMiddleClickSearch(button, searchBox);
  33. }
  34.  
  35. if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
  36. // already loaded
  37. setup();
  38. } else {
  39. document.addEventListener("DOMContentLoaded", function(event) {
  40. // finished loading
  41. setup();
  42. });
  43. }
  44. })();