Bilibili直播弹幕发送失败显示提示

当弹幕发送失败(如被拦截)时在弹幕栏显示提示及原因

// ==UserScript==
// @name         Bilibili直播弹幕发送失败显示提示
// @namespace    https://gf.qytechs.cn/users/236434
// @version      0.0.1
// @description  当弹幕发送失败(如被拦截)时在弹幕栏显示提示及原因
// @author       astrile
// @match        https://live.bilibili.com/*
// @icon         https://www.bilibili.com/favicon.ico
// @license      MIT
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const checkCommentRsp = async (requestData, response) => {
        const rsp = await response.clone().json();
        if (rsp.code === 0 && rsp.msg) {
            rsp.msg = {
                'f': "弹幕含全局屏蔽词",
                'fire': "弹幕含全局屏蔽词",
                'k': "弹幕含房间屏蔽词",
                "max limit exceeded": "当前房间弹幕流量过大",
            }[rsp.msg] || rsp.msg;
            const e = document.createElement("div");
            e.className = "chat-item convention-msg border-box";
            e.innerText = '弹幕发送失败:' + rsp.msg;
            document.querySelector('#chat-items').appendChild(e);
        }
    }

    const origFetch = window.fetch;
    window.fetch = async function() {
        const url = arguments[0];
        if (url.match('api.live.bilibili.com/msg/send')) {
            const data = arguments[1].data;
            const response = await origFetch.apply(this, arguments);
            checkCommentRsp(data, response.clone());
            return response;
        } else {
            return origFetch.apply(this, arguments);
        }
    }

})();

QingJ © 2025

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