IPTorrents thumbs

Adds thumbs on list pages

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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