nhentai preloader

Preload images on nhentai for faster loading

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         nhentai preloader
// @description  Preload images on nhentai for faster loading
// @version      0.1.1
// @author       blazeu
// @namespace    https://greasyfork.org/users/11422
// @match        http://nhentai.net/g/*/*/
// @grant        none
// ==/UserScript==

/* global Image, media_id, current_page, num_pages */

(function () {
  function load (url, callback) {
    var img = new Image()
    img.onload = img.onerror = function () {
      callback()
    }
    img.src = url
  }

  function mediaUrl (media, page) {
    return '//i.nhentai.net/galleries/'.replace(/^https?:/, '') + media + '/' + page
  }

  function preload (media, start, end) {
    var url = mediaUrl(media, start)
    load(url, function () {
      if (++start > end) return
      preload(media, start, end)
    })
  }

  preload(media_id, +current_page + 1, num_pages)
})()