Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
fixed bugs causing too many injected rules, and wrongly parsing excep…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
gorhill committed May 18, 2014
1 parent efa268f commit 8aff806
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 11 additions & 4 deletions js/abp-hide-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ var FilterPlain = function(s) {
};

FilterPlain.prototype.retrieve = function(s, out) {
if ( s === this.s.slice(0, s.length) ) {
if ( s === this.s ) {
out.push(this.s);
}
// if ( s === this.s.slice(0, s.length) ) {
// out.push(this.s);
// }
};

/******************************************************************************/
Expand All @@ -92,7 +95,7 @@ var FilterPlainHostname = function(s, hostname) {
};

FilterPlainHostname.prototype.retrieve = function(s, out) {
if ( s === this.s.slice(0, s.length) && pageHostname === this.hostname ) {
if ( s === this.s && pageHostname === this.hostname ) {
out.push(this.s);
}
};
Expand Down Expand Up @@ -147,7 +150,7 @@ FilterParser.prototype.parse = function(s) {

this.anchor = s.indexOf('##');
if ( this.anchor < 0 ) {
this.anchor = s.indexOf('#@');
this.anchor = s.indexOf('#@#');
if ( this.anchor < 0 ) {
this.invalid = true;
return this;
Expand All @@ -157,7 +160,11 @@ FilterParser.prototype.parse = function(s) {
if ( this.anchor > 0 ) {
this.hostnames = s.slice(0, this.anchor).split(/\s*,\s*/);
}
this.f = s.slice(this.anchor + 2);
if ( this.filterType === '@' ) {
this.f = s.slice(this.anchor + 3);
} else {
this.f = s.slice(this.anchor + 2);
}

// selector
var selectorType = this.f.charAt(0);
Expand Down
12 changes: 8 additions & 4 deletions js/contentscript-elemhide.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ var retrieveHandler = function(selectors) {
}
var styleText = [];
if ( selectors.hide.length > 0 ) {
var hideStyleText = '{{hideSelectors}} {visibility:hidden;display:none;}';
styleText.push(hideStyleText.replace('{{hideSelectors}}', selectors.hide.join(',')));
var hideStyleText = '{{hideSelectors}} {display:none;}'
.replace('{{hideSelectors}}', selectors.hide.join(','));
styleText.push(hideStyleText);
console.log('ABP cosmetic filters: injecting CSS rule:', hideStyleText);
}
if ( selectors.donthide.length > 0 ) {
var dontHideStyleText = '{{donthideSelectors}} {visibility:inherit;display:inherit;}';
styleText.push(donthideStyleText.replace('{{donthideSelectors}}', selectors.donthide.join(',')));
var dontHideStyleText = '{{donthideSelectors}} {display:initial;}'
.replace('{{donthideSelectors}}', selectors.donthide.join(','));
styleText.push(donthideStyleText);
console.log('ABP cosmetic filters: injecting CSS rule:', donthideStyleText);
}
if ( styleText.length > 0 ) {
var style = document.createElement('style');
Expand Down

0 comments on commit 8aff806

Please sign in to comment.