Skip to content

Commit

Permalink
deploy: ayuxy/Blog_Backup@954559b4889b785f1ee68e8989623751593a0e45
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuxy committed Dec 11, 2023
1 parent fe3b3c7 commit 39b0f73
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions js/AESDecrypt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
let decryptionSuccess = false; // 新增的标志

async function AESDecrypt(cipher, password) {
let parts = cipher.split("|");
Expand Down Expand Up @@ -66,39 +67,38 @@ function checkPassword() {
decryption(password)
}
// 解密函数
function decryption(password) {
async function decryption(password) {
let secretElement = document.getElementById('secret');
let ciphertext = secretElement.innerText;

AESDecrypt(ciphertext, password).then(plaintext => {
try {
const plaintext = await AESDecrypt(ciphertext, password);

document.getElementById("verification").style.display = "none";
let verificationElement = document.getElementById('verification');
let htmlText = marked.parse(plaintext);
verificationElement.insertAdjacentHTML('afterend', htmlText);

// 手动执行插入的 JavaScript 代码
executeInsertedScripts(verificationElement);
location.reload(true); // 参数为 true 表示强制从服务器重新加载页面


// 设置解密成功的标志
decryptionSuccess = true;

if (localStorage.getItem(title) !== password) localStorage.setItem(title, password);
}).catch(error => {

// 在所有解密成功后进行一次页面重载
reloadPageIfNeeded();

} catch (error) {
alert("Incorrect password. Please try again.");
console.error("Failed to decrypt", error);
});
}
}

function executeInsertedScripts(parentElement) {
// 获取所有插入的 <script> 标签
const scriptElements = parentElement.getElementsByTagName('script');

// 遍历执行每个 <script> 标签中的代码
for (let script of scriptElements) {
const scriptContent = script.textContent || script.innerText;
if (scriptContent) {
// 使用 Function 构造函数执行代码
const scriptFunction = new Function(scriptContent);
scriptFunction();
}
// 新增的检查是否重载页面的函数
function reloadPageIfNeeded() {
if (decryptionSuccess) {
location.reload(true); // 参数为 true 表示强制从服务器重新加载页面
}
}

0 comments on commit 39b0f73

Please sign in to comment.