Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

feat: add microshield-token-parser #221

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,4 @@ jobs:
- name: Install dependencies
run: npm i
- name: Run ESLint
run: npm run lint
build:
name: Detect changes
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Set up NodeJS LTS
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Checkout
uses: actions/checkout@v4
- name: Install Dependencies
run: npm i
- name: Build
run: npm run build
- name: Detect changes are applied
run: |
! git diff --stat | grep -E " [A-Za-z0-9-]+\.user\.js"
shell: bash
needs: [eslint]
run: npm run lint\
25 changes: 2 additions & 23 deletions .github/workflows/purgecache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,6 @@ jobs:
run: npm i
- name: Run ESLint
run: npm run lint
build:
name: Detect changes
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Set up NodeJS LTS
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Checkout
uses: actions/checkout@v4
- name: Install Dependencies
run: npm i
- name: Build
run: npm run build
- name: Detect changes are applied
run: |
! git diff --stat | grep -E " [A-Za-z0-9-]+\.user\.js"
shell: bash
needs: [eslint]
release:
name: Create a Release
runs-on: ubuntu-latest
Expand All @@ -59,7 +38,7 @@ jobs:
fetch-depth: 0
- name: Create a Release
uses: List-KR/[email protected]
needs: [eslint, build]
needs: [eslint]
jsdelivrpurge:
name: Purge jsDelivr cache
runs-on: ubuntu-latest
Expand All @@ -77,4 +56,4 @@ jobs:
fetch-depth: 0
- name: Run jsDelivr-Purge
uses: List-KR/[email protected]
needs: [eslint, build, release]
needs: [eslint, release]
27 changes: 27 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import tsPlugin from "@typescript-eslint/eslint-plugin"
import tsParser from "@typescript-eslint/parser"

const config = [
{
files: ["**/*.ts", "**/*.tsx"], // Target TypeScript files
languageOptions: {
parser: tsParser,
sourceType: "module",
},
plugins: {
"@typescript-eslint": tsPlugin,
},
rules: {
...tsPlugin.configs.recommended.rules,
"semi": ["error", "never"],
"quotes": ["error", "single"],
"@typescript-eslint/no-unused-vars": "warn",
'@typescript-eslint/naming-convention': ['error', {
selector: ['variableLike', 'parameterProperty', 'classProperty', 'typeProperty'],
format: ['PascalCase']
}]
}
}
]

export default config
8 changes: 7 additions & 1 deletion microShield-ios-blocker.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// @downloadURL https://cdn.jsdelivr.net/gh/List-KR/microShield@latest/microShield-ios-blocker.user.js
// @license Apache-2.0
//
// @version 4.6.11
// @version 4.7.0
// @author PiQuark6046 and contributors
//
// @match *://ygosu.com/*
Expand Down Expand Up @@ -190,6 +190,12 @@
// @match *://*.onlinegdb.com/*
// @match *://winfuture.de/*
// @match *://*.winfuture.de/*
// @match *//hoyme.jp/*
// @match *//*.hoyme.jp/*
// @match *://pravda.com.ua/*
// @match *://*.pravda.com.ua/*
// @match *://freemcserver.net/*
// @match *://*.freemcserver.net/*
//
// @description microShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield widely.
// @description:ko microShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 널리 저항할 수 있도록 합니다.
Expand Down
30,948 changes: 30,945 additions & 3 deletions microShield-ios-recovery.user.js

Large diffs are not rendered by default.

30,952 changes: 30,947 additions & 5 deletions microShield.user.js

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microshield",
"version": "4.6.11",
"version": "4.7.0",
"description": "",
"type": "module",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"bundle:iosblocker": "esbuild sources/src/index-ios-blocker.ts --bundle --minify-whitespace --minify-syntax --define:global=window --inject:./sources/esbuild.inject.ts --banner:js=\"$(cat ./sources/banner-ios-blocker.txt)\" --target=es2022,chrome109,safari16,firefox115 --outfile=./microShield-ios-blocker.user.js",
"bundle:iosrecovery": "esbuild sources/src/index-ios-recovery.ts --bundle --minify-whitespace --minify-syntax --define:global=window --inject:./sources/esbuild.inject.ts --banner:js=\"$(cat ./sources/banner-ios-recovery.txt)\" --target=es2022,chrome109,safari16,firefox115 --outfile=./microShield-ios-recovery.user.js",
"debug": "esbuild sources/src/index.ts --bundle --define:global=window --inject:./sources/esbuild.inject.ts --banner:js=\"$(cat ./sources/banner.txt)\" --target=es2022,chrome109,safari16,firefox115 --outfile=./microShield-debug.user.js",
"lint": "tsc && eslint sources --ext .ts"
"lint": "tsc --noEmit && eslint sources"
},
"keywords": [],
"author": {
Expand All @@ -36,18 +36,16 @@
],
"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"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"esbuild": "^0.21.3",
"eslint": "^8.57.0",
"eslint": "^9.9.0",
"pnpm": "^9.1.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.10.0"
"typescript": "^5.5.4",
"typescript-eslint": "^8.1.0"
}
}
28 changes: 0 additions & 28 deletions sources/.eslintrc.cjs

This file was deleted.

8 changes: 7 additions & 1 deletion sources/banner-ios-blocker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// @downloadURL https://cdn.jsdelivr.net/gh/List-KR/microShield@latest/microShield-ios-blocker.user.js
// @license Apache-2.0
//
// @version 4.6.11
// @version 4.7.0
// @author PiQuark6046 and contributors
//
// @match *://ygosu.com/*
Expand Down Expand Up @@ -190,6 +190,12 @@
// @match *://*.onlinegdb.com/*
// @match *://winfuture.de/*
// @match *://*.winfuture.de/*
// @match *//hoyme.jp/*
// @match *//*.hoyme.jp/*
// @match *://pravda.com.ua/*
// @match *://*.pravda.com.ua/*
// @match *://freemcserver.net/*
// @match *://*.freemcserver.net/*
//
// @description microShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield widely.
// @description:ko microShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 널리 저항할 수 있도록 합니다.
Expand Down
12 changes: 11 additions & 1 deletion sources/banner-ios-recovery.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// @downloadURL https://cdn.jsdelivr.net/gh/List-KR/microShield@latest/microShield-ios-recovery.user.js
// @license Apache-2.0
//
// @version 4.6.11
// @version 4.7.0
// @author PiQuark6046 and contributors
//
// @match *://ygosu.com/*
Expand Down Expand Up @@ -190,12 +190,22 @@
// @match *://*.onlinegdb.com/*
// @match *://winfuture.de/*
// @match *://*.winfuture.de/*
// @match *//hoyme.jp/*
// @match *//*.hoyme.jp/*
// @match *://pravda.com.ua/*
// @match *://*.pravda.com.ua/*
// @match *://freemcserver.net/*
// @match *://*.freemcserver.net/*
//
// @description microShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield widely.
// @description:ko microShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 널리 저항할 수 있도록 합니다.
// @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:
Expand Down
12 changes: 11 additions & 1 deletion sources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// @downloadURL https://cdn.jsdelivr.net/gh/List-KR/microShield@latest/microShield.user.js
// @license Apache-2.0
//
// @version 4.6.11
// @version 4.7.0
// @author PiQuark6046 and contributors
//
// @match *://ygosu.com/*
Expand Down Expand Up @@ -190,12 +190,22 @@
// @match *://*.onlinegdb.com/*
// @match *://winfuture.de/*
// @match *://*.winfuture.de/*
// @match *//hoyme.jp/*
// @match *//*.hoyme.jp/*
// @match *://pravda.com.ua/*
// @match *://*.pravda.com.ua/*
// @match *://freemcserver.net/*
// @match *://*.freemcserver.net/*
//
// @description microShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield widely.
// @description:ko microShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 널리 저항할 수 있도록 합니다.
// @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:
Expand Down
2 changes: 1 addition & 1 deletion sources/src/GM.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
export type GM = {
getValue(key: string, defaultValue: undefined): Promise<string | undefined>
getValue<T>(key: string, defaultValue: T): Promise<string | T>
setValue(key: string, value: string): Promise<void>
deleteValue(key: string): Promise<void>
listValues(): Promise<string[]>
Expand Down
17 changes: 14 additions & 3 deletions sources/src/adshield/resources.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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]
Expand All @@ -49,13 +61,12 @@ export const ResolveResourceUrls = async (Html: string, Token: string) => {
const Host = GetRandomAdShieldHost()

let NewHtml = ''
// eslint-disable-next-line @typescript-eslint/ban-types
let Matches: RegExpExecArray | null = null

while ((Matches = Pattern.exec(Html)) !== null) {
const Url = 'https://' + Host + '/resources/' + Matches[1].slice(12 /* 'resources://'.length */) + '?token=' + Token

// eslint-disable-next-line no-await-in-loop
NewHtml += await GetCachableHtml(Url)
.catch(Errors => {
console.error(Errors)
Expand Down
2 changes: 1 addition & 1 deletion sources/src/adshield/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const AdshieldKeywords = [

const AdshieldDomainsize = AdshieldHostableDomains.length

// eslint-disable-next-line no-bitwise
export const GetRandomAdShieldHost = () => AdshieldHostableDomains[(Number(cryptoRandomString({length: 16, type: 'numeric'})) * 0.0000000000000001 * AdshieldDomainsize) >>> 0]

export const IsAdShieldCall = (Trace = JustifyCallStack()) => {
Expand Down
2 changes: 1 addition & 1 deletion sources/src/index-ios-blocker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AdshieldKeywords} from './adshield/validators.js'
import {Tinywave} from './loaders/ztinywave.js'

Check warning on line 2 in sources/src/index-ios-blocker.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'Tinywave' is defined but never used

Check warning on line 2 in sources/src/index-ios-blocker.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'Tinywave' is defined but never used
import {BaseDrop} from './loaders/basedrop.js'

Check warning on line 3 in sources/src/index-ios-blocker.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'BaseDrop' is defined but never used

Check warning on line 3 in sources/src/index-ios-blocker.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'BaseDrop' is defined but never used
import {DocumentReady} from './utils/frame.js'
import {CreateDebug} from './utils/logger.js'
import {ProtectFunctionDescriptors} from './utils/secret.js'
Expand All @@ -12,7 +12,7 @@
declare const unsafeWindow: unsafeWindow

const Hook = () => {
// eslint-disable-next-line no-negated-condition
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window

// Pollusions
Expand Down
5 changes: 3 additions & 2 deletions sources/src/index-ios-recovery.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {AdshieldKeywords} from './adshield/validators.js'
import {Tinywave} from './loaders/ztinywave.js'
import {BaseDrop} from './loaders/basedrop.js'
import {DocumentReady} from './utils/frame.js'

Check warning on line 4 in sources/src/index-ios-recovery.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'DocumentReady' is defined but never used

Check warning on line 4 in sources/src/index-ios-recovery.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'DocumentReady' is defined but never used
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
declare const unsafeWindow: unsafeWindow

const Hook = () => {

Check warning on line 15 in sources/src/index-ios-recovery.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'Hook' is assigned a value but never used

Check warning on line 15 in sources/src/index-ios-recovery.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'Hook' is assigned a value but never used
// eslint-disable-next-line no-negated-condition
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window

// Pollusions
Expand Down Expand Up @@ -51,7 +52,7 @@
ProtectFunctionDescriptors(Win, 'fetch', {CheckArguments: true})
}

const Observe = () => {

Check warning on line 55 in sources/src/index-ios-recovery.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'Observe' is assigned a value but never used

Check warning on line 55 in sources/src/index-ios-recovery.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'Observe' is assigned a value but never used
const Debug = CreateDebug('observe')
const Observer = new MutationObserver(Mutations => {
for (const Mutation of Mutations) {
Expand Down Expand Up @@ -82,5 +83,5 @@
// Observe()
// })
}

CheckVersion()
Bootstrap()
4 changes: 3 additions & 1 deletion sources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ 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
declare const unsafeWindow: unsafeWindow

const Hook = () => {
// eslint-disable-next-line no-negated-condition
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window

// Pollusions
Expand Down Expand Up @@ -83,4 +84,5 @@ const Bootstrap = () => {
})
}

CheckVersion()
Bootstrap()
Loading
Loading