Greasy Fork

Greasy Fork is available in English.

Masiro: Blurs NSFW Covers

Blurs the covers of NSFW novels on Masiro.

当前为 2023-12-03 提交的版本,查看 最新版本

// ==UserScript==
// @name               Masiro: Blurs NSFW Covers
// @name:zh-TW         真白萌:模糊 R17 封面
// @description        Blurs the covers of NSFW novels on Masiro.
// @description:zh-TW  模糊真白萌 R17 小說的封面。
// @icon               https://icons.duckduckgo.com/ip3/masiro.me.ico
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.0.1
// @license            MIT
// @match              https://masiro.me/admin
// @match              https://masiro.me/admin/
// @match              https://masiro.me/admin/novels
// @match              https://masiro.me/admin/novelIndex
// @run-at             document-idle
// @grant              GM.addStyle
// @supportURL         http://greasyfork.icu/scripts/471783/feedback
// ==/UserScript==

GM.addStyle(`
    .updateCards > a.nsfw .updateImg, .layui-card.nsfw .n-img
    {
        filter: blur(7.5px);
        transition: 0.3s;
    }

    .updateCards > a.nsfw:hover .updateImg, .updateCards > a.nsfw:active .updateImg,
    .layui-card.nsfw:hover .n-img, .card.nsfw:active .n-img
    {
        filter: blur(0px);
    }
`);

const pathname = location.pathname;
if ((pathname === "/admin") || (pathname === "/admin/"))
{
    const observer = new MutationObserver((records) =>
    {
        for (const record of records)
        {
            if (record.target.classList.contains("updateCards"))
            {
                for (const node of record.addedNodes)
                {
                    queueMicrotask(async () =>
                    {
                        if (await isNsfw(node.href))
                        {
                            node.classList.add("nsfw");
                        }
                    });
                }
            }
        }
    });

    observer.observe(document.querySelector(".fl"), { subtree: true, childList: true });

    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");

                const tags = Array.prototype.map.call(page.querySelectorAll(".tags .label"), (element) => element.innerText);
                if (tags.includes("R17")) { return true; }
            }
        }
        catch (e)
        {
            console.error(e);
        }

        return false;
    }
}
else
{
    const observer = new MutationObserver((records) =>
    {
        for (const record of records)
        {
            for (const node of record.addedNodes)
            {
                if ((node instanceof HTMLElement) && node.classList.contains("layui-card"))
                {
                    const tags = Array.prototype.map.call(node.querySelectorAll(".tags > .tag"), (element) => element.innerText);
                    if (tags.includes("R17"))
                    {
                        node.classList.add("nsfw");
                    }
                }
            }
        }
    });

    observer.observe(document.querySelector(".n-leg"), { childList: true });
}