This repository was archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (40 loc) · 1.32 KB
/
index.js
File metadata and controls
48 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const INSTAGRAM_KEY = 'instagram'
const FACEBOOK_KEY = 'facebook'
const URLS_TO_CANCEL = [
'*://*.facebook.com/ajax/mercury/change_read_status.php*',
'*://*.instagram.com/ajax/bz*',
'*://*.instagram.com/qp/batch_fetch_web*',
'*://*.instagram.com/api/v1/stories/reel/seen',
'*://*.instagram.com/api/v1/direct_v2/threads/*/items/*/seen/',
]
const isNodeEnv = typeof exports !== 'undefined'
// Chrome support: `browser` should fallback to `chrome`
// since Chrome doesn't fully support WebExtensions
if (typeof browser === 'undefined' && !isNodeEnv) {
browser = chrome
}
const shouldCancelRequest = (url, storage) => {
const isCancellable = key => {
if (chrome) {
// See: https://github.com/diessica/no-seen/issues/2
return true
}
return url.includes(key) && storage.get().then(s => s[key] !== false)
}
return {
cancel: [FACEBOOK_KEY, INSTAGRAM_KEY].some(isCancellable),
}
}
const handleRequest = ({ url }) =>
shouldCancelRequest(url, browser.storage.sync)
const listenToRequests = () =>
browser.webRequest.onBeforeRequest.addListener(
handleRequest,
{ urls: URLS_TO_CANCEL },
['blocking']
)
if (typeof browser === 'undefined' && isNodeEnv) {
exports.shouldCancelRequest = shouldCancelRequest
} else {
listenToRequests()
}