[Brick-Kill] Ban Detector

Automatically runs an action when banned.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// discord.gg/JjszyaD63A

// ==UserScript==
// @name         [Brick-Kill] Ban Detector
// @version      2
// @description  Automatically runs an action when banned.
// @match        *://www.brick-hill.com/*
// @icon         https://www.brick-hill.com/favicon.ico
// @license      MIT
// @namespace    bhbandetector
// @run-at       document-start
// @grant        GM_notification
// ==/UserScript==

(function() {
    'use strict';

    /*-    SETTINGS    -*/

    const action = "logout"; // What to do when you get banned. Use "logout" or "refresh".

    const Check_interval = 60; // How many seconds you want to check. Recommended to do 60 seconds, or 20 seconds if active on the website.

    /*-                -*/

    const banCheckUrl = 'https://www.brick-hill.com/banned';

    async function logoutAndRedirect() {
        try {
            const tokenInput = document.querySelector('input[name="_token"]');
            if (!tokenInput) throw new Error('Token input not found');

            const formData = new URLSearchParams({ '_token': tokenInput.value });

            const response = await fetch('https://www.brick-hill.com/logout', {
                method: 'POST',
                credentials: 'include',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                body: formData
            });

            if (response.ok) {
                console.log('Successfully logged out');
                window.location.href = 'https://www.brick-hill.com/login';
            } else {
                throw new Error('Failed to log out');
            }
        } catch (error) {
            console.error('Error during logout:', error);
        }
    }

    function refreshPage() {
        if (!window.location.href.includes(banCheckUrl)) {
            console.log('Refreshing page...');
            window.location.reload();
        } else {
            console.log('Ban page detected. Not refreshing.');
        }
    }

    function showNotification() {
        GM_notification({
            title: 'Ban Detected',
            text: 'You have been banned from Brick Hill!',
            timeout: 5000,
            onclick: () => window.focus(),
        });
    }

    async function checkBanStatus() {
        try {
            const response = await fetch(banCheckUrl, { method: 'GET', credentials: 'include', redirect: 'manual' });

            if (response.status === 302 || response.redirected) {
                console.log('Redirect detected (potential ban). Performing action:', action);
                showNotification();
                if (action === "logout") {
                    logoutAndRedirect();
                } else if (action === "refresh") {
                    refreshPage();
                }
            } else if (response.status === 200) {
                console.log('Ban detected. Performing action:', action);
                showNotification();
                if (action === "logout") {
                    logoutAndRedirect();
                } else if (action === "refresh") {
                    refreshPage();
                }
            }
        } catch (error) {
            console.error('Error checking ban status:', error);
        }
    }

    function startBanCheck() {
        setInterval(checkBanStatus, Check_interval * 1000);
    }

    window.addEventListener('load', startBanCheck);
})();