Skip to content

Commit

Permalink
#437 Safari converter generichide
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Nov 25, 2016
1 parent b8f5046 commit 1fe863b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Extension/browser/safari/lib/converter.js
Expand Up @@ -18,7 +18,7 @@
/**
* Safari content blocking format rules converter.
*/
var CONVERTER_VERSION = '1.3.18';
var CONVERTER_VERSION = '1.3.19';
// Max number of CSS selectors per rule (look at _compactCssRules function)
var MAX_SELECTORS_PER_WIDE_RULE = 250;
var URL_FILTER_ANY_URL = ".*";
Expand Down Expand Up @@ -660,7 +660,7 @@ exports.SafariContentBlockerConverter = {

var cssBlockingWide = [];
var cssBlockingDomainSensitive = [];
var cssBlockingGenericHideExceptions = [];
var cssBlockingGenericDomainSensitive = [];

var wideSelectors = [];
var addWideRule = function() {
Expand Down Expand Up @@ -688,7 +688,7 @@ exports.SafariContentBlockerConverter = {
if (rule.trigger['if-domain']) {
cssBlockingDomainSensitive.push(rule);
} else if (rule.trigger['unless-domain']) {
cssBlockingGenericHideExceptions.push(rule);
cssBlockingGenericDomainSensitive.push(rule);
} else {
wideSelectors.push(rule.action.selector);
if (wideSelectors.length >= MAX_SELECTORS_PER_WIDE_RULE) {
Expand All @@ -699,13 +699,11 @@ exports.SafariContentBlockerConverter = {
}
addWideRule();

Log.info('Compacted result: wide=' + cssBlockingWide.length
+ ' domainSensitive=' + cssBlockingDomainSensitive.length
+ ' domainSensitiveExceptions=' + cssBlockingGenericHideExceptions.length);
Log.info('Compacted result: wide=' + cssBlockingWide.length + ' domainSensitive=' + cssBlockingDomainSensitive.length);
return {
cssBlockingWide: cssBlockingWide,
cssBlockingDomainSensitive: cssBlockingDomainSensitive,
cssBlockingGenericHideExceptions: cssBlockingGenericHideExceptions
cssBlockingGenericDomainSensitive: cssBlockingGenericDomainSensitive
};
},

Expand All @@ -723,9 +721,9 @@ exports.SafariContentBlockerConverter = {
// Elemhide rules (##) - wide generic rules
cssBlockingWide: [],
// Elemhide rules (##) - generic domain sensitive
cssBlockingGenericHideExceptions: [],
cssBlockingGenericDomainSensitive: [],
// Generic hide exceptions
cssBlockingWideExceptions: [],
cssBlockingGenericHideExceptions: [],
// Elemhide rules (##) with domain restrictions
cssBlockingDomainSensitive: [],
// Elemhide exceptions ($elemhide)
Expand Down Expand Up @@ -770,7 +768,7 @@ exports.SafariContentBlockerConverter = {
cssExceptions.push(item);
} else if (item.action.type == 'ignore-previous-rules' &&
(ruleText && ruleText.indexOf('generichide') > 0)) {
contentBlocker.cssBlockingWideExceptions.push(item);
contentBlocker.cssBlockingGenericHideExceptions.push(item);
} else if (item.action.type == 'ignore-previous-rules' &&
(item.trigger["resource-type"] &&
item.trigger["resource-type"].length > 0 &&
Expand All @@ -789,15 +787,15 @@ exports.SafariContentBlockerConverter = {
if (!optimize) {
contentBlocker.cssBlockingWide = cssCompact.cssBlockingWide;
}
contentBlocker.cssBlockingGenericHideExceptions = cssCompact.cssBlockingGenericHideExceptions;
contentBlocker.cssBlockingGenericDomainSensitive = cssCompact.cssBlockingGenericDomainSensitive;
contentBlocker.cssBlockingDomainSensitive = cssCompact.cssBlockingDomainSensitive;

var convertedCount = rules.length - contentBlocker.errors.length;
var message = 'Rules converted: ' + convertedCount + ' (' + contentBlocker.errors.length + ' errors)';
message += '\nBasic rules: ' + contentBlocker.urlBlocking.length;
message += '\nElemhide rules (wide): ' + contentBlocker.cssBlockingWide.length;
message += '\nElemhide rules (generic domain sensitive): ' + contentBlocker.cssBlockingGenericHideExceptions.length;
message += '\nExceptions Elemhide (wide): ' + contentBlocker.cssBlockingWideExceptions.length;
message += '\nElemhide rules (generic domain sensitive): ' + contentBlocker.cssBlockingGenericDomainSensitive.length;
message += '\nExceptions Elemhide (wide): ' + contentBlocker.cssBlockingGenericHideExceptions.length;
message += '\nElemhide rules (domain-sensitive): ' + contentBlocker.cssBlockingDomainSensitive.length;
message += '\nExceptions (elemhide): ' + contentBlocker.cssElemhide.length;
message += '\nExceptions (other): ' + contentBlocker.other.length;
Expand All @@ -810,8 +808,8 @@ exports.SafariContentBlockerConverter = {
var overLimit = false;
var converted = [];
converted = converted.concat(contentBlocker.cssBlockingWide);
converted = converted.concat(contentBlocker.cssBlockingGenericDomainSensitive);
converted = converted.concat(contentBlocker.cssBlockingGenericHideExceptions);
converted = converted.concat(contentBlocker.cssBlockingWideExceptions);
converted = converted.concat(contentBlocker.cssBlockingDomainSensitive);
converted = converted.concat(contentBlocker.cssElemhide);
converted = converted.concat(contentBlocker.urlBlocking);
Expand Down

0 comments on commit 1fe863b

Please sign in to comment.