nhentai preloader

Preload images on nhentai for faster loading

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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)
})()