Replace Links with Images on 1337x.to

Replace specified links with images on 1337x.to

Από την 10/08/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Replace Links with Images on 1337x.to
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  Replace specified links with images on 1337x.to
// @author       Wei Zong
// @match        *://1337x.to/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    "use strict";

    // 获取所有的a标签
    const links = document.querySelectorAll("a.js-modal-url");
    links.forEach((link) => {
        const href = link.href;

        // 检查链接是否匹配 imgtraffic.com 的两种格式
        const imgtrafficMatch = href.match(
            /https:\/\/imgtraffic\.com\/[a-z]-1\/(\d{4}\/\d{2}\/\d{2}\/[a-z0-9]+)\.jpeg\.html/
        );
        if (imgtrafficMatch) {
            const imgSrc = `https://imgtraffic.com/1/${imgtrafficMatch[1]}.jpeg`;
            const imgElement = document.createElement("img");
            imgElement.src = imgSrc;
            imgElement.dataset.original = imgSrc;
            imgElement.classList.add("img-responsive", "descrimg", "lazy");
            imgElement.style.display = "block";

            link.parentNode.replaceChild(imgElement, link);
        }
    });

    // 获取所有的img标签
    const imgs = document.querySelectorAll("img");
    // 替换 imgtraffic.com 中的 /1s/ 为 /1/
    const replaceUrl1 = (url) =>
        url.replace("https://imgtraffic.com/1s/", "https://imgtraffic.com/1/");
    // 替换 .th.jpg 为 .jpg
    const replaceUrl2 = (url) =>
        url.replace(".th.jpg", ".jpg");

    imgs.forEach((img) => {
        if (img.src.includes("https://imgtraffic.com/1s/")) {
            img.src = replaceUrl1(img.src);
        }
        if (
            img.dataset.original &&
            img.dataset.original.includes("https://imgtraffic.com/1s/")
        ) {
            img.dataset.original = replaceUrl1(img.dataset.original);
        }
        if (img.src.includes(".th.jpg")) {
            img.src = replaceUrl2(img.src);
        }
        if (
            img.dataset.original &&
            img.dataset.original.includes(".th.jpg")
        ) {
            img.dataset.original = replaceUrl2(img.dataset.original);
        }
    });
})();