From 9393b333cf314d703447c468c64990acc3f897b0 Mon Sep 17 00:00:00 2001 From: Tron Date: Wed, 9 Oct 2024 22:40:04 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20siyuan=20v3.1.8=20=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E3=80=8A=E4=B8=BB=E9=A2=98=E5=9D=97=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E3=80=8B=E6=8C=89=E9=92=AE=E5=A4=B1=E6=95=88?= =?UTF-8?q?=20#116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ theme.js | 54 ++++++++++------------------------------------------ theme.json | 2 +- 3 files changed, 14 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44975cc..2d46602 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v2.2.7/ 2024.10.09 +- 🐛 siyuan v3.1.8 导致《主题块样式更改》按钮失效 + ## V2.2.6 / 2024.09.12 - 🐛 Dark主题无法修改加粗文字 diff --git a/theme.js b/theme.js index 4b0034b..98ace5e 100644 --- a/theme.js +++ b/theme.js @@ -200,7 +200,7 @@ function create_theme_button() { drag.insertAdjacentElement('afterend', button_change_color); } } -setTimeout(() => {}, 0); +setTimeout(() => { }, 0); /** * 发送API请求 @@ -381,7 +381,7 @@ async function 解析响应体(response) { * subtype: string, // 块子类型(若没有则为 null) * } * @returns {null} 没有找到块 ID */ -function getBlockSelected() { +function getBlockSelected() { let node_list = document.querySelectorAll('.protyle-wysiwyg--select'); if (node_list.length === 1 && node_list[0].dataset.nodeId != null) return { @@ -405,7 +405,7 @@ function MenuShow() { if ( selecttype == 'NodeList' || selecttype == 'NodeTable' || - selecttype == 'NodeBlockquote' || + // selecttype == 'NodeBlockquote' || selecttype == 'NodeCodeBlock' ) { setTimeout(() => InsertMenuItem(selectid, selecttype), 0); @@ -414,30 +414,7 @@ function MenuShow() { }, 0); } -function InsertMenuItem(selectid, selecttype) { - let commonMenu = document.querySelector('.b3-menu__items'); - let readonly = commonMenu.querySelector('.b3-menu__item--readonly'); - let selectview = commonMenu.querySelector('[id="viewselect"]'); - if (readonly) { - if (!selectview) { - commonMenu.insertBefore(ViewSelect(selectid, selecttype), readonly); - commonMenu.insertBefore(MenuSeparator(), readonly); - } - } -} -function ViewMonitor(event) { - let id = event.currentTarget.getAttribute('data-node-id'); - let attrName = 'custom-' + event.currentTarget.getAttribute('custom-attr-name'); - let attrValue = event.currentTarget.getAttribute('custom-attr-value'); - let blocks = document.querySelectorAll(`.protyle-wysiwyg [data-node-id="${id}"]`); - if (blocks) { - blocks.forEach(block => block.setAttribute(attrName, attrValue)); - } - let attrs = {}; - attrs[attrName] = attrValue; - 设置思源块属性(id, attrs); -} setTimeout(() => ClickMonitor(), 1000); @@ -517,7 +494,7 @@ function ViewSelect(selectid, selecttype) { button.id = 'viewselect'; button.className = 'b3-menu__item'; button.innerHTML = - '主题块样式更改'; + '主题块样式更改'; button.appendChild(SubMenu(selectid, selecttype)); return button; } @@ -525,7 +502,7 @@ function ViewSelect(selectid, selecttype) { function SubMenu(selectid, selecttype, className = 'b3-menu__submenu') { let node = document.createElement('div'); node.className = className; - console.log(selecttype); + console.log(selecttype); if (selecttype == 'NodeList') { node.appendChild(GraphView(selectid)); node.appendChild(TableView(selectid)); @@ -685,27 +662,16 @@ function ClickMonitor() { window.addEventListener('mouseup', MenuShow); } -function MenuShow() { - setTimeout(() => { - let selectinfo = getBlockSelected(); - if (selectinfo) { - let selecttype = selectinfo.type; - let selectid = selectinfo.id; - if (selecttype == 'NodeList' || selecttype == 'NodeTable' || selecttype == 'NodeCodeBlock') { - setTimeout(() => InsertMenuItem(selectid, selecttype), 0); - } - } - }, 0); -} function InsertMenuItem(selectid, selecttype) { let commonMenu = document.querySelector('.b3-menu__items'); - let readonly = commonMenu.querySelector('.b3-menu__item--readonly'); + let target = commonMenu.querySelector('.b3-menu__separator[data-id="separator_5"]'); let selectview = commonMenu.querySelector('[id="viewselect"]'); - if (readonly) { + if (target) { + console.log('test'); if (!selectview) { - commonMenu.insertBefore(ViewSelect(selectid, selecttype), readonly); - commonMenu.insertBefore(MenuSeparator(), readonly); + // 在 target 元素后插入 ViewSelect + target.insertAdjacentElement('afterend', ViewSelect(selectid, selecttype)); } } } diff --git a/theme.json b/theme.json index 55c97b4..fccd174 100644 --- a/theme.json +++ b/theme.json @@ -2,7 +2,7 @@ "name": "Tsundoku", "author": "Achuan-2", "url": "https://github.com/Achuan-2/siyuan-themes-tsundoku", - "version": "2.2.6", + "version": "2.2.7", "displayName": { "default": "Tsundoku", "zh_CN": "積読"