import { basePath, execCommand, showPrompt, toast, applyRippleEffect } from './main.js'; // Function to check or uncheck all app function toggleCheckboxes(shouldCheck) { document.querySelectorAll(".card").forEach(card => { if (card.style.display !== "none") { card.querySelector(".checkbox").checked = shouldCheck; } }); } // Function to select all visible apps document.getElementById("select-all").addEventListener("click", () => toggleCheckboxes(true)); // Function to deselect all visible apps document.getElementById("deselect-all").addEventListener("click", () => toggleCheckboxes(false)); // Function to read the denylist and check corresponding apps document.getElementById("select-denylist").addEventListener("click", async () => { try { const result = await execCommand(`magisk --denylist ls 2>/dev/null | awk -F'|' '{print $1}' | grep -v "isolated" | sort -u`); const denylistApps = result.split("\n").map(app => app.trim()).filter(Boolean); const apps = document.querySelectorAll(".card"); apps.forEach(app => { const contentElement = app.querySelector(".content"); const packageName = contentElement.getAttribute("data-package"); const checkbox = app.querySelector(".checkbox"); if (denylistApps.includes(packageName)) { checkbox.checked = true; } }); await execCommand('touch "/data/adb/tricky_store/target_from_denylist"'); console.log("Denylist apps selected successfully."); } catch (error) { toast("Failed to read DenyList!"); console.error("Failed to select Denylist apps:", error); } }); // Function to read the exclude list and uncheck corresponding apps document.getElementById("deselect-unnecessary").addEventListener("click", async () => { try { const fileCheck = await execCommand(`test -f ${basePath}common/tmp/exclude-list && echo "exists" || echo "not found"`); if (fileCheck.trim() === "not found") { setTimeout(async () => { await execCommand(`sh ${basePath}common/get_extra.sh --unnecessary`); }, 0); console.log("Exclude list not found. Running the unnecessary apps script."); } else { setTimeout(async () => { await execCommand(`sh ${basePath}common/get_extra.sh --xposed`); }, 0); console.log("Exclude list found. Running xposed script."); } await new Promise(resolve => setTimeout(resolve, 100)); const result = await execCommand(`cat ${basePath}common/tmp/exclude-list`); const UnnecessaryApps = result.split("\n").map(app => app.trim()).filter(Boolean); const apps = document.querySelectorAll(".card"); apps.forEach(app => { const contentElement = app.querySelector(".content"); const packageName = contentElement.getAttribute("data-package"); const checkbox = app.querySelector(".checkbox"); if (UnnecessaryApps.includes(packageName)) { checkbox.checked = false; } }); console.log("Unnecessary apps deselected successfully."); } catch (error) { toast("Failed!"); console.error("Failed to deselect unnecessary apps:", error); } }); // Function to replace aosp kb export async function aospkb() { try { const sourcePath = `${basePath}common/.default`; const destinationPath = "/data/adb/tricky_store/keybox.xml"; await execCommand(`mv -f ${destinationPath} ${destinationPath}.bak && xxd -r -p ${sourcePath} | base64 -d > ${destinationPath}`); console.log("AOSP keybox copied successfully."); showPrompt("prompt.aosp_key_set"); } catch (error) { console.error("Failed to copy AOSP keybox:", error); showPrompt("prompt.key_set_error", false); } } // Function to replace valid kb document.getElementById("validkb").addEventListener("click", async () => { setTimeout(async () => { await execCommand(`sh ${basePath}common/get_extra.sh --kb`); }, 100); const sourcePath = `${basePath}common/tmp/.extra`; const destinationPath = "/data/adb/tricky_store/keybox.xml"; try { await new Promise(resolve => setTimeout(resolve, 300)); const fileExists = await execCommand(`[ -f ${sourcePath} ] && echo "exists"`); if (fileExists.trim() !== "exists") { throw new Error(".extra file not found"); } await execCommand(`mv -f ${destinationPath} ${destinationPath}.bak && xxd -r -p ${sourcePath} | base64 -d > ${destinationPath}`); console.log("Valid keybox copied successfully."); showPrompt("prompt.valid_key_set"); } catch (error) { console.error("Failed to copy valid keybox:", error); await aospkb(); showPrompt("prompt.no_valid_fallback", false); } }); // Add file selector dialog elements dynamically const fileSelector = document.createElement('div'); fileSelector.className = 'file-selector-overlay'; fileSelector.innerHTML = `
/storage/emulated/0/Download
`; document.body.appendChild(fileSelector); // Add styles for animations const style = document.createElement('style'); style.textContent = ` .file-selector-overlay { transition: opacity 0.3s ease; opacity: 0; } .file-selector-overlay.visible { opacity: 1; } .file-list { transition: transform 0.3s ease, opacity 0.3s ease; } .file-list.switching { transform: scale(0.95); opacity: 0; } `; document.head.appendChild(style); let currentPath = '/storage/emulated/0/Download'; function updateCurrentPath() { const currentPathElement = document.querySelector('.current-path'); const segments = currentPath.split('/').filter(Boolean); // Create spans with data-path attribute for each segment const pathHTML = segments.map((segment, index) => { const fullPath = '/' + segments.slice(0, index + 1).join('/'); return `${segment}`; }).join(''); currentPathElement.innerHTML = pathHTML; currentPathElement.scrollTo({ left: currentPathElement.scrollWidth, behavior: 'smooth' }); } // Function to list files in directory async function listFiles(path, skipAnimation = false) { const fileList = document.querySelector('.file-list'); if (!skipAnimation) { fileList.classList.add('switching'); await new Promise(resolve => setTimeout(resolve, 150)); } try { const result = await execCommand(`find "${path}" -maxdepth 1 -type f -name "*.xml" -o -type d ! -name ".*" | sort`); const items = result.split('\n').filter(Boolean).map(item => ({ path: item, name: item.split('/').pop(), isDirectory: !item.endsWith('.xml') })); fileList.innerHTML = ''; // Add back button item if not in root directory if (currentPath !== '/storage/emulated/0') { const backItem = document.createElement('div'); backItem.className = 'file-item'; backItem.innerHTML = ` .. `; 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(''); currentPathElement.scrollTo({ left: currentPathElement.scrollWidth, behavior: 'smooth' }); await listFiles(currentPath); }); fileList.appendChild(backItem); } items.forEach(item => { if (item.path === path) return; const itemElement = document.createElement('div'); itemElement.className = 'file-item'; itemElement.innerHTML = ` ${item.isDirectory ? '' : ''} ${item.name} `; itemElement.addEventListener('click', async () => { if (item.isDirectory) { currentPath = item.path; const currentPathElement = document.querySelector('.current-path'); currentPathElement.innerHTML = currentPath.split('/').filter(Boolean).join(''); currentPathElement.scrollTo({ left: currentPathElement.scrollWidth, behavior: 'smooth' }); await listFiles(item.path); } else { try { const content = await execCommand(`cat "${item.path}"`); await execCommand(`mv -f /data/adb/tricky_store/keybox.xml /data/adb/tricky_store/keybox.xml.bak 2>/dev/null && echo '${content}' > /data/adb/tricky_store/keybox.xml`); fileSelector.style.display = 'none'; showPrompt('prompt.custom_key_set'); } catch (error) { console.error('Error processing file:', error); showPrompt('prompt.custom_key_set_error'); } } }); fileList.appendChild(itemElement); }); if (!skipAnimation) { fileList.classList.remove('switching'); } } catch (error) { console.error('Error listing files:', error); if (!skipAnimation) { fileList.classList.remove('switching'); } } applyRippleEffect(); updateCurrentPath(); } // Update click handler to use data-path attribute document.querySelector('.current-path').addEventListener('click', async (event) => { const segment = event.target.closest('.path-segment'); if (!segment) return; const targetPath = segment.dataset.path; if (!targetPath || targetPath === currentPath) return; // Return if already at /storage/emulated/0 const clickedSegment = segment.textContent; if ((clickedSegment === 'storage' || clickedSegment === 'emulated') && currentPath === '/storage/emulated/0') { return; } // Always stay within /storage/emulated/0 if (targetPath.split('/').length <= 3) { currentPath = '/storage/emulated/0'; } else { currentPath = targetPath; } updateCurrentPath(); await listFiles(currentPath); }); // Back button handler document.querySelector('.back-button').addEventListener('click', async () => { if (currentPath === '/storage/emulated/0') return; 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(''); currentPathElement.scrollTo({ left: currentPathElement.scrollWidth, behavior: 'smooth' }); await listFiles(currentPath); }); // Close custom keybox selector document.querySelector('.close-selector').addEventListener('click', () => { fileSelector.classList.remove('visible'); document.body.classList.remove("no-scroll"); setTimeout(() => { fileSelector.style.display = 'none'; }, 300); }); fileSelector.addEventListener('click', (event) => { if (event.target === fileSelector) { fileSelector.classList.remove('visible'); document.body.classList.remove("no-scroll"); setTimeout(() => { fileSelector.style.display = 'none'; }, 300); } }); // Open custom keybox selector document.getElementById('customkb').addEventListener('click', async () => { fileSelector.style.display = 'flex'; document.body.classList.add("no-scroll"); fileSelector.offsetHeight; fileSelector.classList.add('visible'); currentPath = '/storage/emulated/0/Download'; const currentPathElement = document.querySelector('.current-path'); currentPathElement.innerHTML = currentPath.split('/').filter(Boolean).join(''); currentPathElement.scrollTo({ left: currentPathElement.scrollWidth, behavior: 'smooth' }); await listFiles(currentPath, true); });