Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 1d59bf9

Browse files
committed
🩹 Check whitelist
1 parent 9649a31 commit 1d59bf9

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

src/backend/lib/remoteFunctions.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ export const remoteFn = (name: string, payload?: any): Promise<any> => {
4141
backend.onMessage.addListener(function (msg: FunctionReturnData) {
4242
if (msg.id === id) {
4343
// This message is the correct return
44-
console.log(msg)
45-
setTimeout(() => resolve(msg.payload), 10)
44+
resolve(msg.payload)
4645
}
4746
})
4847
})

src/backend/sites/cosmetic.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This performs cosmetic filtering on each website
22

33
import { parse } from 'psl'
4-
import { defineFn, initFn, remoteFn } from '../lib/remoteFunctions'
4+
import { remoteFn } from '../lib/remoteFunctions'
55

66
const getDomain = (url: string) =>
77
parse(url.replace('https://', '').replace('http://', '').split('/')[0]).domain
@@ -11,7 +11,11 @@ const url = window.location.href
1111
const hostname = window.location.hostname
1212
const domain = getDomain(url)
1313

14+
console.log('Cosmetics')
1415
;(async () => {
16+
const whitelist = await remoteFn('getWhitelist')
17+
if (whitelist.includes(domain)) return
18+
1519
const payload = await remoteFn('getCosmeticsFilters', {
1620
url,
1721
hostname,

src/backend/sites/youtube.ts

+25-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
// TODO [#25]: Check the whitelist to see if youtube has been whitelisted
21
// Note that google really doesn't want ads blocked on youtube, hence why
32
// the default adblock behavior doesn't work properly. Instead we need to create
43
// a custom blocker that stops ads from being displayed. A really simple bodge
54
// is to just click the skip button instantly and seem like we have properly skipped
65
// the ad. The skip button ad is currently .ytp-ad-text.ytp-ad-skip-button-text
76

8-
setInterval(() => {
9-
// Grab the skip button
10-
const skipButton: HTMLDivElement = document.querySelector(
11-
'.ytp-ad-text.ytp-ad-skip-button-text'
12-
)
7+
import { remoteFn } from '../lib/remoteFunctions'
8+
9+
// Needs to be in an async block to get the whitelist
10+
;(async () => {
11+
const whitelist = await remoteFn('getWhitelist')
12+
if (whitelist.includes('youtube.com')) return
1313

14-
// If the skip button does exists
15-
if (skipButton) {
16-
// Lets "smash that skip button"
17-
skipButton.click()
18-
// TODO [#26]: Automatically remove console.log's in production
19-
// Provide feedback in the console
20-
console.log('Video was skipped')
21-
}
22-
}, 100)
14+
setInterval(() => {
15+
// Grab the skip button
16+
const skipButton: HTMLDivElement = document.querySelector(
17+
'.ytp-ad-text.ytp-ad-skip-button-text'
18+
)
2319

24-
console.log(
25-
'================================\nDot Shield is enabled on youtube.com\nWe will try to block all ads on this webpage'
26-
)
20+
// If the skip button does exists
21+
if (skipButton) {
22+
// Lets "smash that skip button"
23+
skipButton.click()
24+
// TODO [#26]: Automatically remove console.log's in production
25+
// Provide feedback in the console
26+
console.log('Video was skipped')
27+
}
28+
}, 100)
29+
30+
console.log(
31+
'================================\nDot Shield is enabled on youtube.com\nWe will try to block all ads on this webpage'
32+
)
33+
})()

src/frontend/ui/popup/app.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export const App: Component = ({ state, setState, toggleWhitelist }) => {
2727
: '#000'
2828
: 'white'
2929

30-
console.log(state.favicon)
31-
3230
return (
3331
<div className={styles.container}>
3432
<main

0 commit comments

Comments
 (0)