Lasy_load_img_Library

2.0

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/488188/1475752/Lasy_load_img_Library.js

  1. // ==UserScript==
  2. // @name Lasy_load_img_Library 3.0
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024.11.1
  5. // @description 全新的写法
  6. // @author You
  7. // @grant none
  8. // @include *
  9. // ==/UserScript==
  10.  
  11. function LazyLoad(){
  12. // let downloader = new window.GAIL.Downloader();
  13. let loadType = "ImgLoad";
  14. this.Set_laodType = (n)=>{loadType = n;};
  15. this.Start = async (srcs,imgs)=>{
  16. for(var i=0;i<imgs.length;i++){
  17. const img = imgs.eq(i);
  18. const src = srcs[i];
  19. if(loadType == "ImgLoad"){
  20. StartLoadOne(img);
  21. await ByLoadEvent(src);
  22. LoadedOne(src,img);
  23. }
  24. }
  25. AllOver();
  26. }
  27. function ByLoadEvent(src) {
  28. return new Promise((resolve, reject) => {
  29. const img = new Image(); // 使用 Image 构造函数
  30. img.onload = () => resolve(); // 使用箭头函数
  31. img.onerror = () => reject(); // 使用箭头函数
  32. img.src = src;
  33. });
  34. }
  35. let StartLoadOne = (img)=>{
  36. const p = $("<p>loading</p>");
  37. img.after(p);
  38. };
  39. this.OnStartLoadOne = (foo)=>{StartLoadOne = foo;}
  40. let LoadedOne = (src,img)=>{
  41. img.next("p").remove();
  42. img[0].src = src;
  43. console.log(src);
  44. };
  45. this.OnLoadedOne = (foo)=>{LoadedOne = foo;}
  46. let AllOver = ()=>{};
  47. this.OnAllOver = (foo)=>{AllOver = foo;};
  48. }
  49. window.LazyLoad = LazyLoad;

QingJ © 2025

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