diff --git a/build.py b/build.py index 5a93d09..7543562 100644 --- a/build.py +++ b/build.py @@ -35,6 +35,13 @@ def write_manifest(): for content_script in manifest['content_scripts']: content_script['matches'] = [f'*://{match}/*' for match in matches] + domains = [] + for match in matches: + toplevel = match.split('.')[-1] + if toplevel not in domains: + domains.append(toplevel) + manifest['content_security_policy'] = f"script-src 'self' blob: https://cdn.jsdelivr.net {' '.join(f'*.{toplevel}' for toplevel in domains)}; object-src 'self'" + json.dump(manifest, open('src/manifest.json', 'w'), indent=2) diff --git a/src/index.ts b/src/index.ts index 20d1df4..2e1f8d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,11 +28,13 @@ chrome.storage.local.get(['all', 'disabled'], function (result) { if (regex === null) { location.assign(document.body.innerHTML) } else { - location.assign(hasSuffix(re[0], 'm3u8') ? `https://bharadwajpro.github.io/m3u8-player/player/#${re[0]}`: re[0]) + // @ts-ignore + location.assign(hasSuffix(re[0], 'm3u8') ? chrome.runtime.getURL(`res/hls.html#${re[0]}`) : re[0]) } } else { matchClass.match(re).then(function (path) { - location.assign(hasSuffix(path, 'm3u8') ? `https://bharadwajpro.github.io/m3u8-player/player/#${path}`: path) + // @ts-ignore + location.assign(hasSuffix(path, 'm3u8') ? chrome.runtime.getURL(`res/hls.html#${path}`) : path) }) } } diff --git a/src/manifest.json b/src/manifest.json index 3537938..fa133c4 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -15,6 +15,7 @@ "all_frames": true, "matches": [ "*://evoload.io/*", + "*://mcloud.to/*", "*://mixdrop.co/*", "*://streamtape.com/*", "*://streamzz.to/*", @@ -35,6 +36,7 @@ "permissions": [ "storage" ], + "content_security_policy": "script-src 'self' blob: https://cdn.jsdelivr.net *.io *.to *.co *.com *.me *.net *.st *.sx; object-src 'self'", "browser_action": { "default_icon": "icons/stream-bypass.png", "default_title": "Stream Bypass", diff --git a/src/res/hls.html b/src/res/hls.html new file mode 100644 index 0000000..f5f2435 --- /dev/null +++ b/src/res/hls.html @@ -0,0 +1,14 @@ + + + + + + + m3u8 + + + + + + + \ No newline at end of file diff --git a/src/res/hls.sass b/src/res/hls.sass new file mode 100644 index 0000000..b7c47ea --- /dev/null +++ b/src/res/hls.sass @@ -0,0 +1,6 @@ +html, body, video + height: 100% + width: 100% + +video + margin: auto \ No newline at end of file diff --git a/src/res/hls.ts b/src/res/hls.ts new file mode 100644 index 0000000..7e60350 --- /dev/null +++ b/src/res/hls.ts @@ -0,0 +1,20 @@ +function loadHls() { + let url = window.location.hash.substring(1) + let video = document.getElementById('video') as HTMLVideoElement; + + video.controls = true + if (video.canPlayType('application/vnd.apple.mpegurl')) { + video.src = url + // @ts-ignore + } else if (Hls.isSupported()) { + // @ts-ignore + let hls = new Hls() + hls.loadSource(url) + hls.attachMedia(video) + } else { + // shows a message if hls is not supported + document.getElementById('not-supported').hidden = false + } +} + +loadHls()