微信公众号去除图片延迟加载

去除图片延迟加载,直接显示原图片

当前为 2025-05-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Disable Wechat Images Lazyload
  3. // @name:zh-CN 微信公众号去除图片延迟加载
  4. // @description Disable Wechat Images Lazyload, Show Origin Images Directly
  5. // @description:zh-CN 去除图片延迟加载,直接显示原图片
  6. // @namespace https://www.runningcheese.com
  7. // @version 0.3
  8. // @author RunningCheese
  9. // @match https://mp.weixin.qq.com/s/*
  10. // @match https://mp.weixin.qq.com/s?__biz=*
  11. // @run-at document-start
  12. // @require https://code.jquery.com/jquery-3.3.1.min.js
  13. // @icon https://t1.gstatic.cn/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://mp.weixin.qq.com
  14. // @license MIT
  15. // ==/UserScript==
  16. var $ = window.jQuery;
  17. // 处理图片懒加载
  18. function processLazyImages() {
  19. $('img').each(function(){
  20. var dataSrc = $(this).attr('data-src');
  21. if (dataSrc){
  22. $(this).attr('src', dataSrc);
  23. $(this).removeAttr('data-src');
  24. $(this).removeAttr('data-type');
  25. $(this).removeAttr('data-w');
  26. $(this).removeAttr('data-ratio');
  27. $(this).removeAttr('data-fail');
  28. }
  29. });
  30. }
  31. // 移除URL中的懒加载参数
  32. function removeWxLazyParam() {
  33. const links = document.querySelectorAll('a');
  34. links.forEach(link => {
  35. if (link.href && link.href.includes('wx_lazy=1')) {
  36. link.href = link.href.replace('wx_lazy=1', '');
  37. }
  38. });
  39. }
  40. // 监听DOM变化,处理动态加载的内容
  41. function observeDOMChanges() {
  42. const observer = new MutationObserver(function(mutations) {
  43. processLazyImages();
  44. removeWxLazyParam();
  45. });
  46. observer.observe(document.body, {
  47. childList: true,
  48. subtree: true
  49. });
  50. }
  51. // 页面加载完成后执行
  52. $(document).ready(function() {
  53. // 立即执行一次
  54. processLazyImages();
  55. removeWxLazyParam();
  56. // 再延迟执行一次,确保处理完所有图片
  57. setTimeout(function(){
  58. processLazyImages();
  59. removeWxLazyParam();
  60. // 开始监听DOM变化
  61. observeDOMChanges();
  62. }, 1000);
  63. });
  64. // 替换HTML内容中的懒加载属性
  65. document.addEventListener('DOMContentLoaded', function() {
  66. const htmlContent = document.body.innerHTML;
  67. document.body.innerHTML = htmlContent.replace(/wx_lazy=1/g, '').replace(/data-src/g, 'src');
  68. });