插件开发
0 篇文章
简洁版(不推荐,有风险)优点:代码简洁。缺点:要求用户至少安装一个插件。⚠️ 风险警告:当用户关闭第一个插件时,之前的绑定会失效。functioneventBusOn(eventName,callback){constplugin=window.siyuan.ws.app.plugins[0];if(!plugin){console.log('绑定事件'+eventName+'失败,请至少安装一个插件
/*通过给 ul 背景色添加固定宽度实现*//*背景线适配需配合下面的 js 代码实现*//*https://ld246.com/article/1724305128590#%E5%B7%A6%E4%BE%A7%E6%96%87%E6%A1%A3%E6%A0%91%E6%98%BE%E7%A4%BA%E5%B1%82%E7%BA%A7%E5%85%B3%E7%B3%BB%E8%83%8C%E6%99%AF%
方法一、通过数据库里的 html 代码获取//通过块 id 获取数据库 idasyncfunctiongetAvIdByAvBlockId(blockId){constav=awaitgetAvBySql(`SELECT*FROMblockswheretype='av'andid='${blockId}'`);if(av.length===0)returnerror("未找到数据库文档块,请检查数据库文档块 i
从当前脚本中提取 name和 version获取该脚本的远程地址(即 <scriptsrc="remote.js">的地址)从远程地址获取远程版本号(假设远程 JS 文件开头也有注释定义)比较本地版本和远程版本如果远程版本更新,就提示用户是否需要更新 ✅ 总结:不需要下载新版本,只做提示。当前使用的脚本是本地引入的(例如:<scriptsrc="/local/your-script.js">),但这个 js
//调用示例//observeElement('.tooltip.tooltip--memo:not(.fn__none)',({element,mutationsList,stop})=>{//console.log([element?.outerHTML,mutationsList,stop]);//});asyncfunctionobserveElement(selector,callback
showFileInFolderfunctionshowFileInFolder(filePath){require('electron').ipcRenderer.send("siyuan-open-folder",filePath);}运行本地命令 functionrunCmd(command,callback){const{exec}=require('child_process');exec(
/*options={...options,showAction?:boolean,//当点击确定后不想关闭对话框时,可设置为 options.disableClose=true;即可 confirmCallback?:(options?:IObject)=>void}*///创建基础对话框,createDialog 基础上增加 content 容器和确定与取消按钮//当点击确定后不想关闭对话框时,可设置为 o
functionselectText(targetText,container,parentElement){if(typeofparentElement==='string')parentElement=document.querySelector(parentElement);if(typeofcontainer==='string')container=(parentElement||docu
//当文本选择结束事件//onSelectionEnd((selection)=>{//console.log(selection);//});functiononSelectionEnd(callback){letisMouseupListenerActive=false;//标志变量,用于跟踪是否已经绑定了 mouseup 事件 constmouseupHandler=(event)=>{//获取当前
//当 toolbar 出现事件//onToolbarShow((selection,toolbar,protyle)=>{//console.log(selection,toolbar,protyle);//});functiononToolbarShow(callback){letisMouseupListenerActive=false;//标志变量,用于跟踪是否已经绑定了 mouseup 事件 con
注意这个是开始加载时,不是加载完成这种方式实现,如果是添加导航按钮等,不会出现闪烁,但如果是修改编辑器内容推荐 protyle 加载完成执行//监听 protyle 加载,注意这个是开始加载时,不是加载完成//调用示例 observeProtyleLoad((protyle)=>console.log(protyle))functionobserveProtyleLoad(callback,node){let
注意是页面加载完成后触发这种方式比较适合修改编辑器的内容时使用,如果新增导航按钮等,可能由于加载较慢出现闪烁,这种场景推荐使用 protyle 加载时执行//监听 protyle 加载完成,注意这个是开始加载完成时,不是加载时//调用示例 observeProtyleLoaded((protyle)=>console.log(protyle))functionobserveProtyleLoaded(call
functionsendTextToEditable(element,text){//聚焦到编辑器 element.focus();//插入文本 document.execCommand('insertText',false,text);//或直接操作 DOM(适用于简单场景)//element.textContent+=text;//触发 input 事件 constinputEvent=newEvent('
if(type==="undo"){protyle.undo.undo(protyle);return;}elseif(type==="redo"){protyle.undo.redo(protyle);return;}
seehttps://github.com/siyuan-note/siyuan/issues/14572#issuecomment-2795651330:not(:root):fullscreen::backdrop{background-color:var(--b3-theme-background);}
seehttps://ld246.com/article/1744145263614 获取文档 kramdown 全文 awaitfetchSyncPost('/api/block/getBlockKramdown',{id:'文档 id'})更新文档全文(有{:id=""}在 id 不会变)awaitfetchSyncPost('/api/block/updateBlock',{"dataType":"mark
//根据 paths 展开文件夹 functionexpandFolderByPaths(paths,box){//遍历 paths 并展开对应的文件夹 paths.forEach(asyncpath=>{//将路径按/分割,获取每个层级的 node-idconstparts=path.split('/');constfolderIds=parts.slice(1,-1);//最后一个是文件,不需要展开//逐层查
asyncfunctiongetFile(path){returnfetch("/api/file/getFile",{method:"POST",headers:{"Content-Type":"application/json",},body:JSON.stringify({path,}),}).then((response)=>{if(response.ok){//返回 Blob 对象而不是文本 r
(siyuan?.mobile?.docks?.file||siyuan?.mobile?.files||siyuan.layout.leftDock.data.file).selectItem(notebookId,path)比如(siyuan?.mobile?.docks?.file||siyuan?.mobile?.files||siyuan.layout.leftDock.data.file
window.siyuan.menus.menu.remove();document.body.click();constmenuItems=document.querySelector('#commonMenu.b3-menu__items');if(menuItems)menuItems.innerHTML='';
记录精彩的程序人生
开始使用
分类
标签