Youtube: Hide Video

使视频较为透明。

  1. // ==UserScript==
  2. // @name Youtube: Hide Video
  3. // @name:zh-TW Youtube 隱藏影片
  4. // @name:ja Youtube ビデオを隠す
  5. // @name:ko Youtube 비디오 숨기기
  6. // @name:ru Youtube Скрыть видео
  7. // @version 1.0.7
  8. // @description Make the video and images opacity lower.
  9. // @description:zh-TW 使影片較為透明。
  10. // @description:zh-CN 使视频较为透明。
  11. // @description:ja ビデオと画像の不透明度を低くします。
  12. // @description:ko 비디오 및 이미지의 불투명도를 낮추십시오.
  13. // @description:ru Уменьшите непрозрачность видео и изображений.
  14. // @author Hayao-Gai
  15. // @namespace https://github.com/HayaoGai
  16. // @icon https://www.webwise.ie/wp-content/uploads/2015/10/youtube.png
  17. // @match https://www.youtube.com/*
  18. // @grant GM_getValue
  19. // @grant GM_setValue
  20. // ==/UserScript==
  21.  
  22. /* jshint esversion: 6 */
  23.  
  24. (function() {
  25. 'use strict'
  26.  
  27. // icons made by https://www.flaticon.com/authors/pixel-perfect
  28. const on1 = `<svg width="35" height="35" viewBox="0 -107 512 512"><path d="m0 149.332031c0 82.347657 67.007812 149.335938 149.332031 149.335938h213.335938c82.324219 0 149.332031-66.988281 149.332031-149.335938 0-82.34375-67.007812-149.332031-149.332031-149.332031h-213.335938c-82.324219 0-149.332031 66.988281-149.332031 149.332031zm277.332031 0c0-47.058593 38.273438-85.332031 85.335938-85.332031 47.058593 0 85.332031 38.273438 85.332031 85.332031 0 47.0625-38.273438 85.335938-85.332031 85.335938-47.0625 0-85.335938-38.273438-85.335938-85.335938zm0 0"/></svg>`
  29. const on2 = `<svg width="35" height="35" viewBox="0 -107 512 512"><path d="m362.667969 298.667969h-213.335938c-82.34375 0-149.332031-67.007813-149.332031-149.335938 0-82.324219 66.988281-149.332031 149.332031-149.332031h213.335938c82.34375 0 149.332031 67.007812 149.332031 149.332031 0 82.328125-66.988281 149.335938-149.332031 149.335938zm-213.335938-266.667969c-64.703125 0-117.332031 52.652344-117.332031 117.332031 0 64.683594 52.628906 117.335938 117.332031 117.335938h213.335938c64.703125 0 117.332031-52.652344 117.332031-117.335938 0-64.679687-52.628906-117.332031-117.332031-117.332031zm0 0"/><path d="m362.667969 234.667969c-47.0625 0-85.335938-38.273438-85.335938-85.335938 0-47.058593 38.273438-85.332031 85.335938-85.332031 47.058593 0 85.332031 38.273438 85.332031 85.332031 0 47.0625-38.273438 85.335938-85.332031 85.335938zm0-138.667969c-29.398438 0-53.335938 23.914062-53.335938 53.332031 0 29.421875 23.9375 53.335938 53.335938 53.335938 29.394531 0 53.332031-23.914063 53.332031-53.335938 0-29.417969-23.9375-53.332031-53.332031-53.332031zm0 0"/></svg>`
  30. const off1 = `<svg width="35" height="35" viewBox="0 -107 512 512"><path d="m362.667969 298.667969h-213.335938c-82.34375 0-149.332031-67.007813-149.332031-149.335938 0-82.324219 66.988281-149.332031 149.332031-149.332031h213.335938c82.34375 0 149.332031 67.007812 149.332031 149.332031 0 82.328125-66.988281 149.335938-149.332031 149.335938zm-213.335938-266.667969c-64.703125 0-117.332031 52.652344-117.332031 117.332031 0 64.683594 52.628906 117.335938 117.332031 117.335938h213.335938c64.703125 0 117.332031-52.652344 117.332031-117.335938 0-64.679687-52.628906-117.332031-117.332031-117.332031zm0 0"/><path d="m149.332031 234.667969c-47.058593 0-85.332031-38.273438-85.332031-85.335938 0-47.058593 38.273438-85.332031 85.332031-85.332031 47.0625 0 85.335938 38.273438 85.335938 85.332031 0 47.0625-38.273438 85.335938-85.335938 85.335938zm0-138.667969c-29.394531 0-53.332031 23.914062-53.332031 53.332031 0 29.421875 23.9375 53.335938 53.332031 53.335938 29.398438 0 53.335938-23.914063 53.335938-53.335938 0-29.417969-23.9375-53.332031-53.335938-53.332031zm0 0"/></svg>`
  31. const off2 = `<svg width="35" height="35" viewBox="0 -107 512 512"><path d="m362.667969 0h-213.335938c-82.324219 0-149.332031 66.988281-149.332031 149.332031 0 82.347657 67.007812 149.335938 149.332031 149.335938h213.335938c82.324219 0 149.332031-66.988281 149.332031-149.335938 0-82.34375-67.007812-149.332031-149.332031-149.332031zm-213.335938 234.667969c-47.058593 0-85.332031-38.273438-85.332031-85.335938 0-47.058593 38.273438-85.332031 85.332031-85.332031 47.0625 0 85.335938 38.273438 85.335938 85.332031 0 47.0625-38.273438 85.335938-85.335938 85.335938zm0 0"/></svg>`
  32.  
  33. const textStyle = `
  34. .switch {
  35. display: block;
  36. margin: auto 30px;
  37. cursor: pointer;
  38. }
  39. .switch[dark="true"] {
  40. fill: white;
  41. }
  42. .hide-set {
  43. transition: opacity 0.3s;
  44. opacity: 0.1;
  45. }`
  46.  
  47. const targets = [
  48. "img",
  49. "video",
  50. "#background",
  51. ".ytp-videowall-still-image"
  52. ]
  53.  
  54. let updating = false
  55. let href = document.location.href
  56.  
  57. css()
  58.  
  59. observation()
  60.  
  61. init(10)
  62.  
  63. window.addEventListener("scroll", update, true)
  64.  
  65. function init(times) {
  66. for (let i = 0; i < times; i++) {
  67. // switch
  68. setTimeout(addButton, 500 * i)
  69. // hide targets
  70. for (const target of targets) {
  71. setTimeout(() => hideTarget(`${target}:not(.hide-set)`), 500 * i)
  72. }
  73. }
  74. // show targets
  75. showTarget()
  76. }
  77.  
  78. function addButton() {
  79. // check exist
  80. if (!!document.querySelector(".switch")) return
  81. // get parent
  82. const logoPanel = document.querySelector("ytd-topbar-logo-renderer#logo")
  83. if (!logoPanel) return
  84. // add button
  85. const button = document.createElement("span")
  86. button.classList.add("switch")
  87. button.innerHTML = switchSVG()
  88. button.addEventListener("click", onClick)
  89. logoPanel.parentNode.insertBefore(button, logoPanel.nextSibling)
  90. // add "dark" attribute
  91. const attDark = document.createAttribute("dark")
  92. attDark.value = isDark()
  93. button.setAttributeNode(attDark)
  94. }
  95.  
  96. function isDark() {
  97. return document.querySelector("html").getAttribute("dark") === ""
  98. }
  99.  
  100. function switchSVG() {
  101. const on = (!isDark() && !window.location.href.includes("watch?v=")) ? on1 : on2
  102. const off = (!isDark() && !window.location.href.includes("watch?v=")) ? off1 : off2
  103. return getToggle() ? on : off
  104. }
  105.  
  106. function onClick() {
  107. GM_setValue("switch", !getToggle())
  108. this.innerHTML = switchSVG()
  109. init(3)
  110. }
  111.  
  112. function hideTarget(target) {
  113. // check toggle
  114. if (!getToggle()) return
  115. // hide target
  116. document.querySelectorAll(target).forEach(t => {
  117. t.classList.add("hide-set")
  118. })
  119. }
  120.  
  121. function getToggle() {
  122. return GM_getValue("switch", true)
  123. }
  124.  
  125. function showTarget() {
  126. // check toggle
  127. if (getToggle()) return
  128. // show targets
  129. document.querySelectorAll(".hide-set").forEach(target => {
  130. target.classList.remove("hide-set")
  131. })
  132. }
  133.  
  134. function update() {
  135. if (updating) return
  136. updating = true
  137. init(3)
  138. setTimeout(() => { updating = false }, 1000)
  139. }
  140.  
  141. function css() {
  142. const style = document.createElement("style")
  143. style.type = "text/css"
  144. style.innerHTML = textStyle
  145. document.head.appendChild(style)
  146. }
  147.  
  148. function observation() {
  149. const observer = new MutationObserver(mutations => {
  150. mutations.forEach(() => {
  151. if (href != document.location.href) {
  152. href = document.location.href
  153. init(10)
  154. }
  155. })
  156. })
  157. const target = document.querySelector("body")
  158. const config = { childList: true, subtree: true }
  159. observer.observe(target, config)
  160. }
  161.  
  162. })()

QingJ © 2025

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