diff --git a/package.json b/package.json index 4c04f6e..94dfca3 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ ], "license": "Apache-2.0", "dependencies": { + "@list-kr/microshield-token-parser": "^1.0.2", "@types/node": "^20.12.12", "crypto-random-string": "^5.0.0", "parse-domain": "^8.0.2" diff --git a/sources/banner-ios-recovery.txt b/sources/banner-ios-recovery.txt index e1ef3dc..97a5fbe 100644 --- a/sources/banner-ios-recovery.txt +++ b/sources/banner-ios-recovery.txt @@ -196,6 +196,10 @@ // @description:ja microShieldはAdGuard、uBlock Origin、Brave、ABPの環境でAd-Shieldを広範囲に回避します。 // // @grant GM.xmlHttpRequest +// @grant GM.getValue +// @grant GM.setValue +// @grant GM.listValues +// @grant GM.deleteValue // @run-at document-end // ==/UserScript== // Original Srouce Code: diff --git a/sources/banner.txt b/sources/banner.txt index 49c1375..c9059a8 100644 --- a/sources/banner.txt +++ b/sources/banner.txt @@ -196,6 +196,10 @@ // @description:ja microShieldはAdGuard、uBlock Origin、Brave、ABPの環境でAd-Shieldを広範囲に回避します。 // // @grant GM.xmlHttpRequest +// @grant GM.getValue +// @grant GM.setValue +// @grant GM.listValues +// @grant GM.deleteValue // @run-at document-start // ==/UserScript== // Original Srouce Code: diff --git a/sources/src/GM.ts b/sources/src/GM.ts index 3d4bab5..c92b95e 100644 --- a/sources/src/GM.ts +++ b/sources/src/GM.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ export type GM = { - getValue(key: string, defaultValue: undefined): Promise + getValue(key: string, defaultValue: T): Promise setValue(key: string, value: string): Promise deleteValue(key: string): Promise listValues(): Promise diff --git a/sources/src/adshield/resources.ts b/sources/src/adshield/resources.ts index 47806f7..fafd9a7 100644 --- a/sources/src/adshield/resources.ts +++ b/sources/src/adshield/resources.ts @@ -1,6 +1,7 @@ import {UnprotectedFetch} from '../utils/secret.js' import {GetRandomAdShieldHost} from './validators.js' import type {GM} from '../GM.js' +import { AdvancedExtractor } from '@list-kr/microshield-token-parser' declare const GM: GM @@ -27,7 +28,18 @@ export const GetResourceToken = async (ScriptUrl: string) => { if (Match === null) { const ResponseHash = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-1', new TextEncoder().encode(Text)))).map(Block =>Block.toString(16).padStart(2, '0')).join('') - return await GetResourceTokenFromCDN(ResponseHash) + try { + return await GetResourceTokenFromCDN(ResponseHash) + } + catch { + if (await GM.getValue(ResponseHash, null) === null) { + const Token = new AdvancedExtractor(Text).GetToken() + await GM.setValue(ResponseHash, Token) + return Token + } else { + return await GM.getValue(ResponseHash, null) + } + } } return Match[0] diff --git a/sources/src/index-ios-recovery.ts b/sources/src/index-ios-recovery.ts index 5fc6e9a..279fbe3 100644 --- a/sources/src/index-ios-recovery.ts +++ b/sources/src/index-ios-recovery.ts @@ -6,6 +6,7 @@ import {CreateDebug} from './utils/logger.js' import {ProtectFunctionDescriptors} from './utils/secret.js' import {ProtectStorageApis} from './utils/storage.js' import {HasSubstringSetsInString} from './utils/string.js' +import { CheckVersion } from './utils/ucache.js' type unsafeWindow = typeof window // eslint-disable-next-line @typescript-eslint/naming-convention @@ -82,5 +83,5 @@ const Bootstrap = () => { // Observe() // }) } - +CheckVersion() Bootstrap() \ No newline at end of file diff --git a/sources/src/index.ts b/sources/src/index.ts index ec85fba..7232c25 100644 --- a/sources/src/index.ts +++ b/sources/src/index.ts @@ -6,6 +6,7 @@ import {CreateDebug} from './utils/logger.js' import {ProtectFunctionDescriptors} from './utils/secret.js' import {ProtectStorageApis} from './utils/storage.js' import {HasSubstringSetsInString} from './utils/string.js' +import { CheckVersion } from './utils/ucache.js' type unsafeWindow = typeof window // eslint-disable-next-line @typescript-eslint/naming-convention @@ -83,4 +84,5 @@ const Bootstrap = () => { }) } +CheckVersion() Bootstrap() \ No newline at end of file diff --git a/sources/src/utils/ucache.ts b/sources/src/utils/ucache.ts new file mode 100644 index 0000000..c0840a2 --- /dev/null +++ b/sources/src/utils/ucache.ts @@ -0,0 +1,14 @@ +import type {GM} from '../GM.js' + +declare const GM: GM + +export async function CheckVersion() { + if (await GM.getValue('version', null) === null) { + await GM.setValue('version', GM.info.script.version) + } else if (await GM.getValue('version', null) !== GM.info.script.version) { + for (const Key of await GM.listValues()) { + await GM.deleteValue(Key) + } + await GM.setValue('version', GM.info.script.version) + } +} \ No newline at end of file