Nyaa.si - Load Thumbnail

Load image from hentai-covers links.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Nyaa.si - Load Thumbnail
// @name:ja     Nyaa.si - Load Thumbnail
// @name:zh-CN  Nyaa.si - 自动加载预览图
// @name:zh-TW  Nyaa.si - 自動載入預覽圖
// @description       Load image from hentai-covers links.
// @description:ja    hentai-coversのリンクから画像を読み込みます。
// @description:zh-CN 加载预览图从hentai-covers的链接。
// @description:zh-TW 加載預覽圖從hentai-covers的鏈接。
// @namespace   none
// @version     1.4
// @include     https://sukebei.nyaa.si/view/*
// @connect     hentai-covers.site
// @grant       GM_xmlhttpRequest
// ==/UserScript==
(function () {
  let desc = document.querySelector('#torrent-description');
  if (desc) {
    let urls = desc.innerText.match(/https?:\/\/hentai-covers\.site\/image\/\w+/g);
    if (urls) {
      desc.parentNode.insertAdjacentHTML('afterend', '<div class="panel panel-default"><div class="panel-body" id="hentai-covers"></div></div>');
      let covers = document.querySelector('#hentai-covers');
      urls.forEach(url => {
        let loading = document.createElement('div');
        loading.innerHTML = 'Loading... ';
        covers.appendChild(loading);
        GM_GET(url, result => {
          if (result.status == 200) {
            let doc = new DOMParser().parseFromString(result.responseText, 'text/html');
            let img = doc.querySelector('#image-viewer-container > img');
            //if (img) loading.innerHTML = '<img src="' + img.src + '">';
            if (img) {
              GM_GET(img.src, result => {
                loading.innerHTML = '<img src="' + img.src + '">';
              });
            }
            else loading.innerHTML += 'Error: image not found.';
          } else loading.innerHTML += 'Error: ' + result.status;
        });
      });
    }
  }
})();

function GM_GET(url, callback) {
  GM_xmlhttpRequest({
    method: 'GET',
    url: url,
    headers: {referer: "https://hentai-covers.site/"},
    onload: result => callback(result),
    onerror: result => callback(result),
    ontimeout: result => callback(result)
  });
}