Skip to content

Commit

Permalink
feat(spoiler text添加文档):
Browse files Browse the repository at this point in the history
  • Loading branch information
qixing-jk committed Dec 30, 2024
1 parent 06c41ae commit 177c450
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions public/js/spoilerText.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = []
Expand All @@ -45,6 +57,10 @@ function processTextNodes(root, className, spoilerTag) {
}
}

/**
* 定位到目标处理位置,开始进行文本到spoiler的转换
* @param spoilerTag
*/
function textToSpoiler(spoilerTag) {
const intervalID = setInterval(() => {
const articleElement = document.querySelector(
Expand Down

0 comments on commit 177c450

Please sign in to comment.