mirror of
https://github.com/bytedream/stream-bypass.git
synced 2025-06-28 02:50:32 +02:00
Lots of updates :o
This commit is contained in:
59
src/index.ts
59
src/index.ts
@ -1,46 +1,25 @@
|
||||
function hasSuffix(content: string, suffix: string) {
|
||||
return content.indexOf(suffix, content.length - suffix.length) !== -1
|
||||
}
|
||||
import {matches} from "./match/match";
|
||||
import {getAllDisabled, getDisabled} from "./store/store";
|
||||
|
||||
// @ts-ignore
|
||||
chrome.storage.local.get(['all', 'disabled'], function (result) {
|
||||
let keys = Object.keys(result)
|
||||
if (keys.indexOf('all') !== -1 && !result['all']) {
|
||||
async function main() {
|
||||
if (await getAllDisabled()) {
|
||||
return
|
||||
}
|
||||
// @ts-ignore
|
||||
for (let match of matches) {
|
||||
let domain = match[0] as string
|
||||
if (window.location.href.indexOf(domain) !== -1) {
|
||||
if (keys.indexOf('disabled') === -1 || result['disabled'].indexOf(domain) === -1) {
|
||||
let regex = match[1] as RegExp
|
||||
let matchClass = match[2] as Match
|
||||
let reliability = match[3] as Reliability
|
||||
const disabled = await getDisabled()
|
||||
|
||||
let re
|
||||
if (regex !== null) {
|
||||
if ((re = document.body.innerHTML.match(regex)) === null) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
re = document.body.innerHTML.match(regex)
|
||||
}
|
||||
|
||||
if (matchClass === null) {
|
||||
if (regex === null) {
|
||||
location.assign(document.body.innerHTML)
|
||||
} else {
|
||||
// @ts-ignore
|
||||
location.assign(hasSuffix(re[0], 'm3u8') ? chrome.runtime.getURL(`res/hls.html?domain=${domain}&reliability=${reliability}#${re[0]}`) : re[0])
|
||||
}
|
||||
} else {
|
||||
matchClass.match(re).then(function (path) {
|
||||
// @ts-ignore
|
||||
location.assign(hasSuffix(path, 'm3u8') ? chrome.runtime.getURL(`res/hls.html?domain=${domain}&reliability=${reliability}#${path}`) : path)
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
for (const match of matches) {
|
||||
if (disabled.some((v) => v == match) || !match.domains.some((v) => window.location.host.indexOf(v) !== -1)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const re = document.body.innerHTML.match(match.regex)
|
||||
if (re === null) {
|
||||
continue
|
||||
}
|
||||
|
||||
const url = await match.match(re)
|
||||
location.assign(url.indexOf('.m3u8', url.length - 5) === -1 ? url : chrome.runtime.getURL(`ui/hls/hls.html?id=${match.id}&url=${encodeURIComponent(url)}`))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
|
Reference in New Issue
Block a user