mirror of
https://github.com/bytedream/stream-bypass.git
synced 2025-05-09 20:25:14 +02:00
Add functions to bypass websites that are redirected to (looking at you voe)
This commit is contained in:
parent
672b920f31
commit
4cf76eb62a
16
src/background.ts
Normal file
16
src/background.ts
Normal 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']
|
||||
})
|
34
src/index.ts
34
src/index.ts
@ -1,24 +1,26 @@
|
||||
import {matches} from "./match/match";
|
||||
import {getAllDisabled, getDisabled} from "./store/store";
|
||||
import {getMatch} from "./match/match";
|
||||
import {storageDelete, storageGet} from "./store/store";
|
||||
import {Match, matches} from "./match/matches";
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
for (const match of matches) {
|
||||
if (!match.domains.some((v) => window.location.host.indexOf(v) !== -1) || ((await getDisabled()).some((v) => v === match))) {
|
||||
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)}`))
|
||||
}
|
||||
const url = await match.match(re)
|
||||
location.assign(chrome.runtime.getURL(`ui/player/player.html?id=${match.id}&url=${encodeURIComponent(url)}`))
|
||||
}
|
||||
|
||||
main()
|
||||
|
@ -14,21 +14,7 @@
|
||||
{
|
||||
"all_frames": true,
|
||||
"matches": [
|
||||
"*://*.evoload.io/*",
|
||||
"*://*.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/*"
|
||||
"<all_urls>"
|
||||
],
|
||||
"js": [
|
||||
"index.js"
|
||||
@ -36,8 +22,15 @@
|
||||
"run_at": "document_end"
|
||||
}
|
||||
],
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
]
|
||||
},
|
||||
"permissions": [
|
||||
"storage"
|
||||
"storage",
|
||||
"webRequest",
|
||||
"<all_urls>"
|
||||
],
|
||||
"browser_action": {
|
||||
"default_icon": {
|
||||
|
14
src/match/match.ts
Normal file
14
src/match/match.ts
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
@ -192,10 +192,7 @@ class Voe implements Match {
|
||||
id = 'voe'
|
||||
reliability = Reliability.HIGH
|
||||
domains = [
|
||||
'voe.sx',
|
||||
'voeunblk.com',
|
||||
'voeun-block.net',
|
||||
'un-block-voe.net'
|
||||
'voe.sx'
|
||||
]
|
||||
regex = new RegExp(/https?:\/\/\S*m3u8(?=")/gm)
|
||||
|
||||
|
@ -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) => {
|
||||
chrome.storage.local.get(key, (value) => {
|
||||
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 = {}
|
||||
obj[key] = value
|
||||
await chrome.storage.local.set(obj)
|
||||
}
|
||||
|
||||
export async function storageDelete(key: string) {
|
||||
await chrome.storage.local.remove(key)
|
||||
}
|
||||
|
||||
export async function getDisabled(): Promise<Match[]> {
|
||||
const localMatches = []
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {Match, matches, Reliability} from "../../match/match";
|
||||
import {Match, matches, Reliability} from "../../match/matches";
|
||||
// @ts-ignore
|
||||
import Hls from "hls.js";
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
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() {
|
||||
const disabled = await getDisabled()
|
||||
|
@ -9,59 +9,11 @@ const sass = require('node-sass')
|
||||
const sassPluginNodeImport = require('node-sass-package-importer')
|
||||
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() {
|
||||
const manifest = JSON.parse(fs.readFileSync('src/manifest.json'))
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
@ -115,6 +67,7 @@ async function buildJs() {
|
||||
'src/ui/player/player.ts': 'build/ui/player/player.js',
|
||||
|
||||
'src/index.ts': 'build/index.js',
|
||||
'src/background.ts': 'build/background.js'
|
||||
}
|
||||
|
||||
for (const [src, dst] of Object.entries(files)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user