Eternity Tower User Mute

User muting for Eternity Tower. Must refresh after altering list.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Eternity Tower User Mute
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  User muting for Eternity Tower. Must refresh after altering list.
// @author       Aes Sedai
// @match        http*://*.eternitytower.net/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.usermute = {};
    window.usermute.users = JSON.parse(localStorage.getItem('usermute_users')) || [];

    var muteInterval = setInterval(function() {
        if (document.querySelector("#navbarSupportedContent > form > ul") !== null) {
            var shopNav = document.querySelector("#navbarSupportedContent > form > ul");
            var muteButtonLi = document.createElement("li");
            muteButtonLi.className = "nav-item";
            var muteButton = document.createElement("a");
            muteButton.className = "nav-link";
            muteButton.href = "#";
            muteButton.id = "muteButton";
            muteButton.innerHTML = "Muted Users";
            muteButton.onclick = function() {
                var users = prompt("Please enter a lowercased, comma-separated list of users", window.usermute.users.join(','));
                if (users !== null) {
                    window.usermute.users = users.split(',');
                    console.log("usernames: ", window.usermute.users);
                }
            };
            muteButtonLi.appendChild(muteButton);
            shopNav.insertBefore(muteButtonLi, shopNav.childNodes[0]);
            clearInterval(muteInterval); // here muteInterval is undefined, but when we call this function it will be defined in this context
        }
    }, 100);

    Meteor.connection._stream.on('message', function(sMeteorRawData){
        try {
            var oMeteorData = JSON.parse(sMeteorRawData);
            if (oMeteorData.collection == "simpleChats") {
                if (window.usermute.users.indexOf(oMeteorData.fields.username) > -1) {
                    var interval = setInterval(function() {
                        if (document.getElementById(oMeteorData.id) !== null) {
                            var elem = document.getElementById(oMeteorData.id);
                            elem.setAttribute("style", "display:none;");
                            clearInterval(interval); // here interval is undefined, but when we call this function it will be defined in this context
                        }
                    }, 50);
                }
            }
        }
        catch (err) { }
    });

    window.onbeforeunload = function() {
        localStorage.setItem('usermute_users', JSON.stringify(window.usermute.users));
    };
})();