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

View File

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