Youtube社区点击图片查看全图

点击图片查看全图

目前為 2022-10-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Youtube社区点击图片查看全图
// @name:en      Youtube community post click to view full size image
// @homepage     https://gf.qytechs.cn/zh-CN/scripts/403916-%E6%98%B
// @namespace    http://tampermonkey.net/
// @version      1.01
// @description  点击图片查看全图
// @description:en  Youtube community click post image to view full size image.
// @author       CZX Fuckerman
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @match        https://www.youtube.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @license      GPL
// ==/UserScript==

(function() {
    'use strict';
    // Your code here...

    function createObserver(){
        if(window.location.href.match(/^https:\/\/www.youtube.com\/channel\/.*\/community\?lb=.*$/g) != null || window.location.href.match(/^https:\/\/www.youtube.com\/post\/.*$/g) != null){
            let observer = new MutationObserver(function(mutations, observer) {
                let disconn = false;
                mutations.forEach(function(mutation) {
                    mutation.addedNodes.forEach(function(node){
                        if(node.nodeName == "DIV" && node.id == "image-container" && node.classList.contains("style-scope") && node.classList.contains("ytd-backstage-image-renderer") && node.classList.length == 2){
                            $(node).css("cursor", "pointer");
                            $(node).click(function(){
                                var src = $("#img", this).attr("src");
                                var sEqindex = src.search(/[=][s][1-9]\d*/g);
                                var sEqMatch = src.match(/[=][s][1-9]\d*/g);
                                if(sEqMatch.length == 0){
                                    window.open(src.substring(0,src.indexOf("=")));
                                } else {
                                    window.open(src.substring(0,sEqindex + sEqMatch[0].length));
                                }
                            });
                            disconn = true;
                        }
                    });
                });
                if(disconn){
                    observer.disconnect();
                    removeObserver();
                }
            });
            observer.observe(document, {
                childList: true,
                subtree: true
            })
            GM_setValue("observer", observer);
        }
    }

    function removeObserver(){
        let observer = GM_getValue("observer");
        if(observer != null){
            if(observer instanceof MutationObserver){
                observer.disconnect();
            }
            GM_deleteValue("observer");
        }
    }

    createObserver();

    $(document).on("yt-navigate-start", function(e){
        createObserver();
    });
    $(document).on("yt-navigate-finish", function(e){
        removeObserver();
    });
    $(window).on("beforeunload", function(e){
        removeObserver();
    });

})();

QingJ © 2025

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