Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
28528d8d
authored
Jan 09, 2025
by
赵增煜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
3711a68b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
3 deletions
+15
-3
public/static/js/sq.js
+15
-3
No files found.
public/static/js/sq.js
View file @
28528d8d
...
@@ -15,13 +15,25 @@ function replaceKeywords(keyword, replacement) {
...
@@ -15,13 +15,25 @@ function replaceKeywords(keyword, replacement) {
range
.
selectNodeContents
(
body
);
range
.
selectNodeContents
(
body
);
// 将range内的内容转换为DocumentFragment
// 将range内的内容转换为DocumentFragment
var
fragment
=
range
.
extractContents
();
var
fragment
=
range
.
extractContents
();
// 遍历fragment的所有子节点
// 遍历fragment的所有子节点
并替换文本
replaceText
(
fragment
,
keyword
,
replacement
);
traverseNodes
(
fragment
,
keyword
,
replacement
);
// 将修改后的fragment重新插入到body中
// 将修改后的fragment重新插入到body中
body
.
appendChild
(
fragment
);
body
.
appendChild
(
fragment
);
}
}
function
traverseNodes
(
node
,
keyword
,
replacement
)
{
if
(
node
.
nodeType
===
Node
.
TEXT_NODE
)
{
// 如果是文本节点,就进行替换
node
.
nodeValue
=
node
.
nodeValue
.
replace
(
new
RegExp
(
keyword
,
'g'
),
replacement
);
}
else
{
// 否则递归处理每个子节点
for
(
var
i
=
0
;
i
<
node
.
childNodes
.
length
;
i
++
)
{
traverseNodes
(
node
.
childNodes
[
i
],
keyword
,
replacement
);
}
}
}
window
.
onload
=
function
()
{
window
.
onload
=
function
()
{
//
replaceKeywords('新橙科技', '同知堂科技');
replaceKeywords
(
'新橙科技'
,
'同知堂科技'
);
// replaceKeywords('粤ICP备15024370号-7', '苏ICP备2023017636号-1');
// replaceKeywords('粤ICP备15024370号-7', '苏ICP备2023017636号-1');
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment