Youtube社区点击图片查看全图

点击图片查看全图

  1. // ==UserScript==
  2. // @name:zh-CN Youtube社区点击图片查看全图
  3. // @name Youtube community post click to view full size image
  4. // @homepage https://gf.qytechs.cn/en/scripts/452960-youtube-community-post-click-to-view-full-size-image
  5. // @namespace http://tampermonkey.net/
  6. // @version 1.21
  7. // @description:zh-CN 点击图片查看全图
  8. // @description Youtube community click post image to view full size image.
  9. // @author CZX Fuckerman
  10. // @match https://www.youtube.com/*
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_deleteValue
  14. // @license GPL
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. // Your code here...
  20.  
  21. function createObserver(){
  22. 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){
  23. let observer = new MutationObserver(function(mutations, observer) {
  24. let disconn = false;
  25. mutations.forEach(function(mutation) {
  26. mutation.addedNodes.forEach(function(node){
  27. if(node.nodeName == "DIV" && node.id == "image-container" && node.classList.contains("style-scope") && node.classList.contains("ytd-backstage-image-renderer") && node.classList.length == 2){
  28. node.addEventListener('click',()=>{
  29. let src = node.querySelector("img").getAttribute("src");
  30. let sEqindex = src.search(/[=][s][1-9]\d*/g);
  31. let sEqMatch = src.match(/[=][s][1-9]\d*/g);
  32. if(sEqMatch.length == 0){
  33. window.open(src.substring(0,src.indexOf("=")));
  34. } else {
  35. window.open(src.substring(0,sEqindex + sEqMatch[0].length));
  36. }
  37. });
  38. node.style.cursor = "pointer";
  39. disconn = true;
  40. }
  41. });
  42. });
  43. if(disconn){
  44. observer.disconnect();
  45. removeObserver();
  46. }
  47. });
  48. observer.observe(document, {
  49. childList: true,
  50. subtree: true
  51. })
  52. GM_setValue("observer", observer);
  53. }
  54. }
  55.  
  56. function removeObserver(){
  57. let observer = GM_getValue("observer");
  58. if(observer != null){
  59. if(observer instanceof MutationObserver){
  60. observer.disconnect();
  61. }
  62. GM_deleteValue("observer");
  63. }
  64. }
  65.  
  66. createObserver();
  67.  
  68. document.addEventListener('yt-navigate-start',()=>{
  69. createObserver();
  70. });
  71. document.addEventListener('yt-navigate-start',()=>{
  72. createObserver();
  73. });
  74. window.addEventListener('beforeunload',()=>{
  75. createObserver();
  76. });
  77.  
  78.  
  79. })();

QingJ © 2025

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