Greasy Fork is available in English.

IPTorrents thumbs

Adds thumbs on list pages

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

You will need to install an extension such as Tampermonkey to install this 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        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);
  });
}