Disable Youtube PiP Miniplayer

Prevents Youtube from keep playing videos in PiP/miniplayer

目前為 2024-04-29 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Disable Youtube PiP Miniplayer
// @namespace    disableMPYTxFIRKx
// @description  Prevents Youtube from keep playing videos in PiP/miniplayer
// @version      0.3
// @author       xFIRKx
// @match        http://*.youtube.com/*
// @match        https://*.youtube.com/*
// @grant        none
// ==/UserScript==
(function() {
    document.body.addEventListener("yt-navigate-finish", function(event) {
        if (document.getElementsByTagName('ytd-miniplayer').length) {
            document.querySelector('ytd-miniplayer').parentNode.removeChild(document.querySelector('ytd-miniplayer'));
        }
        if (document.getElementsByClassName('ytp-miniplayer-button').length) {
            document.querySelector('.ytp-miniplayer-button').parentNode.removeChild(document.querySelector('.ytp-miniplayer-button'))
        }
        if (window.location.pathname != "/watch") {
            document.querySelector('#movie_player video').parentNode.removeChild(document.querySelector('#movie_player video'));
        }
    });
})();
(() => {
    'use strict'
    // credit: https://stackoverflow.com/a/46428962
    let oldHref = document.location.href
    window.onload = () => {
        let bodyList = document.querySelector('body')
        let observer = new MutationObserver(ms => {
            ms.forEach(_m => {
                if (oldHref != document.location.href) {
                    oldHref = document.location.href
                    // allow some delay for page to load.
                    setTimeout(() => {
                        const jq = $('#movie_player > div.ytp-miniplayer-ui > div > button.ytp-miniplayer-close-button.ytp-button')
                        if (jq.length && !document.location.href.startsWith('https://www.youtube.com/watch?')) {
                            jq.click()
                            console.log('[AutoCloseYoutubeMiniplayer] miniplayer dismissed')
                        }}, 200)
                }
            })
        })
        observer.observe(bodyList, {childList: true, subtree: true})
    }
})()

QingJ © 2025

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