opt: reduce code

This commit is contained in:
KOWX712
2025-03-02 04:06:17 +08:00
parent 93e2e8c8ba
commit c20e8cde1f
15 changed files with 156 additions and 343 deletions
+12 -20
View File
@@ -6,35 +6,27 @@ const githubLink = document.getElementById('github');
// Function to show about overlay
document.getElementById("about").addEventListener("click", () => {
const aboutOverlay = document.getElementById('about-overlay');
const aboutMenu = document.getElementById('about-menu');
const closeAbout = document.getElementById('close-about');
const showMenu = () => {
aboutOverlay.style.display = 'flex';
setTimeout(() => {
aboutOverlay.style.opacity = '1';
aboutMenu.style.opacity = '1';
}, 10);
document.body.style.overflow = 'hidden';
};
// Show about menu
document.body.classList.add("no-scroll");
aboutOverlay.style.display = 'flex';
setTimeout(() => {
aboutOverlay.style.opacity = '1';
}, 10);
const hideMenu = () => {
document.body.classList.remove("no-scroll");
aboutOverlay.style.opacity = '0';
aboutMenu.style.opacity = '0';
setTimeout(() => {
aboutOverlay.style.display = 'none';
document.body.style.overflow = 'auto';
}, 200);
};
showMenu();
closeAbout.addEventListener('click', (event) => {
event.stopPropagation();
hideMenu();
});
closeAbout.addEventListener("click", hideMenu);
aboutOverlay.addEventListener('click', (event) => {
if (!aboutMenu.contains(event.target)) {
hideMenu();
}
if (event.target === aboutOverlay) hideMenu();
});
menu.addEventListener('click', (event) => event.stopPropagation());
});
// Event listener for link redirect
+12 -18
View File
@@ -1,7 +1,6 @@
import { execCommand, showPrompt } from './main.js';
const bootHashOverlay = document.getElementById('boot-hash-overlay');
const card = document.getElementById('boot-hash-card');
const inputBox = document.getElementById('boot-hash-input');
const saveButton = document.getElementById('boot-hash-save-button');
@@ -12,25 +11,20 @@ window.trimInput = (input) => {
// Function to handle Verified Boot Hash
document.getElementById("boot-hash").addEventListener("click", async () => {
const showCard = () => {
bootHashOverlay.style.display = "flex";
card.style.display = "flex";
requestAnimationFrame(() => {
bootHashOverlay.classList.add("show");
card.classList.add("show");
});
document.body.style.overflow = "hidden";
};
const closeCard = () => {
bootHashOverlay.classList.remove("show");
card.classList.remove("show");
// Display boot hash menu
document.body.classList.add("no-scroll");
bootHashOverlay.style.display = "flex";
setTimeout(() => {
bootHashOverlay.style.opacity = 1;
}, 10);
const closeBootHashMenu = () => {
document.body.classList.remove("no-scroll");
bootHashOverlay.style.opacity = 0;
setTimeout(() => {
bootHashOverlay.style.display = "none";
card.style.display = "none";
document.body.style.overflow = "auto";
}, 200);
};
showCard();
try {
const bootHashContent = await execCommand("cat /data/adb/boot_hash");
const validHash = bootHashContent
@@ -50,14 +44,14 @@ document.getElementById("boot-hash").addEventListener("click", async () => {
resetprop -n ro.boot.vbmeta.digest ${inputValue}
`);
showPrompt("prompt.boot_hash_set");
closeCard();
closeBootHashMenu();
} catch (error) {
console.error("Failed to update boot_hash:", error);
showPrompt("prompt.boot_hash_set_error", false);
}
});
bootHashOverlay.addEventListener("click", (event) => {
if (event.target === bootHashOverlay) closeCard();
if (event.target === bootHashOverlay) closeBootHashMenu();
});
// Enter to save
+5 -8
View File
@@ -1,21 +1,18 @@
const helpButton = document.getElementById('help-button');
const helpOverlay = document.getElementById('help-overlay');
const closeHelp = document.getElementById('close-help');
const helpList = document.getElementById('help-list');
// Open help menu
helpButton.addEventListener("click", () => {
helpOverlay.classList.remove("hide");
helpOverlay.style.display = "flex";
requestAnimationFrame(() => {
helpOverlay.classList.add("show");
});
document.body.classList.add("no-scroll");
helpOverlay.style.display = "flex";
setTimeout(() => {
helpOverlay.style.opacity = 1;
}, 10);
});
const hideHelpOverlay = () => {
helpOverlay.classList.remove("show");
helpOverlay.classList.add("hide");
helpOverlay.style.opacity = 0;
document.body.classList.remove("no-scroll");
setTimeout(() => {
helpOverlay.style.display = "none";
+1 -1
View File
@@ -214,7 +214,7 @@ async function checkMMRL() {
MMRL_API = true;
} catch (error) {
console.error('Permission check failed:', error);
permissionPopup.classList.remove('hidden');
permissionPopup.style.display('flex');
MMRL_API = false;
}
}
+3 -10
View File
@@ -234,9 +234,11 @@ document.getElementById("validkb").addEventListener("click", async () => {
});
});
// File selector
const fileSelector = document.querySelector('.file-selector-overlay');
let currentPath = '/storage/emulated/0/Download';
// Function to display file in current path
function updateCurrentPath() {
const currentPathElement = document.querySelector('.current-path');
const segments = currentPath.split('/').filter(Boolean);
@@ -281,17 +283,8 @@ async function listFiles(path, skipAnimation = false) {
<span>..</span>
`;
backItem.addEventListener('click', async () => {
currentPath = currentPath.split('/').slice(0, -1).join('/');
if (currentPath === '') currentPath = '/storage/emulated/0';
const currentPathElement = document.querySelector('.current-path');
currentPathElement.innerHTML = currentPath.split('/').filter(Boolean).join('<span class="separator"></span>');
currentPathElement.scrollTo({
left: currentPathElement.scrollWidth,
behavior: 'smooth'
});
await listFiles(currentPath);
document.querySelector('.back-button').click();
});
fileList.appendChild(backItem);
}
items.forEach(item => {
+1 -1
View File
@@ -3,7 +3,7 @@ import { updateCard } from './applist.js';
const updateCardText = document.getElementById('redirect-to-release');
const UpdateMenu = document.querySelector('.update-overlay');
const closeUpdate = document.querySelector('.close-update');
const closeUpdate = document.getElementById('close-update');
const releaseNotes = document.querySelector('.changelog');
const installButton = document.querySelector('.install');
const rebootButton = document.querySelector('.reboot');