Add functions to bypass websites that are redirected to (looking at you voe)

This commit is contained in:
bytedream 2022-07-13 00:45:52 +02:00
parent 672b920f31
commit 4cf76eb62a
9 changed files with 68 additions and 89 deletions

16
src/background.ts Normal file
View File

@ -0,0 +1,16 @@
import {getMatch} from "./match/match";
import {storageGet, storageSet} from "./store/store";
import {Match} from "./match/matches";
chrome.webRequest.onBeforeRedirect.addListener(async details => {
// check if redirects origins from a previous redirect
if (await storageGet('redirect') === undefined) {
let match: Match
if ((match = await getMatch(new URL(details.url).host)) !== undefined) {
await storageSet('redirect', match.id)
}
}
}, {
urls: ['<all_urls>'],
types: ['main_frame', 'sub_frame']
})

View File

@ -1,24 +1,26 @@
import {matches} from "./match/match"; import {getMatch} from "./match/match";
import {getAllDisabled, getDisabled} from "./store/store"; import {storageDelete, storageGet} from "./store/store";
import {Match, matches} from "./match/matches";
async function main() { async function main() {
if (await getAllDisabled()) { let match: Match;
if ((match = await getMatch(window.location.host)) === undefined) {
let id: string
if ((id = await storageGet('redirect')) !== undefined) {
match = matches.find(m => m.id === id)
await storageDelete('redirect')
} else {
return
}
}
const re = document.body.innerHTML.match(match.regex)
if (re === null) {
return return
} }
for (const match of matches) { const url = await match.match(re)
if (!match.domains.some((v) => window.location.host.indexOf(v) !== -1) || ((await getDisabled()).some((v) => v === match))) { location.assign(chrome.runtime.getURL(`ui/player/player.html?id=${match.id}&url=${encodeURIComponent(url)}`))
continue
}
const re = document.body.innerHTML.match(match.regex)
if (re === null) {
continue
}
const url = await match.match(re)
location.assign(chrome.runtime.getURL(`ui/player/player.html?id=${match.id}&url=${encodeURIComponent(url)}`))
}
} }
main() main()

View File

@ -14,21 +14,7 @@
{ {
"all_frames": true, "all_frames": true,
"matches": [ "matches": [
"*://*.evoload.io/*", "<all_urls>"
"*://*.mixdrop.co/*",
"*://*.newgrounds.com/*",
"*://*.streamtape.com/*",
"*://*.streamzz.to/*",
"*://*.streamz.ws/*",
"*://*.upstream.to/*",
"*://*.vidlox.me/*",
"*://*.vidoza.net/*",
"*://*.vivo.sx/*",
"*://*.voe.sx/*",
"*://*.voeunblk.com/*",
"*://*.voeun-block.net/*",
"*://*.un-block-voe.net/*",
"*://*.vupload.com/*"
], ],
"js": [ "js": [
"index.js" "index.js"
@ -36,8 +22,15 @@
"run_at": "document_end" "run_at": "document_end"
} }
], ],
"background": {
"scripts": [
"background.js"
]
},
"permissions": [ "permissions": [
"storage" "storage",
"webRequest",
"<all_urls>"
], ],
"browser_action": { "browser_action": {
"default_icon": { "default_icon": {

14
src/match/match.ts Normal file
View File

@ -0,0 +1,14 @@
import {Match, matches} from "./matches";
import {getAllDisabled, getDisabled} from "../store/store";
export async function getMatch(host: string): Promise<Match | undefined> {
if (await getAllDisabled()) {
return undefined
}
for (const match of matches) {
if (match.domains.some(v => host.indexOf(v) !== -1) && !((await getDisabled()).some(v => v === match))) {
return match
}
}
}

View File

@ -192,10 +192,7 @@ class Voe implements Match {
id = 'voe' id = 'voe'
reliability = Reliability.HIGH reliability = Reliability.HIGH
domains = [ domains = [
'voe.sx', 'voe.sx'
'voeunblk.com',
'voeun-block.net',
'un-block-voe.net'
] ]
regex = new RegExp(/https?:\/\/\S*m3u8(?=")/gm) regex = new RegExp(/https?:\/\/\S*m3u8(?=")/gm)

View File

@ -1,6 +1,6 @@
import {Match, matches} from "../match/match"; import {Match, matches} from "../match/matches";
async function storageGet(key: string): Promise<any> { export async function storageGet(key: string): Promise<any> {
return new Promise((resolve) => { return new Promise((resolve) => {
chrome.storage.local.get(key, (value) => { chrome.storage.local.get(key, (value) => {
resolve(value[key]) resolve(value[key])
@ -8,12 +8,16 @@ async function storageGet(key: string): Promise<any> {
}) })
} }
async function storageSet(key: string, value: any) { export async function storageSet(key: string, value: any) {
const obj = {} const obj = {}
obj[key] = value obj[key] = value
await chrome.storage.local.set(obj) await chrome.storage.local.set(obj)
} }
export async function storageDelete(key: string) {
await chrome.storage.local.remove(key)
}
export async function getDisabled(): Promise<Match[]> { export async function getDisabled(): Promise<Match[]> {
const localMatches = [] const localMatches = []

View File

@ -1,4 +1,4 @@
import {Match, matches, Reliability} from "../../match/match"; import {Match, matches, Reliability} from "../../match/matches";
// @ts-ignore // @ts-ignore
import Hls from "hls.js"; import Hls from "hls.js";

View File

@ -1,5 +1,5 @@
import {getDisabled, disable, enable, getAllDisabled, enableAll, disableAll} from "../../store/store"; import {getDisabled, disable, enable, getAllDisabled, enableAll, disableAll} from "../../store/store";
import {matches, Reliability} from "../../match/match"; import {matches, Reliability} from "../../match/matches";
async function main() { async function main() {
const disabled = await getDisabled() const disabled = await getDisabled()

View File

@ -9,59 +9,11 @@ const sass = require('node-sass')
const sassPluginNodeImport = require('node-sass-package-importer') const sassPluginNodeImport = require('node-sass-package-importer')
const typescript = require('typescript') const typescript = require('typescript')
function getDomains() {
// because nodejs is nodejs, the simple commented out code below cannot be used.
// thus, the following bloated regexes must be used
/*const manifestMatches = []
for (const m of matches) {
for (const domain of m.domains) {
manifestMatches.push(`*://*.${domain}/*`)
}
}
manifest['content_scripts']['matches'] = manifestMatches*/
let domains = []
const matchesRegex = new RegExp(/export\s+const\s+matches\s+=\s+(?<matches>\[.*?])/gms)
const matchesClassesRegex = new RegExp(/(?<!\/\/\s*)new\s+(?<class>\w+)\(\)/gms)
const matchTs = fs.readFileSync('src/match/matches.ts')
const jsMatches = matchesRegex.exec(matchTs).groups.matches
let m
while ((m = matchesClassesRegex.exec(jsMatches))) {
if (m.index === matchesClassesRegex.lastIndex) {
matchesClassesRegex.lastIndex++
}
if (m.groups.class !== undefined) {
const classDomainsRegex = new RegExp('class\\s+' + m.groups.class + '.*?domains\\s*=\\s*(?<domains>\\[.*?])', 'gms')
let mm
while ((mm = classDomainsRegex.exec(matchTs))) {
if (mm.index === classDomainsRegex.lastIndex) {
classDomainsRegex.lastIndex++
}
if (mm.groups.domains !== undefined) {
const matches = []
for (const domain of JSON.parse(mm.groups.domains.replace(/'/g, '"', -1))) {
matches.push(domain)
}
domains = domains.concat(matches)
}
}
}
}
return domains
}
async function buildManifest() { async function buildManifest() {
const manifest = JSON.parse(fs.readFileSync('src/manifest.json')) const manifest = JSON.parse(fs.readFileSync('src/manifest.json'))
manifest['version'] = process.env.npm_package_version manifest['version'] = process.env.npm_package_version
manifest['content_scripts'][0]['matches'] = getDomains().map((domain) => {return `*://*.${domain}/*`})
fs.writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2)) fs.writeFileSync('src/manifest.json', JSON.stringify(manifest, null, 2))
} }
@ -115,6 +67,7 @@ async function buildJs() {
'src/ui/player/player.ts': 'build/ui/player/player.js', 'src/ui/player/player.ts': 'build/ui/player/player.js',
'src/index.ts': 'build/index.js', 'src/index.ts': 'build/index.js',
'src/background.ts': 'build/background.js'
} }
for (const [src, dst] of Object.entries(files)) { for (const [src, dst] of Object.entries(files)) {