MikeCoder /
hexo-blog-encrypt
| 1 | View Code Duplication | 'use strict'; |
|
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | function decryptAES () { |
||
| 4 | |||
| 5 | const pass = String(document.getElementById('pass').value); |
||
| 6 | const decryptionError = String(document.getElementById('decryptionError').innerHTML); |
||
| 7 | const noContentError = String(document.getElementById('noContentError').innerHTML); |
||
| 8 | try { |
||
| 9 | |||
| 10 | let content = CryptoJS.AES.decrypt(document.getElementById('encrypt-blog').innerHTML.trim(), pass); |
||
|
0 ignored issues
–
show
The variable
CryptoJS seems to be never declared. If this is a global, consider adding a /** global: CryptoJS */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 11 | content = content.toString(CryptoJS.enc.Utf8); |
||
| 12 | content = decodeBase64(content); |
||
| 13 | content = unescape(content); |
||
| 14 | if (content === '') { |
||
| 15 | |||
| 16 | throw new Error(noContentError); // No content. |
||
| 17 | |||
| 18 | } else { |
||
| 19 | |||
| 20 | document.getElementById('encrypt-blog').style.display = 'inline'; |
||
| 21 | document.getElementById('encrypt-blog').innerHTML = ''; |
||
| 22 | // Use jquery to load some js code |
||
| 23 | $('#encrypt-blog').html(content); |
||
| 24 | document.getElementById('security').style.display = 'none'; |
||
| 25 | if (document.getElementById('toc-div')) { |
||
| 26 | |||
| 27 | document.getElementById('toc-div').style.display = 'inline'; |
||
| 28 | |||
| 29 | } |
||
| 30 | |||
| 31 | } |
||
| 32 | |||
| 33 | // Call MathJax to render |
||
| 34 | if(typeof MathJax !== 'undefined') { |
||
|
0 ignored issues
–
show
The variable
MathJax seems to be never declared. If this is a global, consider adding a /** global: MathJax */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 35 | |||
| 36 | MathJax.Hub.Queue( |
||
| 37 | ['resetEquationNumbers', MathJax.InputJax.TeX, ], |
||
| 38 | ['PreProcess', MathJax.Hub, ], |
||
| 39 | ['Reprocess', MathJax.Hub, ] |
||
| 40 | ); |
||
| 41 | |||
| 42 | } |
||
| 43 | |||
| 44 | } catch (e) { |
||
| 45 | |||
| 46 | alert(decryptionError); |
||
| 47 | console.log(e); |
||
|
0 ignored issues
–
show
|
|||
| 48 | |||
| 49 | } |
||
| 50 | |||
| 51 | } |
||
| 52 | |||
| 53 | function htmlDecode (str) { |
||
| 54 | |||
| 55 | let s = ''; |
||
| 56 | if (str.length == 0) { |
||
| 57 | |||
| 58 | return ''; |
||
| 59 | |||
| 60 | } |
||
| 61 | |||
| 62 | s = str.replace(/>/g, '&'); |
||
| 63 | s = s.replace(/</g, '<'); |
||
| 64 | s = s.replace(/>/g, '>'); |
||
| 65 | s = s.replace(/ /g, ' '); // ??? why not ' ' |
||
| 66 | s = s.replace(/'/g, '\''); |
||
| 67 | s = s.replace(/"/g, '"'); |
||
| 68 | s = s.replace(/<br>/g, '\n'); |
||
| 69 | return s; |
||
| 70 | |||
| 71 | } |
||
| 72 | |||
| 73 | function decodeBase64 (content) { |
||
| 74 | |||
| 75 | content = CryptoJS.enc.Base64.parse(content); |
||
|
0 ignored issues
–
show
The variable
CryptoJS seems to be never declared. If this is a global, consider adding a /** global: CryptoJS */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 76 | content = CryptoJS.enc.Utf8.stringify(content); |
||
| 77 | return content; |
||
| 78 | |||
| 79 | } |
||
| 80 | |||
| 81 | // Since you decided to use jQuery. |
||
| 82 | $(document).ready( |
||
| 83 | function () { |
||
| 84 | |||
| 85 | console.log('Registering Enter for decrypt.'); |
||
|
0 ignored issues
–
show
|
|||
| 86 | document.getElementById('pass').onkeypress = function (keyPressEvent) { |
||
| 87 | |||
| 88 | if (keyPressEvent.keyCode === 13) { |
||
| 89 | |||
| 90 | decryptAES(); |
||
| 91 | |||
| 92 | } |
||
| 93 | |||
| 94 | }; |
||
| 95 | |||
| 96 | } |
||
| 97 | ); |
||
| 98 |