Kageshi Mode Stumblechat

Automatically add new users to localStorage HideList

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Kageshi Mode Stumblechat
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically add new users to localStorage HideList
// @match        https://stumblechat.com/room/*
// @author       MeKLiN
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
        'use strict';

        // Helper: Load HideList from localStorage or create a new one
        function loadHideList() {
                const list = localStorage.getItem('HideList');
                return list ? JSON.parse(list) : [];
        }

        // Helper: Save HideList back to localStorage
        function saveHideList(list) {
                localStorage.setItem('HideList', JSON.stringify(list));
        }

        // Add username if not already in HideList
        function addToHideList(username) {
                const hideList = loadHideList();
                if (!hideList.includes(username)) {
                        hideList.push(username);
                        saveHideList(hideList);
                        console.log(`[HideList] Added: ${username}`);
                }
        }

        // Extract usernames from all <li class="bar"> elements
        function scanAndUpdateUserList() {
                document.querySelectorAll('ul.list li.bar').forEach(li => {
                        const usernameSpan = li.querySelector('.username');
                        if (usernameSpan) {
                                const username = usernameSpan.textContent.trim();
                                if (username) addToHideList(username);
                        }
                });
        }

        // Start observing when ul.list is available
        function observeUserList() {
                const userList = document.querySelector('ul.list');
                if (!userList) {
                        setTimeout(observeUserList, 500); // Wait and retry
                        return;
                }

                // Initial scan
                scanAndUpdateUserList();

                const observer = new MutationObserver(() => {
                        scanAndUpdateUserList();
                });

                observer.observe(userList, { childList: true, subtree: true });
                console.log('[HideList] MutationObserver started on user list.');
        }

        // Start script
        observeUserList();
})();