This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Diéssica
committed
Aug 11, 2018
1 parent
82a9ee3
commit b05669a
Showing
5 changed files
with
73 additions
and
47 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"semi": false, | ||
"tabWidth": 4, | ||
"trailingComma": true, | ||
"singleQuote": true | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
const INSTAGRAM_KEY = 'instagram' | ||
const FACEBOOK_KEY = 'facebook' | ||
const BLOCKED_URLS = [ | ||
'*://*.facebook.com/ajax/mercury/change_read_status.php*', | ||
'*://*.instagram.com/stories/reel/seen', | ||
const URLS_TO_CANCEL = [ | ||
'*://*.facebook.com/ajax/mercury/change_read_status.php*', | ||
'*://*.instagram.com/stories/reel/seen', | ||
] | ||
|
||
const isNodeEnv = typeof exports !== 'undefined' | ||
|
||
// Chrome support: `browser` should fallback to `chrome` | ||
// since Chrome doesn't fully support WebExtensions | ||
if (typeof browser === "undefined") { | ||
browser = chrome; | ||
if (typeof browser === 'undefined' && !isNodeEnv) { | ||
browser = chrome | ||
} | ||
|
||
const shouldCancel = (url, storage) => { | ||
const isAble = key => url.includes(key) && storage.get() | ||
.then(s => s[key] !== false) | ||
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 isAble(FACEBOOK_KEY) || isAble(INSTAGRAM_KEY) | ||
return { | ||
cancel: [FACEBOOK_KEY, INSTAGRAM_KEY].some(isCancellable), | ||
} | ||
} | ||
|
||
const onCancel = ({ originUrl: url }) => | ||
shouldCancel(url, browser.storage.sync) | ||
.then(cancel => ({ cancel })) | ||
const handleRequest = ({ url }) => | ||
shouldCancelRequest(url, browser.storage.sync) | ||
|
||
const init = () => browser.webRequest.onBeforeRequest | ||
.addListener(onCancel, { urls: BLOCKED_URLS }, ['blocking']) | ||
const listenToRequests = () => | ||
browser.webRequest.onBeforeRequest.addListener( | ||
handleRequest, | ||
{ urls: URLS_TO_CANCEL }, | ||
['blocking'] | ||
) | ||
|
||
if (typeof browser === 'undefined' && typeof exports !== 'undefined') { | ||
exports.shouldCancel = shouldCancel | ||
if (typeof browser === 'undefined' && isNodeEnv) { | ||
exports.shouldCancelRequest = shouldCancelRequest | ||
} else { | ||
init() | ||
} | ||
listenToRequests() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
{ | ||
"name": "No Seen", | ||
"description": "Blocks \"seen\" marks on Facebook Messenger and Instagram Stories.", | ||
"version": "1.1", | ||
"manifest_version": 2, | ||
"background": { | ||
"scripts": ["index.js"] | ||
}, | ||
"options_ui": { | ||
"page": "preferences.html" | ||
}, | ||
"permissions": [ | ||
"storage", | ||
"webRequest", | ||
"webRequestBlocking", | ||
"*://*.facebook.com/*", | ||
"*://*.instagram.com/*" | ||
], | ||
"developer": { | ||
"name": "Diéssica Gurskas", | ||
"url": "https://diessi.ca" | ||
}, | ||
"applications": { | ||
"gecko": { | ||
"id": "no-seen@no.seen" | ||
} | ||
"name": "No Seen", | ||
"description": "Blocks \"seen\" marks on Facebook Messenger and Instagram Stories.", | ||
"version": "1.2", | ||
"manifest_version": 2, | ||
"background": { | ||
"scripts": ["index.js"] | ||
}, | ||
"options_ui": { | ||
"page": "preferences.html" | ||
}, | ||
"permissions": [ | ||
"storage", | ||
"webRequest", | ||
"webRequestBlocking", | ||
"*://*.facebook.com/*", | ||
"*://*.instagram.com/*" | ||
], | ||
"developer": { | ||
"name": "Diéssica Gurskas", | ||
"url": "https://diessi.ca" | ||
}, | ||
"applications": { | ||
"gecko": { | ||
"id": "no-seen@no.seen" | ||
} | ||
} | ||
} | ||
} |
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