Pixiv Image Preload

Preload pixiv images

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Pixiv Image Preload
// @namespace   https://greatest.deepsurf.us/en/users/37676
// @description Preload pixiv images
// @match       *://*.pixiv.net/member_illust.php?*mode=manga*
// @match       *://*.pixiv.net/member_illust.php?*mode=medium*
// @match       *://*.pixiv.net/*/artworks/*
// @run-at      document-end
// @version     2.0.0
// @grant       none
// @license     Creative Commons Attribution 4.0 International Public License; http://creativecommons.org/licenses/by/4.0/
// ==/UserScript==

var preloadMeta = document.querySelector('meta[name="preload-data"]');

if (preloadMeta)
{
	var preloadContent = preloadMeta.getAttribute('content');

    if (preloadContent)
    {
        var illustID = null;

        try
        {
            preloadContent = JSON.parse(preloadContent);
            illustID = Object.values(preloadContent.illust)[0].id;

        } catch(e) {

        }
		
        if (illustID)
        {
            fetch('https://www.pixiv.net/ajax/illust/'+illustID+'/pages?lang=en').then((response) => {
                return response.json();
            }).then((imagesObj) => {
                if (imagesObj.error == false && Array.isArray(imagesObj.body))
                {
                    var arrayImage = [];

                    for (const element of imagesObj.body)
                    {
                        if (element.urls.regular)
                        arrayImage.push(element.urls.regular);
                    }

                    if (arrayImage.length > 0)
                    loadImage(0, arrayImage);
                }

            }).catch(function(error) {
                console.log("error fetching json data");
                console.log(error);
            });
        }
    }
}

function loadImage(index, arrayImage)
{
	if (index < arrayImage.length)
	{
		var image = new Image();
		image.onload = function() {
			loadImage(index+1, arrayImage);
		};
		image.src = arrayImage[index];
	}
}