Greasy Fork is available in English.

IPTorrents thumbs

Adds thumbs on list pages

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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