隱藏巴哈原、鐵看板內鬼資訊

以眼不見為淨的方式隱藏巴哈姆特《原神》和《崩壞:星穹鐵道》看板內的內鬼相關文章

当前为 2024-05-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         隱藏巴哈原、鐵看板內鬼資訊
// @namespace    http://wysalan.com/
// @version      0.9.5
// @description  以眼不見為淨的方式隱藏巴哈姆特《原神》和《崩壞:星穹鐵道》看板內的內鬼相關文章
// @author       Wysalan
// @match        https://forum.gamer.com.tw/B.php?bsn=36730*
// @match        https://forum.gamer.com.tw/B.php?bsn=72822*
// @match        https://forum.gamer.com.tw/C.php?bsn=36730*
// @match        https://forum.gamer.com.tw/C.php?bsn=72822*
// @match        https://forum.gamer.com.tw/B.php?page=*
// @match        https://forum.gamer.com.tw/C.php?page=*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-body
// @license      MIT
// ==/UserScript==

(function() {
    "use strict";
    var status = false;
    let url = document.URL;

    // --------------------------
    // --------強制模式-----------
    // --------------------------
    var forceMode = false;
    // --------------------------
    // ------內鬼分類編號---------
    // (編號說明:從零開始,由上至下、從左到右)
    // --------------------------
    let subForumIndex_Genshin = 1;
    let subForumIndex_StarRail = 12;

    let forumID_Genshin = "36730";
    let forumID_StarRail = "72822";

    if(!forceMode)
    {
        waitForElementObserved('BH-menuE', createIndicator);
    }
    if(forceMode)
    {
        waitForElementObserved('b-tags', hideCategoryTab);
    }
    waitForElementObserved('b-list', removePost);
    hidePostContent();

    // 等待 elementClassName 元素出現後立刻執行 functionName 函數
    function waitForElementObserved(elementClassName, functionName)
    {
        let callback = function(mutationsList) {
            if (document.getElementsByClassName(elementClassName).length > 0) {
                functionName();
                this.disconnect();
            }
        };
        let observer = new MutationObserver(callback);
        let targetNode = document.documentElement;
        let config = { attributes: true, childList: true, subtree: true };
        observer.observe(targetNode, config);
    }

    // 建立指示器
    function createIndicator()
    {
        const menuBar = document.querySelector('.BH-menuE');
        const indicator = document.createElement('li');
        const indicatorContent = document.createElement('a');
        indicatorContent.className = "indicator";
        indicatorContent.style.fontWeight = "bold";
        if(status)
        {
            indicatorContent.innerHTML = "防內鬼已啟用";
            indicatorContent.onclick = () => hidePostSwitchToggle();
        } else {
            indicatorContent.innerHTML = "防內鬼已啟用(生效範圍外)";
        }
        indicator.appendChild(indicatorContent);
        menuBar.appendChild(indicator);
    }

    // 隱藏指示器
    function hidePostSwitchToggle()
    {
        const postListArea = document.querySelector('.b-list');
        const indicator = document.querySelector('.indicator');
        if(status)
        {
            postListArea.style.display = postListArea.style.display === "none" ? "block" : "none";
            indicator.innerHTML = indicator.innerHTML === "防內鬼已啟用" ? "防內鬼暫時停用" : "防內鬼已啟用";
        }
    }

    // 移除文章列表內所有文章
    function removePost()
    {
        if(urlChecker("PostList", url))
        {
            const postListArea = document.querySelector('.b-list');
            postListArea.style.display = "none";
            status = true;
        }
    }

    // 隱藏文章內容
    function hidePostContent()
    {
        if (urlChecker("PostContent", url))
        {
            status = true;
            warnWindowGenerate();
        }
    }

    // 隱藏子板入口
    function hideCategoryTab()
    {
        if(locationChecker("StarRail", url))
        {
            let tab = document.querySelectorAll('.b-tags__item')[subForumIndex_StarRail].remove();
        }
        else if(locationChecker("Genshin", url))
        {
            let tab = document.querySelectorAll('.b-tags__item')[subForumIndex_Genshin].remove();
        }
    }

    // 網址檢查(偵測是否位於文章列表或文章內)
    function urlChecker(checkType, url)
    {
        const inGenshinForum = url.includes("&subbsn=10");
        const inStarRailForum = url.includes("&subbsn=8");
        const inPLFirstPage = url.includes("B.php?bsn=");
        const inPLAnotherPages = url.includes("B.php?page=");
        const inPostPage = url.includes("C");

        if(checkType == "PostList")
        {
            if(locationChecker("Genshin", url))
            {
                return (inPLFirstPage || inPLAnotherPages) && inGenshinForum;
            }
            else
            {
                return (inPLFirstPage || inPLAnotherPages) && inStarRailForum;
            }

        }
        else if(checkType == "PostContent")
        {
            if(locationChecker("Genshin", url))
            {
                return inPostPage && inGenshinForum;
            }
            else
            {
                return inPostPage && inStarRailForum;
            }
        }
    }

    // 網址檢查(偵測是否位於原神或崩鐵看板)
    function locationChecker(GameName, url)
    {
        const inGenshinForum = url.includes(forumID_Genshin);
        const inStarRailForum = url.includes(forumID_StarRail);

        if(GameName == "Genshin")
        {
            return inGenshinForum;
        }
        else if(GameName == "StarRail")
        {
            return inStarRailForum;
        }
    }

    // 建立警告頁面
    function warnWindowGenerate()
    {
        // 警告:底部背景
        const div = document.createElement('div');
        div.className = "leakContentAlert";
        div.style.position = "fixed";
        div.style.top = 0;
        div.style.right = 0;
        div.style.width = "100%";
        div.style.height = "100%";
        div.style.zIndex = 9999;
        div.style.backgroundColor = "#ffffff";
        document.body.appendChild(div);

        // 警告:內容區域
        const contentDiv = document.createElement('div');
        contentDiv.style.position = "absolute";
        contentDiv.style.top = "50%";
        contentDiv.style.left = "50%";
        contentDiv.style.transform = "translate(-50%, -50%)";
        contentDiv.style.fontSize = "24px";
        div.appendChild(contentDiv);

        // 警告:文字區域
        const contentText = document.createElement("p");
        contentText.style.lineHeight = "1.5";
        if(forceMode)
        {
            contentText.innerHTML = "此文章含有<b>內鬼</b>資訊<br>選擇「返回上一頁」離開或自行關閉此分頁。";
        } else {
            contentText.innerHTML = "你即將要瀏覽<b>內鬼</b>分類裡的文章<br>如要繼續請選擇「仍要閱讀」<br>否則選擇「返回上一頁」離開或自行關閉此分頁。";
        }

        const returnButton = document.createElement("button");
        const allowButton = document.createElement("button");

        // Style for returnButton
        returnButton.style.width = "100px";
        returnButton.style.height = "40px";
        returnButton.style.margin = "10px";
        returnButton.style.backgroundColor = "#04AA6D";
        returnButton.textContent = "返回上一頁";

        // Evnet for returnButton
        returnButton.addEventListener("click", function() {
            window.history.back();
        });

        // Style for allowButton
        allowButton.style.width = "100px";
        allowButton.style.height = "40px";
        allowButton.style.margin = "10px";
        allowButton.style.backgroundColor = "#ff8787";
        allowButton.textContent = "仍要閱讀";

        // Evnet for allowButton
        allowButton.addEventListener("click", function() {
            let warnWindow = document.querySelector('.leakContentAlert');
            if(warnWindow)
            {
                if(window.confirm("確定要瀏覽嗎?這次允許之後還會出現提示。"))
                {
                    warnWindow.style.display = "none";
                }
            }
        });

        // 附加在 contentDiv 底下
        contentDiv.appendChild(contentText);
        contentDiv.appendChild(returnButton);

        // 警告:按鈕
        if(!forceMode)
        {
            contentDiv.appendChild(allowButton);
        }

        status = true;
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址