Guest User

Untitled

a guest
Jul 13th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. // ==UserScript==
  2. // @name:zh-CN Youtube社区点击图片查看全图
  3. // @name Youtube community post click to view full size image
  4. // @homepage https://greasyfork.org/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. // @downloadURL https://update.greasyfork.org/scripts/452960/Youtube%20community%20post%20click%20to%20view%20full%20size%20image.user.js
  16. // @updateURL https://update.greasyfork.org/scripts/452960/Youtube%20community%20post%20click%20to%20view%20full%20size%20image.meta.js
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21. // Your code here...
  22.  
  23. function createObserver(){
  24. 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){
  25. let observer = new MutationObserver(function(mutations, observer) {
  26. let disconn = false;
  27. mutations.forEach(function(mutation) {
  28. mutation.addedNodes.forEach(function(node){
  29. if(node.nodeName == "DIV" && node.id == "image-container" && node.classList.contains("style-scope") && node.classList.contains("ytd-backstage-image-renderer") && node.classList.length == 2){
  30. node.addEventListener('click', () => {
  31. let src = node.querySelector("img").getAttribute("src");
  32. let modifiedSrc = src.replace(/=s[1-9]\d*[^&]*/g, '=s0');
  33. window.open(modifiedSrc);
  34. });
  35. node.style.cursor = "pointer";
  36. disconn = true;
  37. }
  38. });
  39. });
  40. if(disconn){
  41. observer.disconnect();
  42. removeObserver();
  43. }
  44. });
  45. observer.observe(document, {
  46. childList: true,
  47. subtree: true
  48. })
  49. GM_setValue("observer", observer);
  50. }
  51. }
  52.  
  53. function removeObserver(){
  54. let observer = GM_getValue("observer");
  55. if(observer != null){
  56. if(observer instanceof MutationObserver){
  57. observer.disconnect();
  58. }
  59. GM_deleteValue("observer");
  60. }
  61. }
  62.  
  63. createObserver();
  64.  
  65. document.addEventListener('yt-navigate-start',()=>{
  66. createObserver();
  67. });
  68. document.addEventListener('yt-navigate-start',()=>{
  69. createObserver();
  70. });
  71. window.addEventListener('beforeunload',()=>{
  72. createObserver();
  73. });
  74.  
  75.  
  76. })();
Advertisement
Add Comment
Please, Sign In to add comment