Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
do now allow duplicated items for resources blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jul 4, 2018
1 parent 4b19788 commit 52bd2ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/helpers/arrayUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* 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/. */

export const unique = (arr: Array<string>) => [...new Set(arr)]
21 changes: 14 additions & 7 deletions app/state/shieldsPanelState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as shieldState from '../types/state/shieldsPannelState'
import { unique } from '../helpers/arrayUtils'

export const getActiveTabId: shieldState.GetActiveTabId = (state) => state.windows[state.currentWindowId]

Expand Down Expand Up @@ -73,23 +74,23 @@ export const updateResourceBlocked: shieldState.UpdateResourceBlocked = (state,
}

if (blockType === 'ads') {
tabs[tabId].adsBlocked++
tabs[tabId].adsBlockedResources = [ ...tabs[tabId].adsBlockedResources, subresource ]
tabs[tabId].adsBlockedResources = unique([ ...tabs[tabId].adsBlockedResources, subresource ])
tabs[tabId].adsBlocked = tabs[tabId].adsBlockedResources.length
} else if (blockType === 'trackers') {
tabs[tabId].trackersBlocked++
tabs[tabId].trackersBlockedResources = [ ...tabs[tabId].trackersBlockedResources, subresource ]
tabs[tabId].trackersBlockedResources = unique([ ...tabs[tabId].trackersBlockedResources, subresource ])
tabs[tabId].trackersBlocked = tabs[tabId].trackersBlockedResources.length
} else if (blockType === 'httpUpgradableResources') {
tabs[tabId].httpsRedirected++
tabs[tabId].httpsRedirectedResources = [ ...tabs[tabId].httpsRedirectedResources, subresource ]
tabs[tabId].httpsRedirectedResources = unique([ ...tabs[tabId].httpsRedirectedResources, subresource ])
} else if (blockType === 'javascript') {
const origin = new window.URL(subresource).origin + '/'
tabs[tabId].javascriptBlocked++
tabs[tabId].noScriptInfo = { ...tabs[tabId].noScriptInfo }
tabs[tabId].noScriptInfo[origin] = { ...{ actuallyBlocked: true, willBlock: true } }
tabs[tabId].javascriptBlockedResources = [ ...tabs[tabId].javascriptBlockedResources, subresource ]
tabs[tabId].javascriptBlockedResources = unique([ ...tabs[tabId].javascriptBlockedResources, subresource ])
} else if (blockType === 'fingerprinting') {
tabs[tabId].fingerprintingBlocked++
tabs[tabId].fingerprintingBlockedResources = [ ...tabs[tabId].fingerprintingBlockedResources, subresource ]
tabs[tabId].fingerprintingBlockedResources = unique([ ...tabs[tabId].fingerprintingBlockedResources, subresource ])
}

return { ...state, tabs }
Expand All @@ -116,3 +117,9 @@ export const resetBlockingStats: shieldState.ResetBlockingStats = (state, tabId)
tabs[tabId] = { ...tabs[tabId], ...{ adsBlocked: 0, trackersBlocked: 0, httpsRedirected: 0, javascriptBlocked: 0, fingerprintingBlocked: 0 } }
return { ...state, tabs }
}

export const resetBlockingResources: shieldState.ResetBlockingResources = (state, tabId) => {
const tabs: shieldState.Tabs = { ...state.tabs }
tabs[tabId] = { ...tabs[tabId], ...{ adsBlockedResources: [], trackersBlockedResources: [], httpsRedirectedResources: [], javascriptBlockedResources: [], fingerprintingBlockedResources: [] } }
return { ...state, tabs }
}

0 comments on commit 52bd2ce

Please sign in to comment.