Skip to content

Instantly share code, notes, and snippets.

@Winding6636
Created September 17, 2026 14:34
Show Gist options
  • Select an option

  • Save Winding6636/31c293c19136b1fbb175df1c4af31f06 to your computer and use it in GitHub Desktop.

Select an option

Save Winding6636/31c293c19136b1fbb175df1c4af31f06 to your computer and use it in GitHub Desktop.
youtube theater disable
// ==UserScript==
// @name YouTube シアターモード強制リセット
// @version 1.0.0
// @description ページ/動画を新しく開いたときに、以前のシアターモード設定が引き継がれるのを防ぎ、常に通常表示で開始させる(視聴中の手動切替は妨げない)
// @author Winding
// @match https://www.youtube.com/watch*
// @match https://youtu.be/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
"use strict";
// 新しい動画/ページを開いてから、この時間だけ「シアター強制解除」を監視する。
const WATCH_DURATION_MS = 6000;
const CHECK_INTERVAL_MS = 150;
let intervalId = null;
function isWatchPage() {
return location.pathname === "/watch";
}
function getFlexy() {
return document.querySelector("ytd-watch-flexy");
}
function isTheaterMode() {
const flexy = getFlexy();
return !!flexy && flexy.hasAttribute("theater");
}
function exitTheaterMode() {
// プレイヤーの「シアター モード」ボタン(.ytp-size-button)をクリックして解除する。
// Cookie(PREF)やlocalStorageを直接書き換えるより確実で、YouTube側の内部状態とズレない。
const sizeButton = document.querySelector(".ytp-size-button");
if (sizeButton) {
sizeButton.click();
return;
}
// ボタンが見つからない場合の保険(描画タイミングの問題等)
const flexy = getFlexy();
if (flexy) flexy.removeAttribute("theater");
}
function stopWatching() {
if (intervalId !== null) {
clearInterval(intervalId);
intervalId = null;
}
}
function startWatching() {
stopWatching();
if (!isWatchPage()) return;
const startedAt = Date.now();
intervalId = setInterval(() => {
if (isTheaterMode()) {
exitTheaterMode();
}
if (Date.now() - startedAt > WATCH_DURATION_MS) {
stopWatching();
}
}, CHECK_INTERVAL_MS);
}
// YouTubeはSPAなので、動画/ページ切り替え時にフルリロードされず
// "yt-navigate-finish" イベントが発火する。通常のページ読み込み(load)も合わせて拾う。
document.addEventListener("yt-navigate-finish", startWatching);
window.addEventListener("load", startWatching);
if (document.readyState === "complete") startWatching();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment