Twitch Middle Mouse Button Mute / Unmute

Mutes / unmutes a Twitch video by clicking the middle mouse button within the video player. While performing the middle mouse button click, the scroll button gets disabled. Mute / unmute / scroll disabling won't work with any elements floating over the video player.

  1. // ==UserScript==
  2. // @name Twitch Middle Mouse Button Mute / Unmute
  3. // @author NWP
  4. // @description Mutes / unmutes a Twitch video by clicking the middle mouse button within the video player. While performing the middle mouse button click, the scroll button gets disabled. Mute / unmute / scroll disabling won't work with any elements floating over the video player.
  5. // @namespace https://gf.qytechs.cn/users/877912
  6. // @version 0.1
  7. // @license MIT
  8. // @match *://*.twitch.tv/*
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. // div[data... is for when the controls are visible, video is for when the controls are hidden
  15. // due to https://gf.qytechs.cn/en/scripts/501592-auto-hide-video-controls-almost-instantly-really-quickly-for-the-twitch-desktop-and-mobile-site
  16. // being enabled
  17. //
  18. // Normally, only div[data... is needed
  19. const videoArea = "div[data-a-target='player-overlay-click-handler'], video";
  20. const muteButton = "button[data-a-target='player-mute-unmute-button']";
  21.  
  22. function handleMiddleMouseButtonDown(event) {
  23. if (event.button === 1 && event.target.closest(videoArea)) {
  24. event.preventDefault();
  25. const button = document.querySelector(muteButton);
  26. if (button) {
  27. button.click();
  28. }
  29. }
  30. }
  31.  
  32. function addEventListenersToVideos() {
  33. const videos = document.querySelectorAll(videoArea);
  34. videos.forEach((video) => {
  35. video.removeEventListener('mousedown', handleMiddleMouseButtonDown);
  36. video.addEventListener('mousedown', handleMiddleMouseButtonDown);
  37. });
  38. }
  39.  
  40. const observer = new MutationObserver((mutationsList) => {
  41. for (const mutation of mutationsList) {
  42. if (mutation.type === 'childList' && mutation.addedNodes.length) {
  43. mutation.addedNodes.forEach((node) => {
  44. if (node.nodeType === 1) {
  45. if (node.matches(videoArea) || node.querySelector(videoArea)) {
  46. addEventListenersToVideos();
  47. }
  48. }
  49. });
  50. }
  51. }
  52. });
  53.  
  54. observer.observe(document.body, { childList: true, subtree: true });
  55.  
  56. addEventListenersToVideos();
  57. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址