-
-
Save pixeltris/e659867516ed0be149bf5e9e22d7d6e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/uBlockOrigin/uAssets/pull/3517 | |
twitch-videoad.js application/javascript | |
(function() { | |
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; } | |
// m3u8 segment stripper by instance01 (https://github.com/instance01/Twitch-HLS-AdBlock) | |
const SUPPORTED_VERSION = "2.9.2"; | |
const oldWorker = window.Worker; | |
window.Worker = class Worker extends oldWorker { | |
constructor(twitchBlobUrl) { | |
var version = getWasmBinaryVersion(twitchBlobUrl); | |
var usePerformanceFix = true; | |
if (version != SUPPORTED_VERSION) { | |
console.log(`Twitch HLS Adblock found possibly unsupported version: ${version}.`); | |
console.log(`Current supported version: ${SUPPORTED_VERSION}.`); | |
console.log("This is most likely fine. Trying upstream wasmworker.."); | |
usePerformanceFix = false; | |
} | |
var functions = getFuncsForInjection_FectTest(usePerformanceFix); | |
var newBlobStr = ` | |
var Module = { | |
WASM_BINARY_URL: 'https://cvp.twitch.tv/${version}/wasmworker.min.wasm', | |
WASM_CACHE_MODE: true | |
} | |
${ functions } | |
importScripts('https://cvp.twitch.tv/${version}/wasmworker.min.js'); | |
` | |
super(URL.createObjectURL(new Blob([newBlobStr]))); | |
} | |
} | |
function getWasmBinaryVersion (twitchBlobUrl) { | |
var req = new XMLHttpRequest(); | |
req.open('GET', twitchBlobUrl, false); | |
req.send(); | |
return req.responseText.match(/tv\/(.*)\/wasmworker/)[1]; | |
} | |
function getFuncsForInjection_FectTest (usePerformanceFix) { | |
return `${fetchTest.toString()}fetchTest();`; | |
} | |
function fetchTest() { | |
// This is a simple test using a proxy server to process the m3u8 response | |
var realFetch = fetch; | |
fetch = function(input, init) { | |
if (typeof input === 'string' && input.includes('/playlist/') && input.includes('.m3u8')) { | |
arguments[0] = 'http://localhost/TwitchTest?data=' + btoa(arguments[0]); | |
//console.log('redirect url ' + arguments[0]); | |
} | |
return realFetch.apply(this, arguments); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment