Skip to content

Commit

Permalink
fix: don't clear stuff
Browse files Browse the repository at this point in the history
I really only care about the fast forward. I guess I'll have to use one of these user-script adblockers that feature the worst codestlye. Honestly, I'd rather watch ads than run that code.
  • Loading branch information
Nerixyz committed Dec 1, 2022
1 parent 22b9097 commit 926b00c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "TTV-Tools",
"version": "0.5.6",
"version": "0.5.7",
"description": "Common helpers when watching twitch",
"background": {
"scripts": [
Expand Down
36 changes: 3 additions & 33 deletions src/background/background.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import _OnBeforeRequestDetails = browser.webRequest._OnBeforeRequestDetails;
import { StreamFilter } from '../types';
import { parseAttributes } from './utilities/m3u8.utilities';
import { OverridePlayer, UserAgent } from '../options';
import { onAdPod, StreamTabs } from './ad.replacement';
import { TWITCH_USER_PAGE } from './utilities/request.utilities';
import { eventHandler } from './utilities/messaging';
import { TwitchStitchedAdData } from './twitch-m3u8.types';
import { StreamTabs } from './ad.replacement';
function onRequest(request: _OnBeforeRequestDetails) {
if (!request.url.includes('video-weaver')) return;

Expand All @@ -28,8 +24,8 @@ function onRequest(request: _OnBeforeRequestDetails) {
filter.close();
};

extractAdData(text, request.documentUrl ?? '', request.tabId);
finalWrite(cleanupAllAdStuff(text));
//extractAdData(text, request.documentUrl ?? '', request.tabId);
finalWrite(text);
};

filter.onstop = () => {
Expand Down Expand Up @@ -81,29 +77,3 @@ browser.webRequest.onBeforeSendHeaders.addListener(
},
['requestHeaders', 'blocking']
);

function cleanupAllAdStuff(data: string) {
return data
.replace(/X-TV-TWITCH-AD-URL="[^"]+"/g, 'X-TV-TWITCH-AD-URL="javascript:alert(\'pogo\')"')
.replace(
/X-TV-TWITCH-AD-CLICK-TRACKING-URL="[^"]+"/g,
'X-TV-TWITCH-AD-CLICK-TRACKING-URL="javascript:alert(\'pogo\')"'
)
.replace(/X-TV-TWITCH-AD-ADVERIFICATIONS="[^"]+"/g, `X-TV-TWITCH-AD-ADVERIFICATIONS="${btoa('{}')}"`)
.replace(/#EXT-X-DATERANGE.+CLASS=".*ad.*".+\n/g, '');
}

function extractAdData(data: string, doc: string, tabId: number) {
const attrString = data.match(/#EXT-X-DATERANGE:(ID="stitched-ad-[^\n]+)\n/)?.[1];
if (!attrString) {
console.warn('no stitched ad');
return;
}
if(!TWITCH_USER_PAGE.test(doc)) return;

const attr = parseAttributes<TwitchStitchedAdData>(attrString);
onAdPod(attr, StreamTabs.get(tabId) ?? TWITCH_USER_PAGE.exec(doc)?.[1] ?? '').then(() => {
eventHandler.emitContext('adSkipped', {});
console.debug('"Skipped" ad.');
}).catch(console.error);
}

0 comments on commit 926b00c

Please sign in to comment.