forked from DIDIQi/drew233.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcommon.js
70 lines (62 loc) · 2.03 KB
/
mcommon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function decryptAES() {
var pass = String(document.getElementById("pass").value);
try {
var content = CryptoJS.AES.decrypt(document.getElementById("encrypt-blog").innerHTML.trim(), pass);
content = content.toString(CryptoJS.enc.Utf8);
content = decodeBase64(content);
console.log(content);
content = unescape(content);
if (content == '') {
alert("密码错误!!");
} else {
document.getElementById("encrypt-blog").style.display = "inline";
document.getElementById("encrypt-blog").innerHTML = content;
document.getElementById("encrypt-message").style.display = "none";
document.getElementById("security").style.display = "none";
if (document.getElementById("toc-div")) {
document.getElementById("toc-div").style.display = "inline";
}
}
} catch (e) {
alert("密码错误!!");
console.log(e);
}
}
function htmlDecode (str) {
var s = "";
if (str.length == 0) return "";
s = str.replace(/>/g, "&");
s = s.replace(/</g, "<");
s = s.replace(/>/g, ">");
s = s.replace(/ /g, " ");
s = s.replace(/'/g, "\'");
s = s.replace(/"/g, "\"");
s = s.replace(/<br>/g, "\n");
return s;
}
function decodeBase64(content) {
content = CryptoJS.enc.Base64.parse(content);
content = CryptoJS.enc.Utf8.stringify(content);
return content;
}
// add enter to decrypt
addLoadEvent(function() {
console.log('register');
document.getElementById("pass").onkeypress = function(keyPressEvent) {
console.log(keyPressEvent.keyCode === 13);
if (keyPressEvent.keyCode === 13) {
decryptAES();
}
};
});
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}