m-team大图浏览

种子列表/详情/演员列表 大图浏览,标题翻译。

// ==UserScript==
// @name         m-team大图浏览
// @namespace    mteam
// @version      0.6.0-beta.9
// @description  种子列表/详情/演员列表 大图浏览,标题翻译。
// @author       AfAn
// @license      MIT
// @match        https://*.m-team.cc/*
// @connect      translate.google.com
// @connect      api.avgle.com
// @grant        GM_xmlhttpRequest

// ==/UserScript==
!(function () {
    "use strict";
    const t = window.location.host;
    var e, n;
    (e = window.history),
        (n = e.pushState),
        (e.pushState = function (t) {
            return (
                "function" == typeof e.onpushstate && e.onpushstate({ state: t }),
                n.apply(e, arguments)
            );
        }),
        (window.history.onpushstate = function (t) {
            setTimeout(function () { }, 0);
        });
    var o = {
        "/api/torrent/search": function (e) {
            !(async function (e) {
                if (0 !== window.location.href.indexOf(`https://${t}/browse/adult`))
                    return;
                let n = JSON.parse(e);
                if (!n || !("code" in n) || "0" != n.code) return !1;
                const o = "next.m-team.cc" === t ? 1 : 2;
                (document.querySelector(
                    `div.ant-spin-container table thead tr th:nth-of-type(${o})`
                ).style.width = window.innerWidth >= 1400 ? "700px" : "500px"),
                    (document.querySelector(
                        "div.app-content__inner div.mx-auto"
                    ).style.maxWidth = "100%");
                let a = [];
                for (let t = 0; t < 30; t++) {
                    await l(1e3),
                        (a = document.querySelectorAll(
                            "div.ant-spin-container table tbody tr"
                        ));
                    let t = +n.data.pageSize,
                        e = +n.data.total;
                    if (a.length == t) break;
                    if (e < t && a.length == e) break;
                }
                document
                    .querySelectorAll(
                        "div.ant-spin-container table div.trans-container"
                    )
                    .forEach((t) => {
                        t.remove();
                    }),
                    a.forEach(async (e, a) => {
                        (e.querySelector(
                            `td:nth-of-type(${o}) img.torrent-list__thumbnail`
                        ).style.height = "auto"),
                            (e.querySelector(
                                `td:nth-of-type(${o}) img.torrent-list__thumbnail`
                            ).style.width = "100%"),
                            (e.querySelector(
                                `td:nth-of-type(${o}) img.torrent-list__thumbnail`
                            ).style.maxWidth = "500px"),
                            e
                                .querySelector(
                                    `td:nth-of-type(${o}) img.torrent-list__thumbnail`
                                )
                                .addEventListener("click", function (e) {
                                    e.stopPropagation(),
                                        window.open(
                                            `https://${t}/detail/${n.data.data[a].id}`,
                                            "_blank"
                                        );
                                }),
                            e.querySelector(`td:nth-of-type(${o}) div.ant-image-mask`) &&
                            e
                                .querySelector(`td:nth-of-type(${o}) div.ant-image-mask`)
                                .remove();
                        let r = e.querySelector("td:nth-of-type(3)");
                        "next.m-team.cc" === t &&
                            (r = e.querySelector("td:nth-of-type(1)"));
                        let s = r.querySelectorAll(
                            "span.ant-typography-ellipsis-single-line"
                        );
                        if (
                            ((s[0].style.whiteSpace = "normal"),
                                (s[0].style.overflow = "unset"),
                                (s[0].style.textOverflow = "unset"),
                                (s[0].style.display = "block"),
                                s.length > 1 &&
                                ((s[1].style.whiteSpace = "normal"),
                                    (s[1].style.overflow = "unset"),
                                    (s[1].style.textOverflow = "unset"),
                                    (s[1].style.display = "block")),
                                r.querySelector("br") && r.querySelector("br").remove(),
                                "next.m-team.cc" === t)
                        ) {
                            const t = s[0].closest("a");
                            t &&
                                t.parentNode.querySelectorAll("a ~ div").forEach((t) => {
                                    t.style.display = "block";
                                });
                        } else s[0].closest("a > div").style.display = "block";
                        async function c(t, e) {
                            t.disabled = !0;
                            let n = s[0].querySelector("strong").innerText;
                            s.length > 1 && (n += " ||| " + s[1].innerText);
                            let o = await i(n);
                            (o = o.replace("|||", "<br />")), (e.innerHTML = o);
                        }
                        (() => {
                            let t = document.createElement("div"),
                                e = document.createElement("button");
                            (e.innerText = "翻 译"),
                                e.classList.add(
                                    "ant-btn",
                                    "css-n9csir",
                                    "ant-btn-default",
                                    "ant-btn-sm"
                                ),
                                (e.onclick = () => {
                                    c(e, t);
                                }),
                                (t.style.marginTop = "2rem"),
                                t.appendChild(e),
                                t.classList.add("trans-container"),
                                s[0].closest("a").parentNode.appendChild(t);
                        })(),
                            30 === a && (await l(1e3));
                    });
            })(e);
        },
        "/api/dmm/showcase/fetchList": function (e) {
            !(async function (e) {
                const n = window.location.href;
                if (
                    0 !== n.indexOf(`https://${t}/showcaseDetail?id=`) &&
                    0 !== n.indexOf(`https://${t}/showcaseDetail?name=`)
                )
                    return;
                let o = JSON.parse(e);
                if (!o || !("code" in o) || "0" != o.code) return !1;
                const a = 2;
                (document.querySelector(
                    `div.ant-spin-container table thead tr th:nth-of-type(${a})`
                ).style.width = window.innerWidth >= 1400 ? "700px" : "500px"),
                    (document.querySelector(
                        "div.app-content__inner div.mx-auto"
                    ).style.maxWidth = "100%");
                let r = [];
                for (
                    let t = 0;
                    t < 30 &&
                    (await l(1e3),
                        (r = document.querySelectorAll(
                            "div.ant-spin-container table tbody tr"
                        )),
                        r.length != o.data.list.length);
                    t++
                );
                r.forEach(async (e, n) => {
                    if (
                        ((e.querySelector(
                            `td:nth-of-type(${a}) img.torrent-list__thumbnail`
                        ).style.height = "auto"),
                            (e.querySelector(
                                `td:nth-of-type(${a}) img.torrent-list__thumbnail`
                            ).style.width = "100%"),
                            (e.querySelector(
                                `td:nth-of-type(${a}) img.torrent-list__thumbnail`
                            ).style.maxWidth = "500px"),
                            e
                                .querySelector(
                                    `td:nth-of-type(${a}) img.torrent-list__thumbnail`
                                )
                                .addEventListener("click", function (e) {
                                    e.stopPropagation(),
                                        window.open(
                                            `https://${t}/detail/${o.data.list[n].id}`,
                                            "_blank"
                                        );
                                }),
                            e.querySelector(`td:nth-of-type(${a}) div.ant-image-mask`) &&
                            e
                                .querySelector(`td:nth-of-type(${a}) div.ant-image-mask`)
                                .remove(),
                            "next.m-team.cc" === t)
                    ) {
                        let o = e.querySelector("td:nth-of-type(2)"),
                            a = o.querySelectorAll(
                                "span.ant-typography-ellipsis-single-line"
                            );
                        if (
                            ((a[0].style.whiteSpace = "normal"),
                                (a[0].style.overflow = "unset"),
                                (a[0].style.textOverflow = "unset"),
                                (a[0].style.display = "block"),
                                a.length > 1 &&
                                ((a[1].style.whiteSpace = "normal"),
                                    (a[1].style.overflow = "unset"),
                                    (a[1].style.textOverflow = "unset"),
                                    (a[1].style.display = "block")),
                                o.querySelector("br") && o.querySelector("br").remove(),
                                "next.m-team.cc" === t)
                        ) {
                            const t = a[0].closest("a");
                            t &&
                                t.parentNode.querySelectorAll("a ~ div").forEach((t) => {
                                    t.style.display = "block";
                                });
                        } else a[0].closest("a > div").style.display = "block";
                        async function r(t, e) {
                            t.disabled = !0;
                            let n = a[0].querySelector("strong").innerText;
                            a.length > 1 && (n += " ||| " + a[1].innerText);
                            let o = await i(n);
                            (o = o.replace("|||", "<br />")), (e.innerHTML = o);
                        }
                        (() => {
                            let t = document.createElement("div"),
                                e = document.createElement("button");
                            (e.innerText = "翻 译"),
                                e.classList.add(
                                    "ant-btn",
                                    "css-n9csir",
                                    "ant-btn-default",
                                    "ant-btn-sm"
                                ),
                                (e.onclick = () => {
                                    r(e, t);
                                }),
                                (t.style.marginTop = "2rem"),
                                t.appendChild(e),
                                t.classList.add("trans-container"),
                                a[0].closest("a").parentNode.appendChild(t);
                        })(),
                            30 === n && (await l(1e3));
                    }
                });
            })(e);
        },
        "/api/dmm/dmmInfo": function (e) {
            !(async function (e) {
                if (0 !== window.location.href.indexOf(`https://${t}/detail/`))
                    return;
                let n = JSON.parse(e);
                if (!n || !("code" in n) || "0" != n.code) return !1;
                await l(1e3),
                    document
                        .querySelectorAll(".ant-image-img.\\!max-w-600")
                        .forEach((t) => {
                            t.classList.remove("!max-w-600");
                        });
                const o =
                    "picData" in n.data && n.data.picData
                        ? n.data.picData.split(",")
                        : [];
                let a = !1;
                function r(t) {
                    return t.replace(
                        /([^\/]+?)(-)(\d+\.\w+)$/,
                        (t, e, n, o) => `${e}jp${n}${o}`
                    );
                }
                o.forEach((t) => {
                    const e = document.querySelector(`img[src="${t}"]`);
                    if (e) {
                        a || (e.closest(".grid").classList.remove("grid"), (a = !0)),
                            (e.src = r(t)),
                            e.parentElement.querySelector(".ant-image-mask").remove();
                        e.closest(".ant-image").style.pointerEvents = "none";
                    }
                });
            })(e);
        },
    },
        a = XMLHttpRequest.prototype.send,
        r = XMLHttpRequest.prototype.open;
    function i(t) {
        return new Promise((e, n) => {
            (t = t.replace("#", "")),
                GM_xmlhttpRequest({
                    method: "GET",
                    url:
                        "https://translate.google.com/translate_a/single?client=gtx&dt=t&dt=bd&dj=1&source=input&hl=zh-CN&sl=auto&tl=zh-CN&q=" +
                        t,
                    headers: { cookie: "" },
                    onload: function (t) {
                        for (
                            var n = JSON.parse(t.responseText), o = "", a = 0;
                            a < n.sentences.length;
                            a++
                        )
                            o += n.sentences[a].trans;
                        e(o);
                    },
                    onerror: function (t) {
                        n();
                    },
                });
        });
    }
    function l(t) {
        return new Promise((e) => setTimeout(e, t));
    }
    (XMLHttpRequest.prototype.open = function (t, e) {
        return (this.url = e), r.apply(this, arguments);
    }),
        (XMLHttpRequest.prototype.send = function () {
            return (
                this.addEventListener("load", function () {
                    4 === this.readyState &&
                        200 === this.status &&
                        Object.keys(o).forEach((t) => {
                            this.url.includes(t) && o[t](this.response);
                        });
                }),
                a.apply(this, arguments)
            );
        });
})();