您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
めぶきちゃんねるの投稿フォームをEnterキーで開き、Escapeキーで閉じます
// ==UserScript== // @name mebuki-post-keybind // @namespace https://mebuki.moe/ // @version 0.1.2 // @description めぶきちゃんねるの投稿フォームをEnterキーで開き、Escapeキーで閉じます // @author ame-chan // @match https://mebuki.moe/app* // @license MIT // @run-at document-idle // ==/UserScript== (async () => { 'use strict'; const handleEscape = (e) => { if (e.key === 'Escape') { const postFormWindowElm = document.querySelector('.compose-window:has(textarea)'); const postFormWindowCloseElm = postFormWindowElm?.querySelector('.absolute.top-1\\.5.right-1\\.5 > button'); if (postFormWindowCloseElm instanceof HTMLButtonElement) { e.preventDefault(); e.stopPropagation(); postFormWindowCloseElm.click(); } } }; const keydownHandler = (e) => { const postFormWindowElm = document.querySelector('.compose-window:has(textarea)'); const postFormOpenButtonElm = document.querySelector('main[data-slot="sidebar-inset"] > div.pb-safe > button'); const isFormVisible = postFormWindowElm instanceof HTMLElement; if (!(postFormOpenButtonElm instanceof HTMLButtonElement)) return; if (e.key === 'Enter' && !isFormVisible) { e.preventDefault(); e.stopPropagation(); postFormOpenButtonElm.click(); } }; document.addEventListener('keydown', keydownHandler, true); const observer = new MutationObserver(() => { const postFormWindowElm = document.querySelector('.compose-window:has(textarea)'); if (postFormWindowElm) { postFormWindowElm.addEventListener('keydown', handleEscape, true); } }); observer.observe(document.body, { childList: true, subtree: true, }); })();