Skip to content

Instantly share code, notes, and snippets.

@lumynou5
Last active April 17, 2024 05:01
Show Gist options
  • Save lumynou5/b036f405a0888bf9c3b9a3f560e36f3d to your computer and use it in GitHub Desktop.
Save lumynou5/b036f405a0888bf9c3b9a3f560e36f3d to your computer and use it in GitHub Desktop.
Disable YouTube autoplaying everywhere.
// ==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);
}
});
@lumynou5
Copy link
Author

YouTube 停用自動播放

功能

  • 在播放清單上新增按鈕,用以切換是否自動播放下一個項目。
  • 防止 Shorts 自動重播。

安裝

在瀏覽器安裝 Tampermonkey 擴充套件後,點擊此頁面上的「Raw」按鈕,然後點擊「安裝」即可。

YouTube Disable Autoplaying

Features

  • Adds a button on playlists to toggle autoplaying.
  • Prevents Shorts from auto-looping.

Installation

Ensure Tampermonkey installed on your browser. Click the "Raw" button on this page, and then click the "Install".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment