mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-01 15:10:14 +00:00
Merge pull request #2709 from tangly1024/release/4.7.0
修复openwrite被目录绕过的bug
This commit is contained in:
@@ -51,6 +51,20 @@ const OpenWrite = () => {
|
|||||||
blogId,
|
blogId,
|
||||||
cookieAge
|
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) {
|
} catch (error) {
|
||||||
console.error('OpenWrite 加载异常', error)
|
console.error('OpenWrite 加载异常', error)
|
||||||
@@ -65,13 +79,30 @@ const OpenWrite = () => {
|
|||||||
// Only load the script if the element doesn't exist
|
// Only load the script if the element doesn't exist
|
||||||
if (!readMoreWrap) {
|
if (!readMoreWrap) {
|
||||||
loadOpenWrite()
|
loadOpenWrite()
|
||||||
|
toggleTocItems(true) // 禁止目录项的点击
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 启动一个监听器,当页面上存在#read-more-wrap对象时,所有的 a .notion-table-of-contents-item 对象都禁止点击
|
||||||
|
|
||||||
return <></>
|
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的字符串
|
* @param {*} path 当前url的字符串
|
||||||
|
|||||||
Reference in New Issue
Block a user