YouTube Image Fix

Fixes display of avatars, channel art, and video previews on YouTube for users in Russia.

目前为 2024-10-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Image Fix
  3. // @namespace *
  4. // @version 1.0.0
  5. // @description Fixes display of avatars, channel art, and video previews on YouTube for users in Russia.
  6. // @author Your Name
  7. // @match *://*.youtube.com/*
  8. // @grant none
  9. // @license MIT
  10.  
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const rules = [
  17. {
  18. id: 1,
  19. priority: 1,
  20. action: {
  21. type: 'redirect',
  22. redirect: {
  23. regexSubstitution: 'https://lh3.ggpht.com/$1'
  24. }
  25. },
  26. condition: {
  27. regexFilter: 'https://yt3.ggpht.com/(.*)',
  28. resourceTypes: ['image']
  29. }
  30. }
  31. ];
  32.  
  33. function applyRules() {
  34. rules.forEach(rule => {
  35. const images = document.querySelectorAll(`img[src^="${rule.condition.regexFilter.replace('(.*)', '')}"]`);
  36. images.forEach(image => {
  37. image.src = image.src.replace(new RegExp(rule.condition.regexFilter), rule.action.redirect.regexSubstitution);
  38. });
  39. });
  40. }
  41.  
  42. // Apply rules initially and on DOM changes
  43. applyRules();
  44. const observer = new MutationObserver(applyRules);
  45. observer.observe(document.body, { childList: true, subtree: true });
  46. })();