You've already forked Tricky-Addon-Update-Target-List
mirror of
https://github.com/KOWX712/Tricky-Addon-Update-Target-List.git
synced 2025-09-06 06:37:09 +00:00
v2.0
This commit is contained in:
@@ -51,48 +51,118 @@ async function fetchAppList() {
|
||||
async function renderAppList() {
|
||||
await readExcludeFile();
|
||||
const apps = await fetchAppList();
|
||||
apps.forEach(appName => {
|
||||
const sortedApps = apps.sort((a, b) => {
|
||||
const aInExclude = excludeList.includes(a);
|
||||
const bInExclude = excludeList.includes(b);
|
||||
return aInExclude === bInExclude ? a.localeCompare(b) : aInExclude ? 1 : -1;
|
||||
});
|
||||
appListContainer.innerHTML = "";
|
||||
sortedApps.forEach(appName => {
|
||||
const appElement = document.importNode(appTemplate, true);
|
||||
appElement.querySelector(".name").textContent = appName;
|
||||
const checkbox = appElement.querySelector(".checkbox");
|
||||
checkbox.checked = !excludeList.includes(appName); // Deselect if in EXCLUDE
|
||||
checkbox.checked = !excludeList.includes(appName);
|
||||
appListContainer.appendChild(appElement);
|
||||
});
|
||||
}
|
||||
|
||||
// Add button click event to update EXCLUDE file
|
||||
document.getElementById("add").addEventListener("click", async () => {
|
||||
await readExcludeFile();
|
||||
const deselectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:not(:checked)"))
|
||||
.map(checkbox => checkbox.closest(".card").querySelector(".name").textContent);
|
||||
const selectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:checked"))
|
||||
.map(checkbox => checkbox.closest(".card").querySelector(".name").textContent);
|
||||
// Add deselected apps to EXCLUDE if not already present
|
||||
for (const app of deselectedApps) {
|
||||
if (!excludeList.includes(app)) {
|
||||
excludeList.push(app); // Add to the local list
|
||||
console.log("Added to EXCLUDE list:", app);
|
||||
// Function to refresh the app list and clear the search input
|
||||
async function refreshAppList() {
|
||||
const searchInput = document.getElementById("search");
|
||||
searchInput.value = '';
|
||||
const apps = appListContainer.querySelectorAll(".card");
|
||||
apps.forEach(app => app.style.display = "block");
|
||||
await renderAppList();
|
||||
}
|
||||
|
||||
// Function to select all apps
|
||||
function selectAllApps() {
|
||||
document.querySelectorAll(".checkbox").forEach(checkbox => checkbox.checked = true);
|
||||
}
|
||||
|
||||
// Function to deselect all apps
|
||||
function deselectAllApps() {
|
||||
document.querySelectorAll(".checkbox").forEach(checkbox => checkbox.checked = false);
|
||||
}
|
||||
|
||||
let promptTimeout; // Variable to store the current timeout
|
||||
|
||||
// Function to show the prompt with a success or error message
|
||||
function showPrompt(message, isSuccess = true) {
|
||||
const prompt = document.getElementById('prompt');
|
||||
prompt.textContent = message;
|
||||
prompt.classList.toggle('error', !isSuccess); // Apply error class if not success
|
||||
prompt.style.display = 'block';
|
||||
|
||||
if (promptTimeout) {
|
||||
clearTimeout(promptTimeout);
|
||||
}
|
||||
|
||||
promptTimeout = setTimeout(() => {
|
||||
prompt.style.display = 'none';
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
// Function to update the target list by executing a script
|
||||
async function updateTargetList() {
|
||||
try {
|
||||
await execCommand("/data/adb/tricky_store/UpdateTargetList.sh");
|
||||
showPrompt("Successfully updated target.txt");
|
||||
} catch (error) {
|
||||
console.error("Failed to update target list:", error);
|
||||
showPrompt("Failed to update target.txt !", false);
|
||||
}
|
||||
}
|
||||
|
||||
// Menu toggle functionality
|
||||
function setupMenuToggle() {
|
||||
const menuButton = document.getElementById('menu-button');
|
||||
const menuOptions = document.getElementById('menu-options');
|
||||
|
||||
menuButton.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
if (menuOptions.classList.contains('visible')) {
|
||||
closeMenu();
|
||||
} else {
|
||||
console.log("App already in EXCLUDE file, skipping:", app);
|
||||
menuOptions.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
menuOptions.classList.remove('hidden');
|
||||
menuOptions.classList.add('visible');
|
||||
menuButton.classList.add('menu-open');
|
||||
menuButton.classList.remove('menu-closed');
|
||||
}, 10);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
if (!menuOptions.contains(event.target) && event.target !== menuButton) {
|
||||
closeMenu();
|
||||
}
|
||||
});
|
||||
|
||||
const closeMenuItems = ['refresh', 'select-all', 'deselect-all', 'update'];
|
||||
closeMenuItems.forEach(id => {
|
||||
const item = document.getElementById(id);
|
||||
if (item) {
|
||||
item.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
closeMenu();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function closeMenu() {
|
||||
if (menuOptions.classList.contains('visible')) {
|
||||
menuOptions.classList.remove('visible');
|
||||
menuOptions.classList.add('hidden');
|
||||
menuButton.classList.remove('menu-open');
|
||||
menuButton.classList.add('menu-closed');
|
||||
setTimeout(() => {
|
||||
menuOptions.style.display = 'none';
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
// Remove selected apps from EXCLUDE
|
||||
if (selectedApps.length > 0) {
|
||||
selectedApps.forEach(app => {
|
||||
excludeList = excludeList.filter(excludedApp => excludedApp !== app); // Remove from local list
|
||||
console.log("Removed from EXCLUDE list:", app);
|
||||
});
|
||||
}
|
||||
// Overwrite the EXCLUDE file with the updated list
|
||||
try {
|
||||
const updatedExcludeContent = excludeList.join("\n");
|
||||
await execCommand(`echo "${updatedExcludeContent}" > /data/adb/tricky_store/target_list_config/EXCLUDE`);
|
||||
console.log("EXCLUDE file updated successfully.");
|
||||
} catch (error) {
|
||||
console.error("Failed to update EXCLUDE file:", error);
|
||||
}
|
||||
await readExcludeFile();
|
||||
});
|
||||
}
|
||||
|
||||
// Search functionality
|
||||
document.getElementById("search").addEventListener("input", (e) => {
|
||||
@@ -104,5 +174,69 @@ document.getElementById("search").addEventListener("input", (e) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Add button click event to update EXCLUDE file
|
||||
document.getElementById("save").addEventListener("click", async () => {
|
||||
await readExcludeFile();
|
||||
const deselectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:not(:checked)"))
|
||||
.map(checkbox => checkbox.closest(".card").querySelector(".name").textContent);
|
||||
const selectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:checked"))
|
||||
.map(checkbox => checkbox.closest(".card").querySelector(".name").textContent);
|
||||
|
||||
for (const app of deselectedApps) {
|
||||
if (!excludeList.includes(app)) {
|
||||
excludeList.push(app);
|
||||
console.log("Added to EXCLUDE list:", app);
|
||||
} else {
|
||||
console.log("App already in EXCLUDE file, skipping:", app);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedApps.length > 0) {
|
||||
selectedApps.forEach(app => {
|
||||
excludeList = excludeList.filter(excludedApp => excludedApp !== app);
|
||||
console.log("Removed from EXCLUDE list:", app);
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const updatedExcludeContent = excludeList.join("\n");
|
||||
await execCommand(`echo "${updatedExcludeContent}" > /data/adb/tricky_store/target_list_config/EXCLUDE`);
|
||||
console.log("EXCLUDE file updated successfully.");
|
||||
showPrompt("Config saved successfully");
|
||||
} catch (error) {
|
||||
console.error("Failed to update EXCLUDE file:", error);
|
||||
showPrompt("Failed to save config", false);
|
||||
}
|
||||
await readExcludeFile();
|
||||
});
|
||||
|
||||
// Event listener for the "Update Target List" menu option
|
||||
document.getElementById('update').addEventListener('click', updateTargetList);
|
||||
|
||||
// Initial load
|
||||
renderAppList();
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
setupMenuToggle();
|
||||
document.getElementById("refresh").addEventListener("click", refreshAppList);
|
||||
document.getElementById("select-all").addEventListener("click", selectAllApps);
|
||||
document.getElementById("deselect-all").addEventListener("click", deselectAllApps);
|
||||
renderAppList();
|
||||
});
|
||||
|
||||
// Scroll event
|
||||
let lastScrollY = window.scrollY;
|
||||
const title = document.getElementById('title');
|
||||
const searchCard = document.querySelector('.search-card');
|
||||
const menu = document.querySelector('.menu');
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
if (window.scrollY > lastScrollY) {
|
||||
title.style.transform = 'translateY(-100%)';
|
||||
searchCard.style.transform = 'translateY(-40px)';
|
||||
menu.style.transform = 'translateY(-40px)';
|
||||
} else {
|
||||
title.style.transform = 'translateY(0)';
|
||||
searchCard.style.transform = 'translateY(0)';
|
||||
menu.style.transform = 'translateY(0)';
|
||||
}
|
||||
lastScrollY = window.scrollY;
|
||||
});
|
||||
Reference in New Issue
Block a user