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

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

目前為 2024-03-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name         隱藏巴哈原、鐵看板內鬼資訊
// @namespace    http://wysalan.com/
// @version      0.9
// @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 indexGS = 1;
    let indexHSR = 12;

    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')[indexHSR].remove();
        }
        else if(locationChecker("Genshin", url))
        {
            let tab = document.querySelectorAll('.b-tags__item')[indexGS].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")
        {
            return (inPLFirstPage || inPLAnotherPages) && (inGenshinForum || inStarRailForum);
        }
        else if(checkType == "PostContent")
        {
            return inPostPage && (inGenshinForum || inStarRailForum);
        }
    }

    function locationChecker(GameName, url)
    {
        const inGenshinForum = url.includes("36730");
        const inStarRailForum = url.includes("72822");

        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>否則選擇「返回上一頁」離開或自行關閉此分頁。";
        }

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

        // 警告:按鈕
        if(!forceMode)
        {
            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(returnButton);
            contentDiv.appendChild(allowButton);
        }

        status = true;
    }
})();

QingJ © 2025

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