YouTube Autoplay Disable

Script to disable autoplay.

  1. // ==UserScript==
  2. // @name YouTube Autoplay Disable
  3. // @name:ja YouTube 自動再生 無効化
  4. // @namespace https://midra.me
  5. // @version 1.0.2
  6. // @description Script to disable autoplay.
  7. // @description:ja 自動再生を無効化するスクリプト。
  8. // @author Midra
  9. // @license MIT
  10. // @match https://www.youtube.com/*
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  12. // @run-at document-start
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_registerMenuCommand
  16. // @require https://gf.qytechs.cn/scripts/7212-gm-config-eight-s-version/code/GM_config%20(eight's%20version).js?version=156587
  17. // ==/UserScript==
  18.  
  19. (() => {
  20. console.log('[YouTube Autoplay Disable]: v1.0.2')
  21.  
  22. const language = (window.navigator.languages && window.navigator.languages[0]) || window.navigator.language || window.navigator.userLanguage || window.navigator.browserLanguage
  23. const lang = language === 'ja-JP' ? 'ja' : 'en'
  24.  
  25. const i18n = {
  26. configTitle: {
  27. ja: '自動再生を無効化する対象',
  28. en: 'Target to disable autoplay',
  29. },
  30. configSaveAlert: {
  31. ja: '設定の変更を反映させるにはページを再読み込みしてください。',
  32. en: 'Please reload the page for the configuration changes to take effect.',
  33. },
  34. configItems: {
  35. default: {
  36. ja: '通常の動画',
  37. en: 'Normal video',
  38. },
  39. live: {
  40. ja: 'ライブ',
  41. en: 'Live',
  42. },
  43. channel: {
  44. ja: 'チャンネルのホーム',
  45. en: 'Channel home',
  46. },
  47. iframe: {
  48. ja: '埋め込み動画',
  49. en: 'Embedded video',
  50. },
  51. },
  52. }
  53.  
  54. const configInitData = {
  55. default: {
  56. label: i18n.configItems.default[lang],
  57. type: 'checkbox',
  58. default: true,
  59. },
  60. live: {
  61. label: i18n.configItems.live[lang],
  62. type: 'checkbox',
  63. default: true,
  64. },
  65. channel: {
  66. label: i18n.configItems.channel[lang],
  67. type: 'checkbox',
  68. default: true,
  69. },
  70. iframe: {
  71. label: i18n.configItems.iframe[lang],
  72. type: 'checkbox',
  73. default: true,
  74. },
  75. }
  76.  
  77. GM_config.init(i18n.configTitle[lang], configInitData)
  78.  
  79. GM_config.onload = () => {
  80. setTimeout(() => {
  81. alert(i18n.configSaveAlert[lang])
  82. }, 200)
  83. }
  84.  
  85. GM_registerMenuCommand('設定', GM_config.open)
  86.  
  87. // 設定取得
  88. const config = {}
  89. Object.keys(configInitData).forEach(v => { config[v] = GM_config.get(v) })
  90.  
  91. if (window === window.parent) {
  92. window.addEventListener('yt-player-updated', ({ target, detail }) => {
  93. if (!(target instanceof HTMLElement)) return
  94.  
  95. const videoData = detail.getVideoData()
  96.  
  97. if (
  98. // 通常の動画
  99. (
  100. config['default'] &&
  101. target.id === 'ytd-player' &&
  102. !videoData.isLive
  103. ) ||
  104. // ライブ
  105. (
  106. config['live'] &&
  107. target.id === 'ytd-player' &&
  108. videoData.isLive
  109. ) ||
  110. // チャンネルのホーム
  111. (
  112. config['channel'] &&
  113. target.classList.contains('ytd-channel-video-player-renderer')
  114. )
  115. ) {
  116. target.stop()
  117. }
  118. })
  119. }
  120. else if (
  121. config['iframe'] &&
  122. window.location.href.startsWith('https://www.youtube.com/embed/')
  123. ) {
  124. const url = new URL(window.location.href)
  125. if (url.searchParams.get('autoplay') === '1') {
  126. url.searchParams.set('autoplay', '0')
  127. window.history.replaceState(null, '', url.href)
  128. window.location.reload()
  129. }
  130. }
  131. })()

QingJ © 2025

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