feat: add mirror link fallback

- mostly mean for China user, possible to use all feature except module update
This commit is contained in:
KOWX712
2025-04-06 22:58:49 +08:00
parent 6b15a09381
commit 92e654614e
2 changed files with 46 additions and 35 deletions

View File

@@ -42,11 +42,16 @@ document.getElementById("deselect-unnecessary").addEventListener("click", async
try { try {
const excludeList = await fetch("https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-exclude.json") const excludeList = await fetch("https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-exclude.json")
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json(); return response.json();
}) })
.catch(async () => {
return fetch("https://raw.gitmirror.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-exclude.json")
.then(response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response.json();
});
})
.then(data => { .then(data => {
return data.data return data.data
.flatMap(category => category.apps) .flatMap(category => category.apps)
@@ -205,35 +210,40 @@ document.getElementById("aospkb").addEventListener("click", async () => {
// Function to replace valid kb // Function to replace valid kb
document.getElementById("validkb").addEventListener("click", async () => { document.getElementById("validkb").addEventListener("click", async () => {
fetch("https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/.extra") fetch("https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/.extra")
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
throw new Error(`HTTP error! status: ${response.status}`); return response.text();
} })
return response.text(); .catch(async () => {
}) return fetch("https://raw.gitmirror.com/KOWX712/Tricky-Addon-Update-Target-List/main/.extra")
.then(async data => { .then(response => {
if (!data.trim()) { if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
await aospkb(); return response.text();
showPrompt("prompt.no_valid_fallback", false); });
return; })
} .then(async data => {
try { if (!data.trim()) {
const hexBytes = new Uint8Array(data.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); await aospkb();
const decodedHex = new TextDecoder().decode(hexBytes); showPrompt("prompt.no_valid_fallback", false);
const source = atob(decodedHex); return;
const result = await setKeybox(source);
if (result) {
showPrompt("prompt.valid_key_set");
} else {
throw new Error("Failed to copy valid keybox");
} }
} catch (error) { try {
throw new Error("Failed to decode keybox data"); const hexBytes = new Uint8Array(data.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
} const decodedHex = new TextDecoder().decode(hexBytes);
}) const source = atob(decodedHex);
.catch(async error => { const result = await setKeybox(source);
showPrompt("prompt.no_internet", false); if (result) {
}); showPrompt("prompt.valid_key_set");
} else {
throw new Error("Failed to copy valid keybox");
}
} catch (error) {
throw new Error("Failed to decode keybox data");
}
})
.catch(async error => {
showPrompt("prompt.no_internet", false);
});
}); });
// File selector // File selector

View File

@@ -41,10 +41,11 @@ function downloadFile(targetURL, fileName) {
// Function to check for updates // Function to check for updates
export async function updateCheck() { export async function updateCheck() {
try { try {
const response = await fetch("https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/update.json"); const response = await fetch("https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/update.json")
if (!response.ok) { .catch(async () => {
throw new Error(`HTTP error! status: ${response.status}`); return fetch("https://raw.gitmirror.com/KOWX712/Tricky-Addon-Update-Target-List/main/update.json");
} });
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
noConnection.style.display = "none"; noConnection.style.display = "none";
const data = await response.json(); const data = await response.json();
remoteVersionCode = data.versionCode; remoteVersionCode = data.versionCode;