Milkie Thumbnails

Hover torrent link to preview thumbnails

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Milkie Thumbnails
// @namespace    dumpsterbaby.lol
// @version      0.0.0
// @description  Hover torrent link to preview thumbnails
// @author       egore
// @license      MIT
// @match        https://milkie.cc/browse*
// @icon         https://milkie.cc/assets/icons/logo.svg
// @grant        none
// ==/UserScript==

(function () {

  function newElement(tagName, attributes, content) {
    var tag = document.createElement(tagName);
    for (var key in attributes || {}) {
      if (attributes[key] !== undefined && attributes[key] !== null) {
        tag.setAttribute(key, attributes[key]);
      }
    }
    tag.innerHTML = content || "";
    return tag;
  }

  function findLinksByHref(urlFragment) {
    const links = Array.from(document.querySelectorAll('a')).filter(link => {
      return link.href.includes(urlFragment);
    });
    return links;
  }

  function iterateNodeList(nodeList, callback) {
    if (!(nodeList instanceof NodeList)) {
      throw new TypeError("Invalid NodeList provided.");
    }
    if (typeof callback !== "function") {
      throw new TypeError("Callback must be a function.");
    }
    for (let i = 0; i < nodeList.length; i++) {
      if (callback(nodeList[i]) === false) {
        break; //Stop iteration if callback returns false
      }
    }
  }

  function init() {
    const uls = document.querySelectorAll('.adult');

    const btns = document.querySelectorAll('.mat-icon.notranslate.download.material-icons.mat-icon-no-color');
    btns.forEach(btn => { btn.style.display = 'none' });

    if (interval) {
      clearInterval(interval);
      interval = undefined;
      window.setInterval(init, 5000);
    }

    iterateNodeList(uls, (node) => {
      const context = node.__ngContext__[115]

      const ln = findLinksByHref(`/browse/${context}`);
      const link = ln[0];

      const previewContainer = newElement("div", {
        style: `
          position: absolute;
        `
      });

      const previewContainer2 = newElement("div", {
        style: `
          position: absolute;
        `
      });

      const previewContainer3 = newElement("div", {
        style: `
          position: absolute;
        `
      });

      for (let i = 0; i < 2; i++) {
        const img = newElement("img", {
          src: `https://cdn.milkie.cc/t/${context}/o_${i}.jpg`,
          style: `
            display: none;
            position: absolute;
            left: ${0 + i * 452}px;
            top: 22px;
            max-width: 450px;
          `,
          loading: "lazy"
        });
        previewContainer.appendChild(img);
        link.parentNode.insertBefore(previewContainer, link.nextSibling);

        link.addEventListener('mouseover', () => {
          img.style.display = "block";
        });
        link.addEventListener('mouseout', () => {
          img.style.display = "none";
        });
      }

      for (let i = 2; i < 4; i++) {
        const img = newElement("img", {
          src: `https://cdn.milkie.cc/t/${context}/o_${i}.jpg`,
          style: `
            display: none;
            position: absolute;
            left: ${0 + (i - 2) * 452}px;
            top: 277px;
            max-width: 450px;
          `,
          loading: "lazy"
        });
        previewContainer2.appendChild(img);
        link.parentNode.insertBefore(previewContainer2, link.nextSibling);

        link.addEventListener('mouseover', () => {
          img.style.display = "block";
        });
        link.addEventListener('mouseout', () => {
          img.style.display = "none";
        });
      }

      for (let i = 4; i < 6; i++) {
        const img = newElement("img", {
          src: `https://cdn.milkie.cc/t/${context}/o_${i}.jpg`,
          style: `
            display: none;
            position: absolute;
            left: ${0 + (i - 4) * 452}px;
            top: 532px;
            max-width: 450px;
          `,
          loading: "lazy"
        });
        previewContainer3.appendChild(img);
        link.parentNode.insertBefore(previewContainer3, link.nextSibling);

        link.addEventListener('mouseover', () => {
          img.style.display = "block";
        });
        link.addEventListener('mouseout', () => {
          img.style.display = "none";
        });
      }

    });
  }

  let interval = window.setInterval(init, 500);

})();