思源
0 篇文章
获取选中文本可以通过 JavaScript 的 window.getSelection()方法来实现。这个方法返回一个 Selection对象,它包含了当前文档中选定的文本信息。你可以从这个对象中获取选定的范围,并从中提取出选定的文本。下面是一个简单的示例,展示了如何获取用户选定的文本,并将其输出到控制台或页面上的某个元素中:HTML 示例代码 <!DOCTYPEhtml><htmllang="en"><h
要在 JavaScript 中对选中的文本添加颜色,可以通过监听用户的文本选择事件,然后修改选定文本所在的元素的样式来实现。这里有一个基本的示例,演示如何在用户选定文本后为其添加颜色。首先,我们需要监听 mouseup事件,因为这是用户完成文本选择的一个标志。然后,我们可以获取当前文档中的选定范围,并应用相应的样式。以下是一个简单的例子:<!DOCTYPEhtml><htmllang="en"><hea
又名获取鼠标所在元素 functiongetCursorElement(){constselection=window.getSelection();if(selection.rangeCount>0){constrange=selection.getRangeAt(0);//获取选择范围的起始位置所在的节点 conststartContainer=range.startContainer;//如果起始
获取当前文档对象//pcsiyuan.layout.centerLayout.children.map(item=>item.children.find(item=>item.headElement?.classList.contains('item--focus')&&(item.panelElement.closest('.layout__wnd--active')||item.panelEle
@mediascreenand(max-width:768px){#menuSafeQuit,#menuSafeQuitsvg{color:var(--b3-theme-error);}}
seehttps://ld246.com/article/1726473563881//!jsreturn(async()=>{///////主逻辑区/////////sql 查询 constsql=`selectmarkdownfromblockswheretype='p'andmarkdownlike'% 工具 %'`;constresult=awaitquery(sql);//无数据提示 if(res
functionshowMessage(message,timeout=6000,type="info",messageId){constmessagesElement=document.getElementById("message").firstElementChild;if(!messagesElement){alert(message);return;}constgenUUID=()=>([
constgenUUID=()=>([1e7].toString()+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(c)=>(parseInt(c,10)^(window.crypto.getRandomValues(newUint32Array(1))[0]&(15>>(parseInt(c,10)/4)))).toString(16));改成函数 function
constgenUUID=()=>([1e7].toString()+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(c)=>(parseInt(c,10)^(window.crypto.getRandomValues(newUint32Array(1))[0]&(15>>(parseInt(c,10)/4)))).toString(16));改成函数 function
(async()=>{observeEditorLoaded((editor)=>{console.log(editor,'editorloaded');});//监听编辑器被添加 letloading=false;functionobserveEditorLoaded(callback){//创建一个观察者实例并传入回调函数 constobserver=newMutationObserver((mut
严格意义上来说是块的序号.protyle-wysiwyg{counter-reset:line-number;/*初始化计数器*/}.protyle-wysiwyg>div{counter-increment:line-number;/*每个 div 递增计数器*/}.protyle-wysiwyg>div::before{content:counter(line-number)"";/*显示行号*/p
嵌入 SQL 查询自定义字段
方法 1 效果//!jsreturn(async()=>{constsql=`select*fromblockswheretype='d'limit2;`;constresult=awaitquery(sql);render(result);functionrender(result){lethtml='';result.forEach(item=>{html+=`<divclass="protyle-
查询不在数据库中的文档
seehttps://ld246.com/article/1725076848647效果代码//!js//seehttps://ld246.com/article/1725076848647return(async()=>{////////主逻辑区//////////////待查询的 SQL 语句 constsql=`select*fromblocks--仅筛选文档块 wheretype='d'--查询某
/**获取配置里面的快捷键,并触发**/functiondispatchKeyEvent(functionName){letkeyInit=parseHotKeyStr(window.top.siyuan.config.keymap.general[functionName].custom);keyInit["bubbles"]=true;letkeydownEvent=newKeyboardEve
//用户名和密码,必须 constusername="";constpassword="";//设置浏览器安装路径,必须,如果填空,则使用 puppeteer 模式而不是 puppeteer-core//Windows 用户可能是"C:\\ProgramFiles\\Google\\Chrome\\Application\\chrome.exe",注意这里的路径要用\转义 constchromePath="/A
//加载时是否自动定位当前文档 constautoFocusTreeOnload=true;//等待标签页容器渲染完成后开始监听 whenElementExist('.layout__center').then(asyncelement=>{//等待笔记列表加载完毕 awaitsleep(40);//监听页签切换事件 observeTabChanged(element,(tab)=>{//折叠所有笔记,然后
{{{row{{{col> 美好心情 >{:id="20240805215037-7pvy56y"updated="20240805215037"}>>{:id="20240805215037-o29paki"updated="20240805215037"}>{:custom-b=""id="20240805215037-9ajqisa"style="margin:0;padding:0!import
(async()=>{//关联的数据库块 id,这里的 id 根据需要改成自己的 constavBlockId='20240727220211-p1awn4b';//关联的图表块 id,这里的 id 根据需要改成自己的 constchartBlockId='20240805130000-vhz1aei';//自动刷新延迟,单位是毫秒,默认是 1 秒,0 则不自动刷新 constautoFreshDelay=1000;//定
//seehttps://ld246.com/article/1723109908986(()=>{//注入样式,模拟激活标签的样式,可根据自己的样式进行调整 addStyle(`.layout__wnd--active.layout-tab-bar.item--pin--focus:after{background-color:var(--b3-theme-primary);}.layout-tab
//功能:代码块最近使用的语言置顶(async()=>{//配置默认的代码语言,注意如果设置了这个参数,则会覆盖上一次使用的语言。始终默认用这个语言,为空不设置 constdefaultCodeLang="";//配置最近代码语言最大显示个数 constrecentlyCodeLangLength=10;//配置置顶的代码语言,这个配置里的语言始终置顶,比如["js","java","php"]lett
记录精彩的程序人生
开始使用
分类
标签