Greasy Fork

Greasy Fork is available in English.

Tong Li Online: Blurs R-rated Covers

Blurs the covers of R-rated novels on Tong Li Online.

目前为 2024-02-09 提交的版本,查看 最新版本

// ==UserScript==
// @name               Tong Li Online: Blurs R-rated Covers
// @name:zh-TW         東立漫遊網:模糊限制級封面
// @description        Blurs the covers of R-rated novels on Tong Li Online.
// @description:zh-TW  模糊東立漫遊網限制級書本的封面。
// @icon               https://icons.duckduckgo.com/ip3/www.tongli.com.tw.ico
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.1.2
// @license            MIT
// @match              https://www.tongli.com.tw/
// @match              https://www.tongli.com.tw/index.aspx
// @match              https://www.tongli.com.tw/search3.aspx
// @match              https://www.tongli.com.tw/BooksList.aspx
// @match              https://www.tongli.com.tw/BooksList.aspx?*
// @match              https://www.tongli.com.tw/GbooksList.aspx
// @match              https://www.tongli.com.tw/GbooksList.aspx?*
// @match              https://www.tongli.com.tw/webpagebooks.aspx
// @match              https://www.tongli.com.tw/webpagebooks.aspx?*
// @match              https://www.tongli.com.tw/WebPageBooks.aspx
// @match              https://www.tongli.com.tw/WebPageBooks.aspx?*
// @match              https://www.tongli.com.tw/ThemeBL.aspx
// @match              https://www.tongli.com.tw/ThemeBLBooks.aspx
// @match              https://www.tongli.com.tw/ThemeBLBooks.aspx?*
// @match              https://www.tongli.com.tw/ThemeBeautiful.aspx
// @match              https://www.tongli.com.tw/ThemeBeautiful.aspx?*
// @match              https://www.tongli.com.tw/ThemeGL.aspx
// @match              https://www.tongli.com.tw/ThemeGL.aspx?*
// @match              https://www.tongli.com.tw/NovelIndex/
// @match              https://www.tongli.com.tw/NovelDetail.aspx
// @match              https://www.tongli.com.tw/NovelDetail.aspx?*
// @run-at             document-end
// @grant              none
// @require            https://update.greasyfork.icu/scripts/483122/1304475/style-shims.js
// @require            https://update.greasyfork.icu/scripts/482311/1297431/queue.js
// @supportURL         http://greasyfork.icu/scripts/482312/feedback
// ==/UserScript==

GM.addStyle(`
    .b_package.nsfw img, .owl-item.nsfw > .item img, .comicBox li.nsfw img, .sdBook :is(.hot, .tabbook).nsfw input
    {
        filter: blur(7.5px);
        transition: 0.3s;
    }

    .b_package.nsfw:hover img, .b_package.nsfw:focus-within img,
    .owl-item.nsfw > .item:hover img, .owl-item.nsfw > .item:focus-within img,
    .comicBox li.nsfw:hover img, .comicBox li.nsfw:focus-within img,
    .sdBook :is(.hot, .tabbook).nsfw:hover input, .sdBook :is(.hot, .tabbook).nsfw:focus-within input
    {
        filter: blur(0px);
    }
`);

async function isNsfw(url)
{
    try
    {
        const response = await fetch(url);
        if (response.status === 200)
        {
            const html = await response.text();
            const parser = new DOMParser();
            const page = parser.parseFromString(html, "text/html");

            if (page.getElementById("ContentPlaceHolder1_GradeTxt")?.innerText === "限制級") { return true; }
        }
    }
    catch (e)
    {
        console.error(e);
    }

    return false;
}

const queue = new Queue({ autostart: true, concurrency: 20 });

const products = document.querySelectorAll(".b_package, .owl-item, .comicBox li");
for (const product of products)
{
    queue.push(async () =>
    {
        if (await isNsfw(product.querySelector("a").href))
        {
            product.classList.add("nsfw");
        }
    });
}

if (location.pathname.toLowerCase() === "/search3.aspx")
{
    const sandbox = document.createElement("iframe");
    sandbox.style = "display: none;"
    document.body.appendChild(sandbox);

    sandbox.contentWindow.WebForm_PostBackOptions = window.WebForm_PostBackOptions;
    sandbox.contentWindow.WebForm_DoPostBackWithOptions = (options) => (new URL(options.actionUrl, location).href);

    const products = document.querySelectorAll(".sdBook :is(.hot, .tabbook)");
    for (const product of products)
    {
        const url = sandbox.contentWindow.eval(product.querySelector("input").getAttribute("onclick"));

        queue.push(async () =>
        {
            if (await isNsfw(url))
            {
                product.classList.add("nsfw");
            }
        });
    }

    sandbox.remove();
}