IPTorrents thumbs

Adds thumbs on list pages

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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        IPTorrents thumbs
// @namespace   com.iptorrents.omdb
// @description Adds thumbs on list pages
// @include     *://iptorrents.com/t*
// @include     *://iptorrents.com/movies*
// @include     *://ipt.lol/t*
// @include     *://ipt.lol/movies*
// @grant       GM_addStyle
// @version     3.1.0
// @run-at      document-end
// ==/UserScript==

GM_addStyle ( `
  /* Body Background Color & Light Mode */
  body {
  background: #111 !important;
  }
  .Brtness {
  background: #eee !important;
  }
 
  /* Shadow & Width Fix */
  #iptStart {
  box-shadow: 0 30px 37px -3px #000,0 60px 60px -6px #111 !important;
  /*max-width: 90%;*/
  }
 
  /* Button Fix & Text Removal */
  .butRow > div > a {
  padding-top: 20px !important;
  padding-bottom: 20px !important;
  }
  .butRow > div > a > b {
  display: none !important;
  }
 
  /* Darken The Banner Nav Bar */
  .stats {
  background: rgba(0,0,0,.6) !important;
  }
 
  /* Max Banner Size If Your Sceen Exceeds 1440p */
  .banner {
  /*max-height: 360px !important;*/
  }
`);

function fetchPoster(id, callback) {
  const xhr = new XMLHttpRequest();
  xhr.open('POST', '/API.php');
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.onload = function () {
    try {
      const data = JSON.parse(xhr.responseText);

      const appendEntry = data.Fs
        ?.flat(Infinity)
        ?.find(item => typeof item === 'string' && item.includes('img') && item.includes('poster'));

      if (appendEntry) {
        const posterUrl = appendEntry.match(/src="([^"]+)"/)?.[1]
          ?.replace(/\\\//g, '/');

        if (posterUrl) callback(posterUrl);
      }
    } catch (err) {
      console.error(`Failed to parse poster for id ${id}:`, err);
    }
  };
  xhr.onerror = function () {
    console.error(`Failed to fetch poster for id ${id}`);
  };
  xhr.send(`jxt=3&jxw=icrd&id=${id}`);
}

const searchInput = document.querySelector('input[name=q]');

if (searchInput?.value) {
  const pagination = document.querySelector('.pagination');
  if (!pagination) return;

  let id = searchInput.value;

  if (/^\d+$/.test(id)) {
    const firstLink = document.querySelector('#torrents tbody tr td.al a[href^="/t/"]');
    if (!firstLink) return;
    id = firstLink.href.match(/\/t\/(\d+)/)?.[1];
    if (!id) return;
  }

  fetchPoster(id, posterUrl => {
    const posterImg = document.createElement('img');
    posterImg.src = posterUrl;
    posterImg.classList.add('poster');
    posterImg.height = 256;

    pagination.style.height = 'unset';
    pagination.style.display = 'flex';
    pagination.style.justifyContent = 'space-between';
    pagination.style.alignItems = 'flex-end';
    pagination.append(posterImg);
  });

} else {
  let prevId = null;
  let delay = 0;

  document.querySelectorAll('#torrents tbody tr').forEach(tr => {
    const link = tr.querySelector('td.al a[href^="/t/"]');
    if (!link) return;

    const id = link.href.match(/\/t\/(\d+)/)?.[1];
    if (!id) return;

    const img = tr.querySelector('img[src*="cloudstatic.net"]');
    if (!img) return;

    if (prevId !== null && id !== prevId) {
      delay += 3000;
    }
    prevId = id;

    setTimeout(() => {
      fetchPoster(id, posterUrl => {
        const posterImg = document.createElement('img');
        posterImg.src = posterUrl;
        posterImg.classList.add('poster');
        posterImg.height = 132;
        img.after(posterImg);
      });
    }, delay);
  });
}