shumin-youtube

按Q点赞,视频结束自动关全屏。Press Q to like the video, and exit fullscreen automatically when the video ends.

目前為 2024-12-31 提交的版本,檢視 最新版本

// ==UserScript==
// @name               shumin-youtube
// @namespace          http://tampermonkey.net/
// @version            2.0.1
// @description        按Q点赞,视频结束自动关全屏。Press Q to like the video, and exit fullscreen automatically when the video ends.
// @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';

// 获取点赞按钮
    function getLikeButton() {
        // 通过 CSS 类名精确查找
        return document.querySelector(
            'div.ytSegmentedLikeDislikeButtonViewModelSegmentedButtonsWrapper button.yt-spec-button-shape-next--segmented-start'
        );
    }
    // 监听键盘事件
    function setupKeyListener() {
        document.addEventListener('keydown', (e) => {
            if (e.key === 'Q' || e.key === 'q') {
                const likeButton = getLikeButton();
                if (likeButton) {
                    likeButton.click();
                    console.log('Q 键被按下,已点赞!');
                } else {
                    console.log('未找到点赞按钮!');
                }
            }
        });
    }
    // 观察 DOM 变化,确保按钮加载完成后绑定事件
    function observeDOMChanges() {
        const observer = new MutationObserver(() => {
            const likeButton = getLikeButton();
            if (likeButton) {
                console.log('找到点赞按钮,绑定事件监听。');
                setupKeyListener();
                observer.disconnect(); // 停止观察
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }
    // 初始化
    observeDOMChanges();


    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('.ytp-progress-bar-container', () => {
        const style = document.createElement('style');
        style.textContent = `
            /* 修改进度条颜色 */
            .ytp-play-progress {
                background-image: linear-gradient(to right, #AAAA00, #00B100) !important;
            }
            /* 修改圆点的颜色
            .ytp-scrubber-button {
                background-color: #00AA00 !important;
            }*/
        `;
        document.head.appendChild(style);
    });

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

QingJ © 2025

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