// ==UserScript== // @name b站直播聊天室去除字数限制 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 并不能去除,只是分开发送了 // @author Pronax // @include /https://live.bilibili.com\/\d+/ // @icon http://bilibili.com/favicon.ico // @grant GM_addStyle // @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js // @downloadURL none // ==/UserScript== (function () { 'use strict'; var jct = document.cookie.match(/bili_jct=(\w*); /) && document.cookie.match(/bili_jct=(\w*); /)[1]; var roomId = location.href.match(/\/(\d+)/)[1]; var limit = 30; var toastCount = 0; var isProcessing = false; GM_addStyle(".medal-section{display:inline-block}.dialog-ctnr>.arrow{display:none}.chat-input-ctnr>div:first-of-type{width:100%}.chat-input-ctnr .input-limit-hint{bottom:0!important;right:53px!important}#chat-control-panel-vm{height:102px}.chat-history-panel{height:calc(100% - 128px - 102px)!important}#liveDanmuSendBtn{height:100%;min-width:50px;padding-top:5px;border-radius:0 3px 3px 0}.link-toast.error{left:40px;right:40px;white-space:normal;margin:auto;text-align:center;box-shadow:0 .2em .1em .1em rgb(255 100 100 / 20%)}#liveDanmuInputArea{padding:8px;overflow:auto}#liveDanmuInputArea::-webkit-scrollbar{width:6px;height:6px}#liveDanmuInputArea::-webkit-scrollbar-thumb{border-radius:6px;background-color:#aaa}.control-panel-icon-row>.icon-right-part{margin-right:6px}.chat-input-ctnr{margin-top:4px!important}.control-panel-icon-row>.medal-section>.medal-item-margin{margin:2px}"); // 默认css GM_addStyle(".control-panel-icon-row .medal-section .action-item.medal.wear-medal{width:54px;height:22px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFYAAAAyCAMAAADx7dyJAAAA51BMVEUAAACampqZmZmampqZmZmampqampqZmZmdnZ2oqKiamprU1NSZmZmZmZmZmZmvr6+ampqampqamprIyMiZmZmampqampqZmZmZmZmampqenp6cnJyfn5+ampqbm5uampqenp7Q0NDOzs6ampqamprPz8/Ozs6ampqbm5vMzMyZmZmZmZnNzc2bm5ubm5uZmZmampqcnJy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BPFk+XspmyV9I5sFa/NcN0NOzqR+sPk0d+dwBnZBnWg/08PWHdvotjFm6rnbLjPmB2kj9B/764Aczbluw9wja6l3XnTRqoy7mccT81mr2vIyllMZdDoG31Dgg6zTt38gpgIsf2GbZWw1EvhoOOXutrHGojycF3JnR6ETL2fyOq6Pyo6Fiq6LSr5hCt8GzOWgiKPnOFRA3kahCF+bmIxAI6tvoXNyhWPwC2G+C0Dalilesq2hRthiIVFqhMN1SkCvd0sCSK4rzKc+OIaDlAYbYv0tnstRiunhW+jd8K1sksS9VuNrsOcC6fVJypPDdW5KOkFe0zlefuaYWydoriTOW4MakdSvNIaZXrKvJQnilIq1yXhAlGW6E8sPOU2IKXjeL4w19GXEgqF0Zf/gAAAABJRU5ErkJggg==)}.control-panel-icon-row .medal-section .action-item.medal{background-size:cover;border:0}.control-panel-icon-row .medal-section .action-item{display:inline-block;margin:0 2px;font-size:12px;color:#fff;line-height:14px;text-align:center;border-radius:2px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}"); var itv = setInterval(() => { let text = $("textarea.chat-input"); if (text.length) { clearInterval(itv); $(".control-panel-icon-row").prepend($(".medal-section")); let tempText = text.clone().attr("id", "liveDanmuInputArea"); text.after(tempText).remove(); let sendBtn = $(".bottom-actions>.right-action").removeClass("p-absolute"); $(sendBtn).find("button").attr("id", "liveDanmuSendBtn"); $(".chat-input-ctnr").append(sendBtn.clone()); sendBtn.remove(); $("#liveDanmuSendBtn").click(async () => { let msg = $("#liveDanmuInputArea").val(); if ((!msg) || isProcessing) { return; } isProcessing = true; let page = 1; limit = 30; if (msg.length > 30) { // 自动平均每条弹幕的长度 while (msg.length / limit % 1 < 0.7 && msg.length / limit % 1 != 0) { limit--; } page = Math.ceil(msg.length / limit); console.log(`长度:${msg.length} 间隔:${limit} 分页:${page}`); } let count = 0; do { let str = msg.substr(0, limit); msg = msg.substr(limit); let result = await SpinLockMsg(str, count++ ? 500 : 0); $("#liveDanmuInputArea").val(msg); document.querySelector("#liveDanmuInputArea").oninput(); } while (msg.length > 0); isProcessing = false; }); document.querySelector('#liveDanmuInputArea').oninput = function () { let length = this.value.length; $(".input-limit-hint").text(length + "/30"); if (length > 30) { $(".input-limit-hint").css("color", "#23ade5"); } else { $(".input-limit-hint").css("color", ""); } }; document.querySelector('#liveDanmuInputArea').onkeydown = function (e) { if ((!e.shiftKey) && e.keyCode == 13) { e.returnValue = false; $("#liveDanmuSendBtn").click(); } }; } }, 100); async function SpinLockMsg(msg, timer) { return new Promise((resolve, reject) => { if (timer > 4000) { toast("重试次数过多,终止发送"); reject(); return; } setTimeout(async () => { resolve(await sendMsg(msg)); }, timer); }); } async function sendMsg(msg) { return new Promise((resolve, reject) => { $.ajax({ url: "https://api.live.bilibili.com/msg/send", type: "POST", timeout: 8000, data: { "bubble": 0, "msg": msg, "color": 16777215, "mode": 1, "fontsize": 25, "rnd": Math.floor(new Date() / 1000), "roomid": roomId, "csrf": jct, "csrf_token": jct }, xhrFields: { withCredentials: true //允许跨域带Cookie }, success: function (result) { if (result.code || result.msg != "") { toast(result.msg); reject(result); isProcessing = false; } else { resolve(true); } }, error: function (e) { console.log("发送弹幕出错:", e); toast(e); reject(e); isProcessing = false; } }); }); } function toast(msg, time = 2000, type = "error") { let id = Math.random() * 1000 >> 1; $(".chat-control-panel").append(``); setTimeout(() => { toastCount--; $(`.link-toast-${id}`).remove(); }, time); } })();