Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated brave extension to wait for css selector #1771

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ chrome.contextMenus.create({
chrome.contextMenus.onClicked.addListener(function (info, tab) {
switch (info.menuItemId) {
case 'addBlockElement': {
rule.selector = window.prompt('CSS selector to block: ', `${rule.selector}`) || ''
chrome.tabs.insertCSS({
code: `${rule.selector} {display: none;}`
chrome.runtime.sendMessage({
type: 'addBlockElement'
})
cosmeticFilterActions.siteCosmeticFilterAdded(rule.host, rule.selector)
break
}
case 'resetSiteFilterSettings': {
Expand All @@ -59,6 +57,10 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) {
// content script listener for right click DOM selection event
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
rule.host = msg.baseURI
rule.selector = msg.selector
rule.selector = window.prompt('CSS selector to block: ', `${msg.selector}`) || ''
chrome.tabs.insertCSS({
code: `${rule.selector} {display: none;}`
})
cosmeticFilterActions.siteCosmeticFilterAdded(rule.host, rule.selector)
sendResponse(rule)
})
22 changes: 15 additions & 7 deletions components/brave_extension/extension/brave_extension/content.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
const unique = require('unique-selector').default
let target: EventTarget | null

function getCurrentURL () {
return window.location.hostname
}

document.addEventListener('contextmenu', (event) => {
let selector = unique(event.target) // this has to be done here, events can't be passed through the messaging API
let baseURI = getCurrentURL()

chrome.runtime.sendMessage({
selector: selector,
baseURI: baseURI
})
target = event.target
}, true)

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
const action = typeof msg === 'string' ? msg : msg.type
switch (action) {
case 'addBlockElement': {
sendResponse({
selector: unique(target),
baseURI: getCurrentURL()
})
break
}
}
})