Boost CJK 输入法回车上屏英文内容却直接发送的解决方案

2026-04-11 10:401阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐
问题描述:

从私聊聊天优化建议继续讨论:

直接消息回车问题 - #7,来自 Haleclipse

// ==UserScript== // @name Discourse Chat IME Guard // @namespace https://linux.do/ // @version 0.5 // @description Block IME Enter & fix IME char-count for chat / DM / Boost // @match https://linux.do/* // @match https://*.discourse.org/* // @run-at document-idle // @inject-into content // @grant none // ==/UserScript== (() => { "use strict"; const TEXTAREA_SELECTORS = [ "textarea.chat-composer__input", "textarea.chat-composer-input", "textarea.d-chat-message-editor", ].join(","); const DIV_SELECTORS = [ "div.discourse-boosts__input", ].join(","); const protectTextarea = (ta) => { if (ta.dataset.imeGuard) return; ta.dataset.imeGuard = "true"; let composing = false; ta.addEventListener("compositionstart", () => (composing = true), true); ta.addEventListener("compositionend", () => queueMicrotask(() => (composing = false)), true ); ta.addEventListener("keydown", (e) => { if (e.key !== "Enter") return; if (e.ctrlKey || e.metaKey) return; if (e.isComposing || composing) e.stopImmediatePropagation(); }, true); }; const protectContentEditable = (div) => { if (div.dataset.imeGuard) return; div.dataset.imeGuard = "true"; let composing = false; div.addEventListener("compositionstart", () => { composing = true; }, true); div.addEventListener("compositionend", () => { queueMicrotask(() => { composing = false; div.dispatchEvent(new Event("input", { bubbles: true, composed: true })); // 兜底:Discourse 异步 DOM 更新后若焦点丢失,拉回并恢复光标到末尾 setTimeout(() => { if (document.activeElement !== div) { div.focus(); const range = document.createRange(); const sel = window.getSelection(); range.selectNodeContents(div); range.collapse(false); sel.removeAllRanges(); sel.addRange(range); } }, 0); }); }, true); // composition 期间屏蔽 input 事件,防止拼音字母被计入字数 div.addEventListener("input", (e) => { if (composing) { e.stopImmediatePropagation(); } }, true); // Enter 拦截:IME 组合中不触发提交 div.addEventListener("keydown", (e) => { if (e.key !== "Enter") return; if (e.ctrlKey || e.metaKey) return; if (e.isComposing || composing) { e.stopImmediatePropagation(); e.preventDefault(); } }, true); }; const scan = () => { document.querySelectorAll(TEXTAREA_SELECTORS).forEach(protectTextarea); document.querySelectorAll(DIV_SELECTORS).forEach(protectContentEditable); }; new MutationObserver(scan).observe(document.documentElement, { childList: true, subtree: true, }); scan(); })();

image1440×300 46.9 KB

直接 轻松 秒杀~

网友解答:
--【壹】--:

出了二十字限制,回帖都变少了

快做啊哈雷酱


--【贰】--:

你点进去看一下 旧帖子就知道是陈年老脚本哈哈
只不过聊天可能没多少人用
现在Boost了 顺手修补一下


--【叁】--:

这还能凭感觉的吗 修补代码都丢这了

很明显是 Discourse 自己代码的问题啊


--【肆】--:

哈雷佬,上线Boost之后特意去找的老帖吗。。


--【伍】--:

哈雷佬能不能再出个逆向的app,翻译成精太好用啦


--【陆】--:

这个我也遇到过,ClaudeCode说好像是 ime 接口的问题


--【柒】--:

必须得跟一个


--【捌】--:

这就是我所疑虑的事情啦~


调整帖子最小长度

挺好的取舍 但是存在一个问题就是

boost并不能将帖子触发 “顶帖”吧

那么如果是 有用的 但是很容易没回复的 高价值 内容
就会很容易消弭
这点如何考量呢


--【玖】--:

哈雷佬最近得闲了啊,开始修复陈年老 bug 了


--【拾】--:

快做呀哈雷

趁着人少跟一个

话说哈雷佬真勤劳啊


--【拾壹】--:

我只知道今天又完成任务了 1/1


--【拾贰】--:


--【拾叁】--:

我还在等始皇官方修复呢


--【拾肆】--:

感觉像是mac输入法的键盘事件拦截没有做好


--【拾伍】--:

最近在推别的 不过可能快了 我有新的想法了
image860×596 49.3 KB
image300×168 52.7 KB


--【拾陆】--:


--【拾柒】--:

哈雷佬出手了耶w!
没有你我可怎么办啊!


--【拾捌】--:


--【拾玖】--:

再次push哈雷酱的ccline 2.0

标签:软件开发
问题描述:

从私聊聊天优化建议继续讨论:

直接消息回车问题 - #7,来自 Haleclipse

// ==UserScript== // @name Discourse Chat IME Guard // @namespace https://linux.do/ // @version 0.5 // @description Block IME Enter & fix IME char-count for chat / DM / Boost // @match https://linux.do/* // @match https://*.discourse.org/* // @run-at document-idle // @inject-into content // @grant none // ==/UserScript== (() => { "use strict"; const TEXTAREA_SELECTORS = [ "textarea.chat-composer__input", "textarea.chat-composer-input", "textarea.d-chat-message-editor", ].join(","); const DIV_SELECTORS = [ "div.discourse-boosts__input", ].join(","); const protectTextarea = (ta) => { if (ta.dataset.imeGuard) return; ta.dataset.imeGuard = "true"; let composing = false; ta.addEventListener("compositionstart", () => (composing = true), true); ta.addEventListener("compositionend", () => queueMicrotask(() => (composing = false)), true ); ta.addEventListener("keydown", (e) => { if (e.key !== "Enter") return; if (e.ctrlKey || e.metaKey) return; if (e.isComposing || composing) e.stopImmediatePropagation(); }, true); }; const protectContentEditable = (div) => { if (div.dataset.imeGuard) return; div.dataset.imeGuard = "true"; let composing = false; div.addEventListener("compositionstart", () => { composing = true; }, true); div.addEventListener("compositionend", () => { queueMicrotask(() => { composing = false; div.dispatchEvent(new Event("input", { bubbles: true, composed: true })); // 兜底:Discourse 异步 DOM 更新后若焦点丢失,拉回并恢复光标到末尾 setTimeout(() => { if (document.activeElement !== div) { div.focus(); const range = document.createRange(); const sel = window.getSelection(); range.selectNodeContents(div); range.collapse(false); sel.removeAllRanges(); sel.addRange(range); } }, 0); }); }, true); // composition 期间屏蔽 input 事件,防止拼音字母被计入字数 div.addEventListener("input", (e) => { if (composing) { e.stopImmediatePropagation(); } }, true); // Enter 拦截:IME 组合中不触发提交 div.addEventListener("keydown", (e) => { if (e.key !== "Enter") return; if (e.ctrlKey || e.metaKey) return; if (e.isComposing || composing) { e.stopImmediatePropagation(); e.preventDefault(); } }, true); }; const scan = () => { document.querySelectorAll(TEXTAREA_SELECTORS).forEach(protectTextarea); document.querySelectorAll(DIV_SELECTORS).forEach(protectContentEditable); }; new MutationObserver(scan).observe(document.documentElement, { childList: true, subtree: true, }); scan(); })();

image1440×300 46.9 KB

直接 轻松 秒杀~

网友解答:
--【壹】--:

出了二十字限制,回帖都变少了

快做啊哈雷酱


--【贰】--:

你点进去看一下 旧帖子就知道是陈年老脚本哈哈
只不过聊天可能没多少人用
现在Boost了 顺手修补一下


--【叁】--:

这还能凭感觉的吗 修补代码都丢这了

很明显是 Discourse 自己代码的问题啊


--【肆】--:

哈雷佬,上线Boost之后特意去找的老帖吗。。


--【伍】--:

哈雷佬能不能再出个逆向的app,翻译成精太好用啦


--【陆】--:

这个我也遇到过,ClaudeCode说好像是 ime 接口的问题


--【柒】--:

必须得跟一个


--【捌】--:

这就是我所疑虑的事情啦~


调整帖子最小长度

挺好的取舍 但是存在一个问题就是

boost并不能将帖子触发 “顶帖”吧

那么如果是 有用的 但是很容易没回复的 高价值 内容
就会很容易消弭
这点如何考量呢


--【玖】--:

哈雷佬最近得闲了啊,开始修复陈年老 bug 了


--【拾】--:

快做呀哈雷

趁着人少跟一个

话说哈雷佬真勤劳啊


--【拾壹】--:

我只知道今天又完成任务了 1/1


--【拾贰】--:


--【拾叁】--:

我还在等始皇官方修复呢


--【拾肆】--:

感觉像是mac输入法的键盘事件拦截没有做好


--【拾伍】--:

最近在推别的 不过可能快了 我有新的想法了
image860×596 49.3 KB
image300×168 52.7 KB


--【拾陆】--:


--【拾柒】--:

哈雷佬出手了耶w!
没有你我可怎么办啊!


--【拾捌】--:


--【拾玖】--:

再次push哈雷酱的ccline 2.0

标签:软件开发