您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
点击图片查看全图
- // ==UserScript==
- // @name:zh-CN Youtube社区点击图片查看全图
- // @name Youtube community post click to view full size image
- // @homepage https://greasyfork.org/en/scripts/452960-youtube-community-post-click-to-view-full-size-image
- // @namespace http://tampermonkey.net/
- // @version 1.21
- // @description:zh-CN 点击图片查看全图
- // @description Youtube community click post image to view full size image.
- // @author CZX Fuckerman
- // @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.addEventListener('click',()=>{
- let src = node.querySelector("img").getAttribute("src");
- let sEqindex = src.search(/[=][s][1-9]\d*/g);
- let 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));
- }
- });
- node.style.cursor = "pointer";
- 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.addEventListener('yt-navigate-start',()=>{
- createObserver();
- });
- document.addEventListener('yt-navigate-start',()=>{
- createObserver();
- });
- window.addEventListener('beforeunload',()=>{
- createObserver();
- });
- })();