Skip to content

Commit

Permalink
Merge pull request #53 from Snuupy/cosmeticFilter
Browse files Browse the repository at this point in the history
Remove Flickering and Fix Context Menu Display
  • Loading branch information
cezaraugusto authored Aug 23, 2018
2 parents 8f599e0 + 068b02e commit 27c815c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ action("brave-extension") {
outputs = [
"$target_gen_dir/brave_extension/build/background.html",
"$target_gen_dir/brave_extension/build/js/background.bundle.js",
"$target_gen_dir/brave_extension/build/js/content.bundle.js",
"$target_gen_dir/brave_extension/build/js/braveShieldsPanel.bundle.js",
"$target_gen_dir/brave_extension/build/braveShieldsPanel.html",
"$target_gen_dir/brave_extension/build/bravelizer.css",
Expand Down
3 changes: 2 additions & 1 deletion app/background/api/cosmeticFilterAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const applySiteFilters = (hostname: string) => {
storeData.cosmeticFilterList[hostname].map((rule: string) => {
console.log('applying rule', rule)
chrome.tabs.insertCSS({
code: `${rule} {display: none;}`
code: `${rule} {display: none;}`,
runAt: 'document_start'
})
})
}
Expand Down
51 changes: 24 additions & 27 deletions app/background/events/cosmeticFilterEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,30 @@ let rule = {
selector: ''
}

// add context menu
chrome.runtime.onInstalled.addListener(function () {
// parent menu
chrome.contextMenus.create({
title: 'Brave',
id: 'brave',
contexts: ['all']
})
// block ad child menu
chrome.contextMenus.create({
title: 'Block element via selector',
id: 'addBlockElement',
parentId: 'brave',
contexts: ['all']
})
chrome.contextMenus.create({
title: 'Clear CSS rules for this site',
id: 'resetSiteFilterSettings',
parentId: 'brave',
contexts: ['all']
})
chrome.contextMenus.create({
title: 'Clear CSS rules for all sites',
id: 'resetAllFilterSettings',
parentId: 'brave',
contexts: ['all']
})
// parent menu
chrome.contextMenus.create({
title: 'Brave',
id: 'brave',
contexts: ['all']
})
// block ad child menu
chrome.contextMenus.create({
title: 'Block element via selector',
id: 'addBlockElement',
parentId: 'brave',
contexts: ['all']
})
chrome.contextMenus.create({
title: 'Clear CSS rules for this site',
id: 'resetSiteFilterSettings',
parentId: 'brave',
contexts: ['all']
})
chrome.contextMenus.create({
title: 'Clear CSS rules for all sites',
id: 'resetAllFilterSettings',
parentId: 'brave',
contexts: ['all']
})

// contextMenu listener - when triggered, grab latest selector
Expand Down
9 changes: 6 additions & 3 deletions test/app/background/api/cosmeticFilterAPITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ describe('cosmeticFilterTestSuite', () => {
})
cosmeticFilterAPI.applySiteFilters('brave.com')
assert.deepEqual(this.insertCSSStub.getCall(0).args[0], {
code: `${filter} {display: none;}`
code: `${filter} {display: none;}`,
runAt: 'document_start'
})
})
it('applies multiple filters correctly', function () {
Expand All @@ -195,10 +196,12 @@ describe('cosmeticFilterTestSuite', () => {
})
cosmeticFilterAPI.applySiteFilters('brave.com')
assert.deepEqual(this.insertCSSStub.getCall(0).args[0], {
code: `${filter} {display: none;}`
code: `${filter} {display: none;}`,
runAt: 'document_start'
})
assert.deepEqual(this.insertCSSStub.getCall(1).args[0], {
code: `${filter2} {display: none;}`
code: `${filter2} {display: none;}`,
runAt: 'document_start'
})

})
Expand Down

0 comments on commit 27c815c

Please sign in to comment.