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

Implement cosmetic filtering #3303

Merged
merged 9 commits into from Dec 14, 2019

adaptations of @Snuupy's MutationObserver work

mutation observer applied only if rule exists

notes

change order

mutation observer WIP

browser tests

isIdempotent

isIdempotent

mutation observer

mutationObserver

mutation observer

mutationObserver

mutation observer commented

mutation observer for anton

cleanup comments
  • Loading branch information
Snuupy authored and antonok-edm committed Jun 18, 2019
commit 0b93419f3dafbbc6ff3b2d83c5b6937dcb5823c1
@@ -22,7 +22,7 @@ export const removeSiteFilter = (origin: string) => {
})
}

export const applySiteFilters = (tabId: number, hostname: string) => {
export const applyCSSCosmeticFilters = (tabId: number, hostname: string) => {
chrome.storage.local.get('cosmeticFilterList', (storeData = {}) => {
if (!storeData.cosmeticFilterList) {
if (process.env.NODE_ENV === 'shields_development') {
@@ -33,7 +33,7 @@ import {
reportBrokenSite
} from '../api/shieldsAPI'
import { reloadTab } from '../api/tabsAPI'
import { applySiteFilters } from '../api/cosmeticFilterAPI'
import { applyCSSCosmeticFilters } from '../api/cosmeticFilterAPI'

// Helpers
import { getAllowedScriptsOrigins } from '../../helpers/noScriptUtils'
@@ -58,7 +58,7 @@ export default function shieldsPanelReducer (
state = shieldsPanelState.resetBlockingResources(state, action.tabId)
state = noScriptState.resetNoScriptInfo(state, action.tabId, new window.URL(action.url).origin)
}
applySiteFilters(action.tabId, getHostname(action.url))
applyCSSCosmeticFilters(action.tabId, getHostname(action.url))
break
}
case windowTypes.WINDOW_REMOVED: {
@@ -1,10 +1,25 @@
const unique = require('unique-selector').default

let target: EventTarget | null

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

/*function applyCosmeticFilterMutationObserver (filterList: any) {
let targetNode = document.documentElement
let observer = new MutationObserver(function (mutations) {
console.log('mutation observed')
injectIncrementalStyles(mutations)
})
let observerConfig = {
childList: true,
subtree: true
// characterData: true
}
observer.observe(targetNode, observerConfig)
}*/

document.addEventListener('contextmenu', (event) => {
// send host and store target
// `target` needed for when background page handles `addBlockElement`
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.