ZhChat增强脚本

增强功能:鼠标中键oldnick(已消抖)、自定义邀请、过滤rule

目前為 2023-03-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ZhChat增强脚本
// @namespace    http://tampermonkey.net/
// @version      2.5.7
// @description  增强功能:鼠标中键oldnick(已消抖)、自定义邀请、过滤rule
// @author       UbisoComes (GreenDebug)
// @match        https://chat.zhangsoft.cf/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zhangsoft.cf
// @license      MIT
// @run-at       document-end
// @grant none
// ==/UserScript==

(function () {

    const local = {
        set: (key, value) => localStorage.setItem(key, value),
        remove: (key) => localStorage.removeItem(key),
        get: (key) => localStorage.getItem(key),
        exist: (key) => localStorage.getItem(key) != undefined,

    };

    const dev = window.console;
    window.dev = dev;
    const doc = window.document;
    const $_ = (q) => doc.querySelectorAll(q);
    const $ = (d) => doc.querySelector(d);
    var is_oldnick_ing = false;
    const SideBarUI = {

        add: (element) => {
            let side = $('#sidebar-content');
            side.insertBefore(element, side.children[1]);
        },
        remove: (filther) => {
            let side = $('#sidebar-content');
            for (let i in side.children) {
                let item = side.children[i];
                if (filther(item)) side.removeChild(item);
            }
        }
    };

    function nick_oldnick() {

        $('#sidebar-content').addEventListener('mousedown', (e) => {
            if (e.button === 1) { // 检测是否为鼠标中键触发的事件
                e.preventDefault();
            }
            [...$('#users').children].map(s => s.children[0]).forEach(q =>
                q.addEventListener('mousedown', (e) => {

                    if (e.button == 1 && !is_oldnick_ing) {
                        send({ cmd: 'oldnick', nick: q.textContent });
                        is_oldnick_ing = true;
                    }

                    e.preventDefault();
                }));
        });
    }
    function initUI() {
        nick_oldnick();

    }
    function init() {
        try {
            initUI();
        }
        catch { }


        setTimeout(() => {
            let _info = COMMANDS.info;
            COMMANDS.info = (h) => {
                e.nick='*';
                if (h.text.indexOf("曾用名") != -1) {
                    is_oldnick_ing = false;
                }
                 if (e.type=="invite") {
                     e.text = e.text.replace(/\\rule/g,"【rule】")
            pushMessage({nick: "!" , text: "发现inviteRule,已被替换!"});
                 }
            };

        }, 1000);
        setTimeout(() => {
            userInvite = function (nick) {
                var gotoChannel = prompt("设置一个去的频道(按取消随机)");
                if (gotoChannel.indexOf("\\rule") != -1)
                   return pushMessage({nick: "!" , text: "兄弟,听我句劝,做个好人"});

                send(gotoChannel ? { cmd: 'invite', nick: nick, to: gotoChannel } : { cmd: 'invite', nick: nick });

            }

        }, 1000);
    }

    init();
})();