Prevent mix/radio playlist on videos

prevent mix/radio playlist on videos

目前為 2025-06-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Prevent mix/radio playlist on videos
// @namespace    https://greasyfork.org/users/821661
// @version      1.0
// @description  prevent mix/radio playlist on videos
// @author       hdyzen
// @match        https://*.youtube.com/*
// @grant        none
// @license      GPL-3.0-only
// ==/UserScript==

const endpointMap = {
	"ytd-rich-item-renderer"(thumb) {
		return thumb?.data?.content?.videoRenderer?.navigationEndpoint?.watchEndpoint;
	},
	"ytd-compact-video-renderer"(thumb) {
		return thumb?.data?.navigationEndpoint?.watchEndpoint;
	},
};

function satinize(selector) {
	const thumbs = document.querySelectorAll(`${selector}:not([satinized])`);

	for (const thumb of thumbs) {
		const watchEndpoint = endpointMap[selector](thumb);

		if (!watchEndpoint) {
			continue;
		}

		if (!(watchEndpoint.playerParams && watchEndpoint.playlistId)) {
			thumb.setAttribute("satinized", "");
			continue;
		}

		thumb.setAttribute("satinized", "");

		watchEndpoint.playerParams = "";
		watchEndpoint.playlistId = "";
	}
}

const observer = new MutationObserver(() => {
	if (window.location.href === "https://www.youtube.com/") {
		satinize("ytd-rich-item-renderer");
	}

	if (window.location.pathname === "/watch") {
		satinize("ytd-compact-video-renderer");
	}
});

observer.observe(document.body, { childList: true, subtree: true });