From d2859a7dd468c7548e663b54c11eeb33828a70d3 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 6 Sep 2024 14:44:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dopenwrite=E8=A2=AB=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=BB=95=E8=BF=87=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/OpenWrite.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/components/OpenWrite.js b/components/OpenWrite.js index eb068102553..4e429a10621 100644 --- a/components/OpenWrite.js +++ b/components/OpenWrite.js @@ -51,6 +51,20 @@ const OpenWrite = () => { blogId, cookieAge }) + + // btw初始化后,开始监听read-more-wrap何时消失 + let intervalId = setInterval(() => { + const readMoreWrapElement = document.getElementById('read-more-wrap') + + if (!readMoreWrapElement) { + toggleTocItems(false) // 恢复目录项的点击 + // 停止定时器 + clearInterval(intervalId) + } + }, 1000) // 每秒检查一次 + + // Return cleanup function to clear the interval if the component unmounts + return () => clearInterval(intervalId) } } catch (error) { console.error('OpenWrite 加载异常', error) @@ -65,13 +79,30 @@ const OpenWrite = () => { // Only load the script if the element doesn't exist if (!readMoreWrap) { loadOpenWrite() + toggleTocItems(true) // 禁止目录项的点击 } } }) + // 启动一个监听器,当页面上存在#read-more-wrap对象时,所有的 a .notion-table-of-contents-item 对象都禁止点击 + return <> } +// 定义禁用和恢复目录项点击的函数 +const toggleTocItems = disable => { + const tocItems = document.querySelectorAll('a.notion-table-of-contents-item') + tocItems.forEach(item => { + if (disable) { + item.style.pointerEvents = 'none' + item.style.opacity = '0.5' + } else { + item.style.pointerEvents = 'auto' + item.style.opacity = '1' + } + }) +} + /** * 检查白名单 * @param {*} path 当前url的字符串