-
思源笔记
23020 引用 • 92599 回帖
思源笔记是一款隐私优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。
融合块、大纲和双向链接,重构你的思维。
-
Q&A
8449 引用 • 38491 回帖 • 155 关注
提问之前请先看《提问的智慧》,好的问题比好的答案更有价值。
相关帖子
-
wilsons •付费者 捐赠者
默认全屏可以实现,但思源的全屏(alt+y)是基于文档的,即如果你没打开任何文档是无法全屏的。
这一点你测试下就知道了,比如把所有文档关闭,然后按 alt+y 是不会全屏的。
所以,要想软件打开时全屏,你关闭软件的时候文档不能全关闭,至少留一个文档不关。
否则,打开软件时全屏失效。
如果这样的逻辑可以满足你的需求,那么下面的代码即可实现,打开软件时自动全屏。
放到 js 代码片段即可。
(async ()=>{ await whenElementExist(async ()=>{ const currentTab = document.querySelector('.layout__center li[data-type="tab-header"].item--focus'); if(!currentTab) return false; const dataId = currentTab.dataset.id; if(!dataId) return false; const currentContent = document.querySelector('.layout__center .fn__flex-1.protyle[data-id="'+dataId+'"]'); if(!currentContent) return false; await sleep(100); currentContent.classList.add("fullscreen"); window.siyuan.editorIsFullscreen = true; return true; }); // 延迟执行 function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } // 等待元素渲染完成后执行 function whenElementExist(selector) { return new Promise(resolve => { const checkForElement = () => { let element = null; if (typeof selector === 'function') { element = selector(); } else { element = document.querySelector(selector); } if (element) { resolve(element); } else { requestAnimationFrame(checkForElement); } }; checkForElement(); }); } })();
-
/** 获取配置里面的快捷键, 并触发 * */ function dispatchKeyEvent(functionName) { let keyInit = parseHotKeyStr(window.top.siyuan.config.keymap.general[functionName].custom); keyInit["bubbles"] = true; let keydownEvent = new KeyboardEvent('keydown', keyInit); document.getElementsByTagName("body")[0].dispatchEvent(keydownEvent); let keyUpEvent = new KeyboardEvent('keyup', keyInit); document.getElementsByTagName("body")[0].dispatchEvent(keyUpEvent); } /** * * @param {*} hotkeyStr 思源hotkey格式 Refer: https://github.com/siyuan-note/siyuan/blob/d0f011b1a5b12e5546421f8bd442606bf0b5ad86/app/src/protyle/util/hotKey.ts#L4 * @returns KeyboardEventInit Refer: https://developer.mozilla.org/zh-CN/docs/Web/API/KeyboardEvent/KeyboardEvent */ function parseHotKeyStr(hotkeyStr) { let result = { ctrlKey: false, altKey: false, metaKey: false, shiftKey: false, key: 'A', keyCode: 0 } if (hotkeyStr == "" || hotkeyStr == undefined || hotkeyStr == null) { console.error("解析快捷键设置失败", hotkeyStr); throw new Error("解析快捷键设置失败"); } let onlyKey = hotkeyStr; if (hotkeyStr.indexOf("⌘") != -1) { result.ctrlKey = true; onlyKey = onlyKey.replace("⌘", ""); } if (hotkeyStr.indexOf("⌥") != -1) { result.altKey = true; onlyKey = onlyKey.replace("⌥", ""); } if (hotkeyStr.indexOf("⇧") != -1) { result.shiftKey = true; onlyKey = onlyKey.replace("⇧", ""); } // 未处理 windows btn (MetaKey) result.key = onlyKey; // 在https://github.com/siyuan-note/siyuan/commit/70acd57c4b4701b973a8ca93fadf6c003b24c789#diff-558f9f531a326d2fd53151e3fc250ac4bd545452ba782b0c7c18765a37a4e2cc // 更改中,思源改为使用keyCode判断快捷键按下事件,这里进行了对应的转换 // 另请参考该提交中涉及的文件 result.keyCode = keyCodeList[result.key]; console.assert(result.keyCode != undefined, `keyCode转换错误,key为${result.key}`); switch (result.key) { case "→": { result.key = "ArrowRight"; break; } case "←": { result.key = "ArrowLeft"; break; } case "↑": { result.key = "ArrowUp"; break; } case "↓": { result.key = "ArrowDown"; break; } case "⌦": { result.key = "Delete"; break; } case "⌫": { result.key = "Backspace"; break; } case "↩": { result.key = "Enter"; break; } } return result; } if (g_addSnippets) addSnippets(); const keyCodeList = { "⌫": 8, "⇥": 9, "↩": 13, "⇧": 16, "⌘": 91, "⌥": 18, "Pause": 19, "CapsLock": 20, "Escape": 27, " ": 32, "PageUp": 33, "PageDown": 34, "End": 35, "Home": 36, "←": 37, "↑": 38, "→": 39, "↓": 40, "PrintScreen": 44, "Insert": 45, "⌦": 46, "0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "A": 65, "B": 66, "C": 67, "D": 68, "E": 69, "F": 70, "G": 71, "H": 72, "I": 73, "J": 74, "K": 75, "L": 76, "M": 77, "N": 78, "O": 79, "P": 80, "Q": 81, "R": 82, "S": 83, "T": 84, "U": 85, "V": 86, "W": 87, "X": 88, "Y": 89, "Z": 90, "ContextMenu": 93, "MyComputer": 182, "MyCalculator": 183, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "`": 192, "[": 219, "\\": 220, "]": 221, "'": 222, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "F1": 112, "F2": 113, "F3": 114, "F4": 115, "F5": 116, "F6": 117, "F7": 118, "F8": 119, "F9": 120, "F10": 121, "F11": 122, "F12": 123, "NumLock": 144, "ScrollLock": 145 };
1 回复1 引用 - 其他回帖
-
默认全屏可以实现,但思源的全屏(alt+y)是基于文档的,即如果你没打开任何文档是无法全屏的。
这一点你测试下就知道了,比如把所有文档关闭,然后按 alt+y 是不会全屏的。
所以,要想软件打开时全屏,你关闭软件的时候文档不能全关闭,至少留一个文档不关。
否则,打开软件时全屏失效。
如果这样的逻辑可以满足你的需求,那么下面的代码即可实现,打开软件时自动全屏。
放到 js 代码片段即可。
(async ()=>{ await whenElementExist(async ()=>{ const currentTab = document.querySelector('.layout__center li[data-type="tab-header"].item--focus'); if(!currentTab) return false; const dataId = currentTab.dataset.id; if(!dataId) return false; const currentContent = document.querySelector('.layout__center .fn__flex-1.protyle[data-id="'+dataId+'"]'); if(!currentContent) return false; await sleep(100); currentContent.classList.add("fullscreen"); window.siyuan.editorIsFullscreen = true; return true; }); // 延迟执行 function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } // 等待元素渲染完成后执行 function whenElementExist(selector) { return new Promise(resolve => { const checkForElement = () => { let element = null; if (typeof selector === 'function') { element = selector(); } else { element = document.querySelector(selector); } if (element) { resolve(element); } else { requestAnimationFrame(checkForElement); } }; checkForElement(); }); } })();
1 回复1 操作wilsons 在 2024-08-26 18:50:19 更新了该回帖 -
- 查看全部回帖