YouTube Preview Unmute

This script automatically unmutes the video previews on the YouTube homepage when you hover over them.

目前为 2025-03-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Preview Unmute
  3. // @icon https://www.youtube.com/img/favicon_48.png
  4. // @author ElectroKnight22
  5. // @namespace electroknight22_youtube_preview_unmute_namespace
  6. // @version 1.0.2
  7. // @match *://*.youtube.com/*
  8. // @match *://www.youtube-nocookie.com/*
  9. // @license MIT
  10. // @description This script automatically unmutes the video previews on the YouTube homepage when you hover over them.
  11. // ==/UserScript==
  12.  
  13. /*jshint esversion: 11 */
  14.  
  15. (function () {
  16. "use strict";
  17.  
  18. let pageType = '';
  19.  
  20. function unmuteVideo(event) {
  21. if (pageType !== 'browse') return;
  22. try {
  23. const ytVolumeSetting = localStorage.getItem('yt-player-volume');
  24. let muted = false;
  25. try {
  26. muted = JSON.parse(JSON.parse(ytVolumeSetting)?.data)?.muted == true;
  27. } catch {
  28. console.warn('Volume setting not found in localStorage.');
  29. }
  30.  
  31. if (!muted && event.target.id === 'inline-player') {
  32. event.target?.player_?.unMute();
  33. }
  34. } catch (error) {
  35. console.error ("Failed to unmute video due to this error. Error: " + error);
  36. }
  37. }
  38.  
  39. window.addEventListener('yt-page-data-fetched', (event) => {
  40. pageType = event.detail?.pageData?.page;
  41. }, true);
  42. window.addEventListener('yt-player-updated', (event) => {
  43. unmuteVideo(event);
  44. }, true);
  45. })();