-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
brings back a feature to add, remove custom CSS selectors
- Loading branch information
1 parent
f5794c4
commit 7bf3915
Showing
3 changed files
with
67 additions
and
0 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
51 changes: 51 additions & 0 deletions
51
components/brave_extension/extension/brave_extension/background/api/cosmeticFilterAPI.ts
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,51 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// User generated cosmetic filtering below | ||
export const applyCSSCosmeticFilters = (tabId: number, hostname: string) => { | ||
chrome.storage.local.get('cosmeticFilterList', (storeData = {}) => { | ||
if (!storeData.cosmeticFilterList) { | ||
if (process.env.NODE_ENV === 'shields_development') { | ||
console.log('applySiteFilters: no cosmetic filter store yet') | ||
} | ||
return | ||
} | ||
if (storeData.cosmeticFilterList[hostname] !== undefined) { | ||
storeData.cosmeticFilterList[hostname].map((rule: string) => { | ||
if (process.env.NODE_ENV === 'shields_development') { | ||
console.log('applying rule', rule) | ||
} | ||
chrome.tabs.insertCSS(tabId, { // https://github.com/brave/brave-browser/wiki/Cosmetic-Filtering | ||
code: `${rule} {display: none !important;}`, | ||
cssOrigin: 'user', | ||
runAt: 'document_start' | ||
}) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
export const removeAllFilters = () => { | ||
chrome.storage.local.set({ 'cosmeticFilterList': {} }) | ||
} | ||
|
||
export const addSiteCosmeticFilter = async (origin: string, cssfilter: string) => { | ||
chrome.storage.local.get('cosmeticFilterList', (storeData = {}) => { | ||
let storeList = Object.assign({}, storeData.cosmeticFilterList) | ||
if (storeList[origin] === undefined || storeList[origin].length === 0) { // nothing in filter list for origin | ||
storeList[origin] = [cssfilter] | ||
} else { // add entry | ||
storeList[origin].push(cssfilter) | ||
} | ||
chrome.storage.local.set({ 'cosmeticFilterList': storeList }) | ||
}) | ||
} | ||
|
||
export const removeSiteFilter = (origin: string) => { | ||
chrome.storage.local.get('cosmeticFilterList', (storeData = {}) => { | ||
let storeList = Object.assign({}, storeData.cosmeticFilterList) | ||
delete storeList[origin] | ||
chrome.storage.local.set({ 'cosmeticFilterList': storeList }) | ||
}) | ||
} |
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