Skip to content

Commit

Permalink
remove remapping of custom action .blockCtlFB to .block
Browse files Browse the repository at this point in the history
plus some cleanup
  • Loading branch information
ladamski committed Apr 23, 2024
1 parent a5e1287 commit a93d49d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,79 +76,13 @@ struct ClickToLoadRulesSplitter {
cnames: originalTDS.cnames)
}

// private func processCTLActions(_ trackers: [String: KnownTracker]) -> (mainTDS: [String: KnownTracker], ctlOverrides: [String: KnownTracker]) {
// var mainTDSTrackers = trackers
// var ctlTrackers: [String: KnownTracker] = [:]
//
// for (key, tracker) in mainTDSTrackers {
// if let rules = tracker.rules as [KnownTracker.Rule]? {
// var ctlRules: [KnownTracker.Rule] = []
//
// for ruleIndex in rules.indices.reversed() {
// if let action = rules[ruleIndex].action, action == .blockCtlFB {
// var newRule = rules[ruleIndex]
// if newRule.surrogate != nil {
// // if rule includes a surroate, the action should be nil, as it gets converted to a redirect
// newRule.action = nil
// } else {
// newRule.action = .block
// }
//
// mainTDSTrackers[key]?.rules?.remove(at: ruleIndex)
// ctlRules.insert(newRule, at: 0)
// }
// }
//
// if !ctlRules.isEmpty {
// var ctlTracker = tracker
// ctlTracker.defaultAction = .ignore
// ctlTracker.rules = ctlRules
// ctlTrackers[key] = ctlTracker
// }
// }
// }
//
// return (mainTDSTrackers, ctlTrackers)
// }

private func filterTrackersWithoutCTLAction(_ trackers: [String: KnownTracker]) -> [String: KnownTracker] {
trackers.filter { (_, tracker) in tracker.containsCTLActions == false }
}

private func filterTrackersWithCTLAction(_ trackers: [String: KnownTracker]) -> [String: KnownTracker] {
return Dictionary(uniqueKeysWithValues: trackers.filter { (_, tracker) in
return tracker.containsCTLActions == true
}.map { (trackerKey, trackerValue) in
// Modify the tracker here
if let rules = trackerValue.rules as [KnownTracker.Rule]? {
let updatedRules = rules.map { (ruleValue) in
var action = ruleValue.action
if action == .blockCtlFB {
if ruleValue.surrogate != nil {
action = nil
} else {
action = .block
}
}
let newRule = KnownTracker.Rule(rule: ruleValue.rule,
surrogate: ruleValue.surrogate,
action: action,
options: ruleValue.options,
exceptions: ruleValue.exceptions)
return newRule
}
let updatedTracker = KnownTracker(domain: trackerValue.domain,
defaultAction: trackerValue.defaultAction,
owner: trackerValue.owner,
prevalence: trackerValue.prevalence,
subdomains: trackerValue.subdomains,
categories: trackerValue.categories,
rules: updatedRules)

return (trackerKey, updatedTracker)
}

return (trackerKey, trackerValue)
})
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct ScriptSourceProvider: ScriptSourceProviding {
private func mergeTrackerDataSets(rules: [ContentBlockerRulesManager.Rules]) -> (trackerData: TrackerData, encodedTrackerData: String) {
let tdsName = DefaultContentBlockerRulesListsSource.Constants.trackerDataSetRulesListName
let tdsIndex = contentBlockingManager.currentRules.firstIndex(where: { $0.name == tdsName})

var combinedTrackers: [String: KnownTracker] = [:]
var combinedEntities: [String: Entity] = [:]
var combinedDomains: [String: String] = [:]
Expand Down

0 comments on commit a93d49d

Please sign in to comment.