Empornium thumbnail preload

Preloads thumbnail images in the torrent table.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name             Empornium thumbnail preload
// @version          1.4.0
// @description      Preloads thumbnail images in the torrent table.
// @namespace        https://greasyfork.org/users/241444
// @author           salad: https://greasyfork.org/en/users/241444-salad
// @license          GPL-3.0-only
// @match            https://www.empornium.is/torrents.php*
// @match            https://www.empornium.is/top10.php*
// @match            https://www.empornium.is/bookmarks.php*
// @match            https://www.empornium.sx/torrents.php*
// @match            https://www.empornium.sx/top10.php*
// @match            https://www.empornium.sx/bookmarks.php*
// @icon             https://www.google.com/s2/favicons?domain=empornium.is
// ==/UserScript==

(async () => {

  if (document.querySelectorAll('#torrent_table, .torrent_table').length === 0) {
    return;
  }

  const torrentLinks = document.querySelectorAll('#torrent_table td a[onmouseover], .torrent_table td a[onmouseover]');

  const torrentUrls = Array.from(torrentLinks)
    .map(el => new URL(el.href));
  const torrentIds = torrentUrls.map(url => url.searchParams.get('id'));

  const domParser = new DOMParser();
  const previewHtmls = torrentIds.map(id => unsafeWindow[`overlay${id}`])
    .map(html => domParser.parseFromString(html, 'text/html'));
  const thumbnailUrls = previewHtmls.map(html => html.querySelector('img').src);

  console.info('Preloading %s thumbnails...', thumbnailUrls.length);
  console.time('Preloading thumbnails');

  const thumbnailElements = thumbnailUrls.map(src => {
    return new Promise(resolve => {
      const img = new Image();
      img.onload = () => resolve(img);
      img.src = src;
    });
  });

  await Promise.all(thumbnailElements);
  console.timeEnd('Preloading thumbnails');

})();