mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-29 15:10:06 +00:00
feat(spoiler text添加文档):
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
/**
|
||||
* 将Node文本中的指定标签内容转换为带有指定类名的span
|
||||
* @param node
|
||||
* @param className
|
||||
* @param spoilerTag
|
||||
*/
|
||||
function convertTextToSpoilerSpan(node, className, spoilerTag) {
|
||||
const regex = new RegExp(`${spoilerTag}(.*?)${spoilerTag}`, 'g')
|
||||
const wholeText = node.wholeText
|
||||
@@ -33,6 +39,12 @@ function convertTextToSpoilerSpan(node, className, spoilerTag) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集并处理指定节点下的所有文本节点
|
||||
* @param root
|
||||
* @param className
|
||||
* @param spoilerTag
|
||||
*/
|
||||
function processTextNodes(root, className, spoilerTag) {
|
||||
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null)
|
||||
const waitProcessNodes = []
|
||||
@@ -45,6 +57,10 @@ function processTextNodes(root, className, spoilerTag) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位到目标处理位置,开始进行文本到spoiler的转换
|
||||
* @param spoilerTag
|
||||
*/
|
||||
function textToSpoiler(spoilerTag) {
|
||||
const intervalID = setInterval(() => {
|
||||
const articleElement = document.querySelector(
|
||||
|
||||
Reference in New Issue
Block a user