Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Sep 7, 2024
2 parents ade1273 + c2c8501 commit ad433e7
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions components/OpenWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ const OpenWrite = () => {
blogId,
cookieAge
})

// btw初始化后,开始监听read-more-wrap何时消失
const intervalId = setInterval(() => {
const readMoreWrapElement = document.getElementById('read-more-wrap')
const articleWrapElement = document.getElementById('article-wrapper')

if (!readMoreWrapElement && articleWrapElement) {
toggleTocItems(false) // 恢复目录项的点击
// 自动调整文章区域的高度
articleWrapElement.style.height = 'auto'
// 停止定时器
clearInterval(intervalId)
}
}, 1000) // 每秒检查一次

// Return cleanup function to clear the interval if the component unmounts
return () => clearInterval(intervalId)
}
} catch (error) {
console.error('OpenWrite 加载异常', error)
Expand All @@ -65,13 +82,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的字符串
Expand Down

0 comments on commit ad433e7

Please sign in to comment.