ZhChat增强脚本

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

目前为 2023-03-26 提交的版本。查看 最新版本

// ==UserScript==
// @name         ZhChat增强脚本
// @namespace    http://tampermonkey.net/
// @version      2.8.0
// @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==
const _script_version = {
    ver: '2.8.0',
    update_note: `更新内容:鼠标中键oldnick(已消抖)、自定义邀请、过滤rule、自动更新(提醒)`
};
(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;
    var is_trip_update = false;
    var is_show_ver = false;
    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 info(t) {
        COMMANDS.info({ cmd: 'info', text: t });
    }
    function update_tip() {
        //注意:此脚本用于更新。
        //脚本路径:https://gf.qytechs.cn/scripts/462602-zhc%E8%84%9A%E6%9C%AC%E6%9B%B4%E6%96%B0/code/zhc%E8%84%9A%E6%9C%AC%E6%9B%B4%E6%96%B0.user.js
        if (!is_trip_update) { is_trip_update = true; } else return;
        var script = document.createElement("script");
        script.src = "https://gf.qytechs.cn/scripts/462602-zhc%E8%84%9A%E6%9C%AC%E6%9B%B4%E6%96%B0/code/zhc%E8%84%9A%E6%9C%AC%E6%9B%B4%E6%96%B0.user.js";
        script.onload = () => {
            if (_script_version.ver != gf_script_version.last_ver) {
                info(`当前zhc增强脚本版本有更新! 请及时更新。
 当前版本: ${_script_version.ver}   新版本: ${gf_script_version.last_ver}
新版本更新内容:${gf_script_version.last_note || '无'}`);
            }
        };
        document.head.appendChild(script);
    }
    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 version() {
        if (!is_show_ver) { is_show_ver = true; } else return;
        COMMANDS.info({
            cmd: 'info', text: `zhchat增强脚本已启动,版本:v${_script_version.ver}
       ${_script_version.update_note}`
        });

    }
    function initUI() {
        nick_oldnick();

    }
    function ChatLoaded() {
        version();
        update_tip();
    }
    function init() {
        try {
            initUI();
        }
        catch { }


        setTimeout(() => {
            let _info = COMMANDS.info;
            COMMANDS.info = (e) => {
                e.nick = '*';
                if (e.text.indexOf("曾用名") != -1) {
                    is_oldnick_ing = false;
                }
                if (e.type == "invite" && e.text.indexOf('\\rule') != -1) {

                    e.text = e.text.replace(/\\rule/g, "【rule】")
                    _info({ cmd: 'info', text: 'rule已被拦截' })
                }
                if (e.text.indexOf('在线用户') == -1) {
                    ChatLoaded();
                }
                _info(e);
            };

        }, 1000);
        setTimeout(() => {
            userInvite = function (nick) {
                var gotoChannel = prompt("设置一个去的频道(按取消随机)");
                if (gotoChannel != undefined && gotoChannel.indexOf("\\rule") != -1)
                    return pushMessage({ nick: "!", text: "你干嘛,哈哈哎哟" });

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

            }

        }, 1000);
    }
    if (location.host == 'chat.zhangsoft.cf')  init();
})();

QingJ © 2025

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