Last active
April 17, 2024 05:01
-
-
Save lumynou5/b036f405a0888bf9c3b9a3f560e36f3d to your computer and use it in GitHub Desktop.
Disable YouTube autoplaying everywhere.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouTube Disable Autoplaying | |
// @version 0.3.4 | |
// @description Disable YouTube autoplaying everywhere. | |
// @author Lumynous | |
// @license MIT | |
// @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js | |
// @match https://www.youtube.com/* | |
// @noframes | |
// @downloadURL https://gist.github.com/lumynou5/b036f405a0888bf9c3b9a3f560e36f3d/raw/youtube-disable-autoplaying.user.js | |
// ==/UserScript== | |
'use strict'; | |
const manager = document.getElementsByTagName('yt-playlist-manager')[0]; | |
const button = document.createElement('button'); | |
button.classList.add('ytp-button'); | |
button.style.width = '40px'; | |
button.style.height = '100%'; | |
const container = document.createElement('div'); | |
container.classList.add('ytp-autonav-toggle-button-container'); | |
const inner = document.createElement('div'); | |
inner.classList.add('ytp-autonav-toggle-button'); | |
inner.style.margin = '0 auto'; | |
button.appendChild(container).appendChild(inner); | |
let state = false; | |
const changeState = (newState) => { | |
state = newState; | |
manager.canAutoAdvance_ = state; | |
inner.setAttribute('aria-checked', state.toString()); | |
}; | |
button.addEventListener('click', () => changeState(!state)); | |
document.addEventListener('yt-navigate-finish', async () => { | |
if (location.pathname === '/watch' && location.search.match(/\?(?:.*&)?list=.*/)) { | |
changeState(state); | |
document.querySelector('#playlist-action-menu #flexible-item-buttons').replaceChildren(button); | |
} else if (location.pathname.startsWith('/shorts/')) { | |
let player = await elmGetter.get('#shorts-player'); | |
setTimeout(() => player.setLoopVideo(false), 1000); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
YouTube 停用自動播放
功能
安裝
在瀏覽器安裝 Tampermonkey 擴充套件後,點擊此頁面上的「Raw」按鈕,然後點擊「安裝」即可。
YouTube Disable Autoplaying
Features
Installation
Ensure Tampermonkey installed on your browser. Click the "Raw" button on this page, and then click the "Install".