Zuoqiu-Yingyi / siyuan-theme-dark-plus

思源笔记的一款多功能双模式主题 | A multifunctional dual-mode theme of SiYuan Note.
GNU Affero General Public License v3.0
139 stars 14 forks source link

特性请求:如何在不知道“显示标记文本”按钮的状态下实现可靠的隐藏或显示 #78

Closed jabobian closed 2 years ago

jabobian commented 2 years ago

我用外部程序通过siyuan:// 访问思源的文档,同时在进入文档时,自动隐藏高亮文本,然后在点击某个按钮之后,显示答案,也就是显示高亮文本。由于现在只能通过发送快捷键Shift-Alt-E来切换状态,存在一定误操作的概率。所以想,能否设定新增两个快捷键,一个负责隐藏(例如 Shift-Alt-H),一个负责显示 (例如 Shift-Alt-S),这两个功能可以不要图标。原来那个toggle的保留,在工具栏上有图标。

对于config.js,不知道怎么修改,望指导。

Zuoqiu-Yingyi commented 2 years ago

这需要自定义文件 widgets/custom.js

  1. 更新 Dark+ 至 v1.2.0, 应该在今天内该版本会上传到集市
  2. 新建文件 data/widgets/custom.js
  3. 在上述文件中写入如下代码并保存
    
    import { globalEventHandler } from '/appearance/themes/Dark+/script/utils/listener.js';

export const config = { theme: { style: { mark: { toolbar: { id: 'toolbar-theme-style-mark', }, }, }, }, };

/ 显示 / globalEventHandler.addEventHandler( 'keyup', { CtrlCmd: false, WinCtrl: false, Shift: true, Alt: true, key: 'S', }, => { // console.log(); const button = document.getElementById(config.theme.style.mark.toolbar.id); if (!button.classList.contains('toolbaritem--active')) { button.click(); } }, ); / 隐藏 / globalEventHandler.addEventHandler( 'keyup', { CtrlCmd: false, WinCtrl: false, Shift: true, Alt: true, key: 'H', }, => { // console.log(); const button = document.getElementById(config.theme.style.mark.toolbar.id); if (button.classList.contains('toolbaritem--active')) { button.click(); } }, );

jabobian commented 2 years ago

感谢Yingyi,但是我这边怎么测试了没反应。添加 console.log, 能看到 KeyboardEvent,和button的classList是对的,能进入 if 的执行块,但是button.click() 似乎没有执行。

Zuoqiu-Yingyi commented 2 years ago

感谢Yingyi,但是我这边怎么测试了没反应。添加 console.log, 能看到 KeyboardEvent,和button的classList是对的,能进入 if 的执行块,但是button.click() 似乎没有执行。

更新到 v1.2.0 版本了没, 之前版本 custom.js 文件重复加载了两次, 所以 button.click() 也重复执行了两次, 导致状态没有发生改变

jabobian commented 2 years ago

更新到v1.2.0,

经你提醒,发现原来是我自己复制了的主题里面的theme.js里面没有按照最新的Dartk+/theme.js更新。注释掉里面的一行 window.theme.loadScript(window.theme.addURLParam("/widgets/custom.js")); 就好了。感谢啊