wilsons
关注
142093 号成员,2024-05-12 13:24:23 加入
2.1k
个人主页 浏览
1.5k
帖子 + 回帖 + 评论
人生最大的敌人是自己,战胜自己,才能超越一切。
  • [js] 连续点击 openAny,小代码,大作用,让一切触手可达

    2025-04-17 23:48

    可以,不仅仅其他主题,浏览器,obsidian,logseq 等只要支持 js 的软件当中都可以。

  • 开发者选项如何保存修改

    2025-04-17 23:44

    这个改不了,因为这个是动态变化的,你改后一拖动又变化了。

    如果写死,就无法拖动了。

    所以只能改最大或最小值,超过这个限制就无法拖动了。

    比如:

    .fn__flex-column.fn__flex-shrink.layout__dockl { min-width: 300px; }

    然后把代码放到 设置 -》外观 =》代码片段 =》css 中查看效果。

  • VBA 代码块类型选择什么

    2025-04-17 22:42

    vb 或 vbscript

    vba 就是 vb 代码

  • [js] 连续点击 openAny,小代码,大作用,让一切触手可达

    2025-04-17 22:35

    哈哈,主要是通过一些模拟点击,按键,输入或 invoke 回调函数来实现你想要的功能。

    比如,打开设置,通过注册快捷键化给文字添加样式,注册快捷键打开那些隐藏在菜单深处的功能等,也可以把这些功能添加到工具栏,编辑器导航等处。

    注册快捷键的代码可以放到代码片段中,或按需放置,比如放到 runjs 代码块中或自己写的代码中等。

    举例说明 实例代码放到控制台执行下就知道它的效果了。

  • 思源数据库列名转义问题

    2025-04-17 16:54
    .action{index . "宽(mm)"} // 如果赋值变量 .action{$w := (index . "宽(mm)")} .action{$w}
  • [js][css] 斜杠菜单,导航栏,状态栏,文档树美化和增强

    2025-04-17 07:27

    抱歉,我在 v3.1.10 和 3.1.27 上都没有发现你说的问题。

    请在新空间测试,排除干扰项试试呢

  • 求助能否将“优化排版”按钮从折叠菜单中放到外面来

    2025-04-16 09:31

    已修改

    锁定状态下点击会提示不可用

    发布服务下不显示

  • 各位大佬请问数据库中模板列输入这种公式有好的办法吗?

    2025-04-15 23:48

    公式

    image.png

    思源模板

    .action{ $t := .t值所在的列名 } .action{ $y := add (mul 0.00003 (mul $t (mul $t (mul $t $t)))) (add (mul -0.0088 (mul $t (mul $t $t))) (add (mul 0.958 (mul $t $t)) (add (mul -54.354 $t) 1771.3))) } y = .action{ $y }

    分步骤实现方式(供参考,方便理解)

    .action{ $t := 10 } .action{ $t4 := mul $t (mul $t (mul $t $t)) } .action{ $t3 := mul $t (mul $t $t) } .action{ $t2 := mul $t $t } .action{ $term1 := mul 0.00003 $t4 } .action{ $term2 := mul -0.0088 $t3 } .action{ $term3 := mul 0.958 $t2 } .action{ $term4 := mul -54.354 $t } .action{ $y := add $term1 (add $term2 (add $term3 (add $term4 1771.3))) } y = .action{ $y }
  • 为什么新版本不支持 macos11 以前的系统了?

    2025-04-15 23:31

    建议官方把内核单独发布,这样在不支持的系统上,可以直接运行内核,然后浏览器使用。

    虽然有 docker 版,但让普通用户搞 docker 有点难。

    @88250

  • 为什么新版本不支持 macos11 以前的系统了?

    2025-04-15 16:18

    应该是思源依赖的第三方开源代码或软件原因,比如 electron。

  • 表格里面的内容能变成列表吗?

    2025-04-15 16:16

    表格一般方法不行,但可以把 Markdown 代码复制给 ai,让帮你转换。

    但如果是列表想显示成表格形式,可以参考这个代码

    [js][css] 提取写味主题列表转表格导图看板功能

  • 如何引用某个块中的一部分内容

    2025-04-15 15:58

    要看具体是什么块?

    思源中块是可引用的最小单位,但思源中的块是可以嵌套的,比如列表,任务,超级块等。

    如果是最内层的块,是无法部分引用的,如果是外层的块,想引用内层块的内容,只需要用内层块 id 即可。

  • 求助能否将“优化排版”按钮从折叠菜单中放到外面来

    2025-04-15 13:11

    最完美的方式,当如是也

    image.png

    // 把优化排版菜单移动到文档导航条 { const main = (protyle)=>{ // 发布服务下不显示 if(window.siyuan.config.readonly) return; if(protyle?.querySelector('.protyle-breadcrumb [data-type="optimizeTypography"]')) return; const exitFocusBtn = protyle.querySelector('.protyle-breadcrumb [data-type="exit-focus"]'); if(!exitFocusBtn) return; const optimizeHtml = `<button class="block__icon fn__flex-center ariaLabel" aria-label="优化排版" data-type="optimizeTypography"><svg><use xlink:href="#iconFormat"></use></svg></button>`; exitFocusBtn.insertAdjacentHTML('afterend', optimizeHtml); const optimizeBtn = protyle.querySelector('.protyle-breadcrumb [data-type="optimizeTypography"]'); if(!optimizeBtn) return; optimizeBtn.addEventListener('click', () => { // 锁定状态下不可修改 const icon = protyle?.querySelector('button[data-type="readonly"] use')?.getAttributeNS('http://www.w3.org/1999/xlink', 'href'); if(icon === '#iconLock') { showMessage('锁定状态不可用'); return } // 优化排版 // see https://github.com/siyuan-note/siyuan/blob/a01523dc98799590396ffcabdc90b2dc6efe8474/app/src/protyle/breadcrumb/index.ts#L415 requestApi("/api/format/autoSpace", { id: protyle?.querySelector('.protyle-title')?.dataset?.nodeId }); }); }; // 监听protyle加载 whenElementExist('.protyle:not(.fn__none)').then(main); observeProtyleLoad(main); function showMessage(message, isError = false, delay = 7000) { return fetch('/api/notification/' + (isError ? 'pushErrMsg' : 'pushMsg'), { "method": "POST", "body": JSON.stringify({"msg": message, "timeout": delay}) }); } async function requestApi(url, data, method = 'POST') { return await (await fetch(url, {method: method, body: JSON.stringify(data||{})})).json(); } function whenElementExist(selector, node) { return new Promise(resolve => { const check = () => { const el = typeof selector==='function'?selector():(node||document).querySelector(selector); if (el) resolve(el); else requestAnimationFrame(check); }; check(); }); } function observeProtyleLoad(callback, parentElement) { // 如果 parentElement 是字符串,则将其转换为 DOM 元素 if (typeof parentElement === 'string') { parentElement = document.querySelector(parentElement); } // 创建一个 MutationObserver 实例 const observer = new MutationObserver((mutationsList) => { mutationsList.forEach((mutation) => { // 检查是否是属性变化并且变化的属性是 class if (mutation.type === 'attributes' && mutation.attributeName === 'class') { const targetElement = mutation.target; // 发生变化的目标元素 // 判断目标元素是否匹配指定选择器 .protyle:not(.fn__none) if (targetElement.matches('.protyle:not(.fn__none)')) { // 触发回调 callback(targetElement); } } }); }); // 配置观察选项 const config = { attributes: true, // 监听属性变化 attributeFilter: ['class'], // 仅监听 class 属性 subtree: true, // 监听父容器及其所有后代元素 }; // 启动观察,默认监听 document.body 或指定的父容器 observer.observe(parentElement || document.body, config); } }

    类似文章推荐 https://pipe.b3log.org/blogs/wilsons/articles/2025/04/15/1744703423359

  • 如何删除表格里面的行

    2025-04-15 13:09

    确实如楼上所说,正常右键是可以删除的,合并的需要先拆分单元格后再删除行

    image.png

    image.png

  • 请问思源怎么通过 iPhone 直接分享?

    2025-04-14 18:09

    可以分享到其他软件,然后再同步到思源,虽然我不知道用什么软件,你可以研究下。

  • 能否优化下 docker 启动速度

    2025-04-14 18:02

    思源本身也确实大,短时间内估计思源不会搞,建议用 CDN 缓存静态文件。

  • [js] 代码块优化之折叠 / 展开 / 全屏 / 悬浮横向滚动条

    2025-04-14 17:52

    不好意思我重现不了你的问题

    1 确保代码是最新版

    2 新空间测试以排除可能的干扰项

    3 提供思源版本及详细重现步骤

    4 最好提供有问题的测试文档

  • [js] 一键编辑思源图片,思源里也可以编辑图片了

    2025-04-14 09:54

    已更新至 0.0.2 版

    0.0.2 发布服务和锁定状态不可修改

  • [js] 代码块优化之折叠 / 展开 / 全屏 / 悬浮横向滚动条

    2025-04-14 09:06

    你确定是这个 js 的问题吗?有没有排除过其他可能影响的因素。

    如果你确定的话,可否把你的文档发来看看。如果不方便也可以发私信。

    我这边测试 4 万字的文章,很多代码块没影响。

  • 块属性中可以添加备注,备注常显示时,怎么把那个备注的图标去掉

    2025-04-13 16:42
    1. 编辑器中去掉该选项(但同时会影响命名,别名等)

      image.png

    2. css 去掉

      .protyle-attr>div.protyle-attr--memo{ display:none; }
  • 如何使用 js 统计访问量及网站运行时间

    2025-04-13 15:42

    可以,等下用新的 dom 显示就行,现在用的 status 公共消息区,可能 🈶 新消息覆盖了

    还有别的问题吗?一起改

  • 如何使用 js 统计访问量及网站运行时间

    2025-04-13 12:48

    写了一个代码,但不知你说的侧边栏是指放哪?感觉放不下,所以放状态栏了。

    另外,手机版也不知道哪里有位置显示,所以暂不支持。

    仅供参考。

    image.png

    // 统计网站访问量和运行时间 (async ()=>{ // api地址,最后不要加 / const apiUrl = 'http://127.0.0.1:6806'; // api token 在设置->关于中查看 const apiToken = ''; // 初始化数据 const initData = { // 网站总访问量 total: 0, // 网站运行初始日期 startDay: '2025-04-13' }; // 定义统计信息显示模板 const tongjiTpl = `总访问量:{total}&nbsp;&nbsp;网站运行:{runningDays}天`; // 已统计的跳过 if(document.querySelector('#status .site__tongji')) return; // 获取置顶数据,格式 {"total":0, "startDay":''} let data = await getFile('/data/storage/site_tongji.json'); data = JSON.parse(data||'{}'); if(data.code && data.code !== 0) data = {}; data = {...initData, ...data}; // 仅发布服务器才统计 if(siyuan.config.readonly) { // 网站访问+1 data.total++; // 存储网站访问数据 putFile('/data/storage/site_tongji.json', JSON.stringify(data, null, 4)); } // 获取网站运行时间 const runningDays = calculateRunningDays(data); // 状态栏显示统计信息 showStatusMsg(tongjiTpl.replace('{total}', data.total).replace('{runningDays}', runningDays)); // 计算网站运行时间(单位:天) function calculateRunningDays(data) { // 获取当前日期并重置时间为 00:00:00 const currentDate = new Date(); resetTime(currentDate); // 解析初始日期并重置时间为 00:00:00 const startDate = new Date(data.startDay); if (isNaN(startDate.getTime())) { return 1; } resetTime(startDate); // 计算时间差(毫秒) const timeDifference = currentDate - startDate; // 转换为天数 const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); return daysDifference + 1; } function resetTime(date) { date.setHours(0, 0, 0, 0); // 设置时间为 00:00:00.000 return date; } // 状态栏输出 function showStatusMsg(html) { const statusMsg = document.querySelector('#status .status__msg'); if(!statusMsg) return; const tongji = document.querySelector('#status .site__tongji'); if(tongji) tongji.remove(); const style = ` color: var(--b3-theme-on-surface); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; padding-left: 5px; font-size: 12px; `; html = `<div class="site__tongji" style="${style}">${html}</div>`; statusMsg.insertAdjacentHTML('beforebegin', html); } // 获取文件 async function getFile(path) { return fetch("/api/file/getFile", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ path, }), }).then((response) => { if (response.ok) { return response.text(); } else { throw new Error("Failed to get file content"); } }).catch((error) => { console.error(error); }); } // 存储文件,支持创建文件夹,当isDir true时创建文件夹,忽略文件 async function putFile(path, content = '', isDir = false) { const formData = new FormData(); formData.append("path", path); formData.append("isDir", isDir) formData.append("file", new Blob([content])); const result = await fetch(apiUrl+"/api/file/putFile", { // 写入js到本地 method: "POST", headers: { "Authorization": "token " + apiToken // 添加 Authorization 头 }, body: formData, }); const json = await result.json(); return json; } })();
  • 希望标题可以包含 / 符号

    2025-04-13 11:39

    / 全角斜杠试试

  • 如何使用 js 统计访问量及网站运行时间

    2025-04-13 11:09

    51LA 统计可以,并支持显示简单统计面板,由于第三方统计,都免去打包的麻烦了。

  • 请问思源笔记的搜索能否设置默认展开数?

    2025-04-12 20:30

    可参考这个大佬的代码,看看能否实现

    [js] 折叠 / 展开所有搜索结果

  • 能够将 Alt + X 标记与加粗结合到一起

    2025-04-12 20:10

    @Adaxi

    这个好像是和 mark 标记是一样的效果,所以我可以直接修改 mark 标记的 css 实现,但是只有一种颜色,也够用了

    这个 protyle.toolbar.setInlineMark(protyle, 'mark', "toolbar"); mark 这个参数可以任意改,工具栏上的"strong", "em", "s", "code", "mark", "tag", "u", "sup", "clear", "sub", "kbd"样式都支持。

    参考 https://github.com/siyuan-note/siyuan/blob/a01523dc98799590396ffcabdc90b2dc6efe8474/app/src/mobile/util/keyboardToolbar.ts#L615C77-L615C154

    如果想要改文字颜色或背景色也可以

    比如:

    protyle.toolbar.setInlineMark(protyle, "text", "range", {type:'color', color:'var(--b3-font-color8)'}); protyle.toolbar.setInlineMark(protyle, "text", "range", {type:'backgroundColor', color:'var(--b3-font-background2)'});

    参考 https://github.com/siyuan-note/siyuan/blob/a01523dc98799590396ffcabdc90b2dc6efe8474/app/src/protyle/toolbar/Font.ts#L284

    当然,你用自己的方法实现也可以的,条条大路通罗马。

  • 能够将 Alt + X 标记与加粗结合到一起

    2025-04-12 19:35

    alt+x 版

    注意:

    代码中加上这个 event.stopPropagation();可以阻止默认的 alt+x 最近使用样式的添加(默认已加上这个代码)

    去掉这个代码,则会同时赋予 3 种样式,加粗,标记和最近样式

    // alt+x 给文字加粗和标记 (()=>{ // 监听键盘按下alt+x事件 document.addEventListener('keydown', function(event) { // 检查是否按下了 Alt 键以及物理按键是 'KeyX' if ( event.altKey && // 按下了 Alt 键 event.code === 'KeyX' && // 物理按键是 X !event.shiftKey && // 未按下 Shift 键 !event.ctrlKey && // 未按下 Ctrl 键 !event.metaKey // 未按下 Meta 键 ) { // 阻止默认行为(如果有必要) event.preventDefault(); // 阻止冒泡,不加这个会和思源的alt+x重合,出现三种效果 event.stopPropagation(); // 获取protyle const protyle = getProtyle(); // 给文字加粗 protyle.toolbar.setInlineMark(protyle, 'strong', "toolbar"); // 给文字标记 protyle.toolbar.setInlineMark(protyle, 'mark', "toolbar"); } },true); function getProtyle() { try { if(document.getElementById("sidebar")) return siyuan.mobile.editor.protyle; const currDoc = siyuan?.layout?.centerLayout?.children.map(item=>item.children.find(item=>item.headElement?.classList.contains('item--focus') && (item.panelElement.closest('.layout__wnd--active')||item.panelElement.closest('[data-type="wnd"]')))).find(item=>item); return currDoc?.model.editor.protyle; } catch(e) { console.error(e); return null; } } })();