Skip to content

Commit b3ce5cd

Browse files
committed
添加刷新函数, 在解密函数成功后执行刷新函数修改HTML元素
1 parent 4fab655 commit b3ce5cd

5 files changed

Lines changed: 94 additions & 78 deletions

File tree

‎layouts/partials/scripts.html‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script src="{{"/js/utils.js" | relURL}}"></script>
22
<script src="{{"/js/startup.js" | relURL}}"></script>
33

4-
<script src="{{"/js/code-block.js" | relURL}}"></script>
5-
<script src="{{"/js/toc_inspect.js" | relURL}}"></script>
64
<script src="{{"/js/hit.js" | relURL}}"></script>
75

86
<script type="text/javascript" src="{{"/js/crypto-js/crypto-js.js" | relURL}}"></script>
97
<script src="{{"/js/decrypt.js" | relURL}}"></script>
108

9+
<script src="{{"/js/code-block.js" | relURL}}"></script>
10+
<script src="{{"/js/toc_inspect.js" | relURL}}"></script>
11+

‎static/js/code-block.js‎

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,86 @@
11
// 添加代码块复制按钮
2-
(function(){
3-
const svgCopy =
4-
'<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg>';
2+
var code_block = function(){
3+
const svgCopy =
4+
'<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg>';
55

6-
const svgCheck =
7-
'<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg>';
6+
const svgCheck =
7+
'<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg>';
88

9-
const svgFold =
10-
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrows-collapse" viewBox="0 0 16 16"> <path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13A.5.5 0 0 1 1 8zm7-8a.5.5 0 0 1 .5.5v3.793l1.146-1.147a.5.5 0 0 1 .708.708l-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 4.293V.5A.5.5 0 0 1 8 0zm-.5 11.707-1.146 1.147a.5.5 0 0 1-.708-.708l2-2a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 11.707V15.5a.5.5 0 0 1-1 0v-3.793z"/> </svg>';
9+
const svgFold =
10+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrows-collapse" viewBox="0 0 16 16"> <path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13A.5.5 0 0 1 1 8zm7-8a.5.5 0 0 1 .5.5v3.793l1.146-1.147a.5.5 0 0 1 .708.708l-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 4.293V.5A.5.5 0 0 1 8 0zm-.5 11.707-1.146 1.147a.5.5 0 0 1-.708-.708l2-2a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 11.707V15.5a.5.5 0 0 1-1 0v-3.793z"/> </svg>';
1111

12-
const svgUnfold =
13-
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-bar-down" viewBox="0 0 16 16"> <path fill-rule="evenodd" d="M1 3.5a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13a.5.5 0 0 1-.5-.5zM8 6a.5.5 0 0 1 .5.5v5.793l2.146-2.147a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 .708-.708L7.5 12.293V6.5A.5.5 0 0 1 8 6z"/> </svg>';
12+
const svgUnfold =
13+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-bar-down" viewBox="0 0 16 16"> <path fill-rule="evenodd" d="M1 3.5a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13a.5.5 0 0 1-.5-.5zM8 6a.5.5 0 0 1 .5.5v5.793l2.146-2.147a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 .708-.708L7.5 12.293V6.5A.5.5 0 0 1 8 6z"/> </svg>';
1414

1515

16-
const getCodeContent = (codeBlock) => {
17-
var res = ""
18-
var elem = codeBlock.firstChild;
19-
while (elem != null) {
20-
res += elem.firstChild.nextSibling.textContent;
21-
elem = elem.nextSibling;
16+
const getCodeContent = (codeBlock) => {
17+
var res = ""
18+
var elem = codeBlock.firstChild;
19+
while (elem != null) {
20+
res += elem.firstChild.nextSibling.textContent;
21+
elem = elem.nextSibling;
22+
}
23+
24+
return res;
2225
}
2326

24-
return res;
27+
// add button function
28+
const addCopyButtons = () => {
29+
document.querySelectorAll("pre > code").forEach((codeBlock) => {
30+
const clickBtn = document.createElement("button");
31+
clickBtn.className = "code-copy";
32+
clickBtn.type = "button";
33+
clickBtn.innerHTML = svgCopy;
34+
clickBtn.addEventListener("click", () => {
35+
const textarea = document.createElement('textarea');
36+
37+
textarea.value = getCodeContent(codeBlock);
38+
39+
document.body.appendChild(textarea);
40+
textarea.select();
41+
document.execCommand('copy');
42+
document.body.removeChild(textarea);
43+
44+
clickBtn.blur();
45+
clickBtn.innerHTML = svgCheck;
46+
setTimeout(() => (clickBtn.innerHTML = svgCopy), 500);
47+
48+
});
49+
50+
const pre = codeBlock.parentNode;
51+
pre.parentNode.insertBefore(clickBtn, pre.nextSibling);
52+
53+
const notice = document.createElement("div");
54+
notice.innerHTML = "代码块已折叠";
55+
notice.className = "code-notice";
56+
const foldBtn = document.createElement("button");
57+
foldBtn.className = "code-toggle";
58+
foldBtn.type = "button";
59+
foldBtn.innerHTML = svgFold;
60+
foldBtn.addEventListener("click", () => {
61+
if(pre.classList.contains('code-folded')) {
62+
pre.classList.remove('code-folded');
63+
pre.firstElementChild.style.display = "block";
64+
pre.removeChild(notice);
65+
foldBtn.innerHTML = svgFold;
66+
}
67+
else {
68+
pre.classList.add('code-folded');
69+
pre.appendChild(notice);
70+
pre.firstElementChild.style.display = "none";
71+
foldBtn.innerHTML = svgUnfold;
72+
}
73+
})
74+
pre.parentNode.insertBefore(foldBtn, pre.nextSibling);
75+
if(pre.parentNode.parentNode.classList.contains("__flag__"))
76+
foldBtn.click();
77+
});
78+
};
79+
80+
addCopyButtons()
2581
}
2682

27-
// add button function
28-
const addCopyButtons = () => {
29-
document.querySelectorAll("pre > code").forEach((codeBlock) => {
30-
const clickBtn = document.createElement("button");
31-
clickBtn.className = "code-copy";
32-
clickBtn.type = "button";
33-
clickBtn.innerHTML = svgCopy;
34-
clickBtn.addEventListener("click", () => {
35-
const textarea = document.createElement('textarea');
36-
37-
textarea.value = getCodeContent(codeBlock);
38-
39-
document.body.appendChild(textarea);
40-
textarea.select();
41-
document.execCommand('copy');
42-
document.body.removeChild(textarea);
43-
44-
clickBtn.blur();
45-
clickBtn.innerHTML = svgCheck;
46-
setTimeout(() => (clickBtn.innerHTML = svgCopy), 500);
47-
48-
});
49-
50-
const pre = codeBlock.parentNode;
51-
pre.parentNode.insertBefore(clickBtn, pre.nextSibling);
52-
53-
const notice = document.createElement("div");
54-
notice.innerHTML = "代码块已折叠";
55-
notice.className = "code-notice";
56-
const foldBtn = document.createElement("button");
57-
foldBtn.className = "code-toggle";
58-
foldBtn.type = "button";
59-
foldBtn.innerHTML = svgFold;
60-
foldBtn.addEventListener("click", () => {
61-
if(pre.classList.contains('code-folded')) {
62-
pre.classList.remove('code-folded');
63-
pre.firstElementChild.style.display = "block";
64-
pre.removeChild(notice);
65-
foldBtn.innerHTML = svgFold;
66-
}
67-
else {
68-
pre.classList.add('code-folded');
69-
pre.appendChild(notice);
70-
pre.firstElementChild.style.display = "none";
71-
foldBtn.innerHTML = svgUnfold;
72-
}
73-
})
74-
pre.parentNode.insertBefore(foldBtn, pre.nextSibling);
75-
if(pre.parentNode.parentNode.classList.contains("__flag__"))
76-
foldBtn.click();
77-
});
78-
};
79-
80-
addCopyButtons()
81-
82-
})()
83+
code_block()
84+
addActionOnModifyHtml(code_block)
85+
8386

‎static/js/decrypt.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const _click_handler = function (element) {
4646
let key = location.pathname + ".password." + index;
4747
storage.setItem(key, password);
4848
parent.innerHTML = decrypted;
49+
onModifyHtml();
4950
}
5051

5152

@@ -62,8 +63,8 @@ addLoadEvent(function() {
6263
let password = localStorage.getItem(key);
6364

6465
if (!password) {
66+
onModifyHtml();
6567
break;
66-
6768
} else {
6869
console.log("Found password for part " + index);
6970

‎static/js/toc_inspect.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
(function(){
2-
1+
var toc_inspect = function(){
32
const selector = ['h2', 'h3', 'h4']
43

54
var content = document.querySelector('article, .list');
@@ -53,5 +52,8 @@
5352

5453
// window.addEventListener('scroll', throttle(scrollHandler, 500));
5554
window.addEventListener('scroll', scrollHandler);
55+
}
56+
57+
toc_inspect()
58+
addActionOnModifyHtml(toc_inspect)
5659

57-
})()

‎static/js/utils.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ var addLoadEvent = (func) => {
1111
}
1212
}
1313

14+
var onModifyHtml = () => {};
15+
var addActionOnModifyHtml = (func) => {
16+
var oldfunc = onModifyHtml;
17+
onModifyHtml = function() {
18+
oldfunc();
19+
func();
20+
}
21+
}
22+

0 commit comments

Comments
 (0)