Pixiv Image Preload

Preload pixiv images

  1. // ==UserScript==
  2. // @name Pixiv Image Preload
  3. // @namespace https://gf.qytechs.cn/en/users/37676
  4. // @description Preload pixiv images
  5. // @match *://*.pixiv.net/member_illust.php?*mode=manga*
  6. // @match *://*.pixiv.net/member_illust.php?*mode=medium*
  7. // @match *://*.pixiv.net/*/artworks/*
  8. // @run-at document-end
  9. // @version 2.0.0
  10. // @grant none
  11. // @license Creative Commons Attribution 4.0 International Public License; http://creativecommons.org/licenses/by/4.0/
  12. // ==/UserScript==
  13.  
  14. var preloadMeta = document.querySelector('meta[name="preload-data"]');
  15.  
  16. if (preloadMeta)
  17. {
  18. var preloadContent = preloadMeta.getAttribute('content');
  19.  
  20. if (preloadContent)
  21. {
  22. var illustID = null;
  23.  
  24. try
  25. {
  26. preloadContent = JSON.parse(preloadContent);
  27. illustID = Object.values(preloadContent.illust)[0].id;
  28.  
  29. } catch(e) {
  30.  
  31. }
  32. if (illustID)
  33. {
  34. fetch('https://www.pixiv.net/ajax/illust/'+illustID+'/pages?lang=en').then((response) => {
  35. return response.json();
  36. }).then((imagesObj) => {
  37. if (imagesObj.error == false && Array.isArray(imagesObj.body))
  38. {
  39. var arrayImage = [];
  40.  
  41. for (const element of imagesObj.body)
  42. {
  43. if (element.urls.regular)
  44. arrayImage.push(element.urls.regular);
  45. }
  46.  
  47. if (arrayImage.length > 0)
  48. loadImage(0, arrayImage);
  49. }
  50.  
  51. }).catch(function(error) {
  52. console.log("error fetching json data");
  53. console.log(error);
  54. });
  55. }
  56. }
  57. }
  58.  
  59. function loadImage(index, arrayImage)
  60. {
  61. if (index < arrayImage.length)
  62. {
  63. var image = new Image();
  64. image.onload = function() {
  65. loadImage(index+1, arrayImage);
  66. };
  67. image.src = arrayImage[index];
  68. }
  69. }

QingJ © 2025

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