点击静音

点击静音、网页静音、视频静音

  1. // ==UserScript==
  2. // @name 点击静音
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description 点击静音、网页静音、视频静音
  6. // @author 你
  7. // @match https://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function generateUniqueId() {
  16. return 'mute-button-' + Math.random().toString(36).substr(2, 9);
  17. }
  18.  
  19. if (document.getElementById('mute-button-container')) {
  20. return; // 页面上已经有按钮,直接退出
  21. }
  22.  
  23. const buttonContainer = document.createElement('div');
  24. buttonContainer.id = 'mute-button-container';
  25. buttonContainer.style.position = 'fixed';
  26. buttonContainer.style.top = '10px';
  27. buttonContainer.style.right = '10px';
  28. buttonContainer.style.zIndex = '9999';
  29.  
  30. const button = document.createElement('button');
  31. button.id = generateUniqueId();
  32. button.innerText = '点击静音';
  33. button.style.backgroundColor = '#ff5733';
  34. button.style.color = 'white';
  35. button.style.border = 'none';
  36. button.style.borderRadius = '20px';
  37. button.style.padding = '10px 20px';
  38. button.style.cursor = 'pointer';
  39. button.style.fontSize = '14px';
  40. buttonContainer.appendChild(button);
  41.  
  42. document.body.appendChild(buttonContainer);
  43.  
  44. let isMuted = false;
  45.  
  46. // 静音功能
  47. function mutePage() {
  48. isMuted = true;
  49. button.innerText = '点击恢复';
  50. document.querySelectorAll('audio, video').forEach(el => el.muted = true);
  51. }
  52.  
  53. function unmutePage() {
  54. isMuted = false;
  55. button.innerText = '点击静音';
  56. document.querySelectorAll('audio, video').forEach(el => el.muted = false);
  57. }
  58.  
  59. button.addEventListener('click', function() {
  60. if (isMuted) {
  61. unmutePage();
  62. } else {
  63. mutePage();
  64. }
  65. });
  66.  
  67. function checkMutedStatus() {
  68. const videos = document.querySelectorAll('audio, video');
  69. if (videos.length > 0) {
  70. const anyMuted = Array.from(videos).some(v => v.muted);
  71. if (anyMuted) {
  72. isMuted = true;
  73. button.innerText = '点击恢复';
  74. } else {
  75. isMuted = false;
  76. button.innerText = '点击静音';
  77. }
  78. }
  79. }
  80.  
  81. setInterval(checkMutedStatus, 1000);
  82.  
  83. })();

QingJ © 2025

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