shumin-youtube

按Q点赞,视频结束自动关全屏,彩虹进度条。Press Q to like the video, automatically exit fullscreen when the video ends, and enjoy a rainbow progress bar.

// ==UserScript==
// @name               shumin-youtube
// @namespace          http://tampermonkey.net/
// @version            2.1.0
// @description        按Q点赞,视频结束自动关全屏,彩虹进度条。Press Q to like the video, automatically exit fullscreen when the video ends, and enjoy a rainbow progress bar.
// @author             qianjunlang
// @match              *://*.youtube.com/*
// @icon               https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant              GM_setValue
// @grant              GM_getValue
// @run-at             document-idle
// @noframes
// @license            MIT License
// ==/UserScript==
'use strict';

    var css = `
        .ytp-play-progress {
            background-image: linear-gradient(to left, #FF0000, #FF9900, #FFFF00, #33CC33, #00CCFF, #6633FF, #CC00FF )!important;
        }
    `;
    if (typeof GM_addStyle != "undefined") {
        GM_addStyle(css);
    } else if (typeof PRO_addStyle != "undefined") {
        PRO_addStyle(css);
    } else if (typeof addStyle != "undefined") {
        addStyle(css);
    } else {
        var node = document.createElement("style");
        node.type = "text/css";
        node.appendChild(document.createTextNode(css));
        var heads = document.getElementsByTagName("head");
        if (heads.length > 0) {
            heads[0].appendChild(node);
        } else {
            // no head yet, stick it whereever
            document.documentElement.appendChild(node);
        }
    }

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    function isVisible(element) {
        return element && element.offsetParent !== null;
    }

    let cycle_id = setInterval(() => {
        if(
            isVisible(document.querySelector('.ytp-endscreen-previous')) ||
            isVisible(document.querySelector('.ytp-endscreen-next')) ||
            isVisible(document.querySelector('.ytp-endscreen-content')) ||
            isVisible(document.querySelector('.html5-endscreen')) ||
            false
        ) {
            document.exitFullscreen();
            document.cancelFullScreen();
            document.webkitCancelFullScreen();
        }
    }, 1000);


//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    function createObserver(selector, callback) {
        const observer = new MutationObserver(() => {
            const element = document.querySelector(selector);
            if (element) {
                callback(element); // 对找到的元素执行回调
                observer.disconnect(); // 停止观察
            }
        });

        // 开始观察
        observer.observe(document.body, {
            childList: true,
            subtree: true,
        });
    }



    createObserver(
        'div.ytSegmentedLikeDislikeButtonViewModelSegmentedButtonsWrapper button.yt-spec-button-shape-next--segmented-start',
        (likeButton) => {
            document.addEventListener('keydown', (e) => {
                if (e.key === 'Q' || e.key === 'q') {
                    if (likeButton) {
                        likeButton.click();
                        console.log('Q 键被按下,已点赞!');
                    } else { console.log('未找到点赞按钮!'); }
                }
            });
        }
    );


    // 修改 #ytCover 的样式
    createObserver('#ytCover', (ytCover) => {
        ytCover.style.fontSize = '1.5em'; // 将字号调小
        ytCover.style.color = 'var(--ytd-searchbox-legacy-button-icon-color)'; // 使用指定的颜色变量
    });

/*
    createObserver('.ytp-progress-bar-container', () => {
        const style = document.createElement('style');
        style.textContent = `
            .ytp-play-progress {
                background-image: linear-gradient(to left, #FF0000, #FF9900, #FFFF00, #33CC33, #00CCFF, #6633FF, #CC00FF )!important;
            }
        `;
        document.head.appendChild(style);
    });
*/