IPTorrents thumbs

Adds thumbs on list pages

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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