Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge branch 'v0.9.5.3'
Browse files Browse the repository at this point in the history
* v0.9.5.3:
  - Handle more complex cases of Extended Pseudo Classes - Add support for Adguard :not operator - Added support for using Extended Pseudo Classes in Style filter rule like mycinema.pro#$#[class]:matches-css(width: 336px):matches-css(height: 280px):matches-css(min-height: 280px):has(>ins.adsbygoogle) { visibility: hidden!important; } - Added support for two types of syntax from uBO (+js, +style)
  • Loading branch information
uBlockAdmin committed Oct 4, 2019
2 parents b839d1b + f2d35d1 commit 4168ac8
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 246 deletions.
4 changes: 2 additions & 2 deletions assets/scriptlets/abort-current-inline-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

var randomNo = Math.floor(Math.random() * 2116316160 + 60466176).toString(36);

function abortCurrentInlineScript(api, search = null) {
function abortCurrentInlineScript(api, search = "null") {
let names = api.split(".");
let base = window;
let property;
Expand All @@ -28,7 +28,7 @@
var descriptor = Object.getOwnPropertyDescriptor(base, lastproperty);
if ( descriptor && descriptor.get !== undefined ) { return; }

let re = search ? strToRegex(search) : null;
let re = search != "null" ? strToRegex(search) : null;
let rid = randomNo;
let us = document.currentScript;
var value = base[lastproperty];
Expand Down
4 changes: 2 additions & 2 deletions platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,

"name": "uBlock",
"version": "0.9.5.21",
"version": "0.9.5.22",

"default_locale": "en",
"description": "__MSG_extShortDesc__",
Expand All @@ -17,7 +17,7 @@
"default_popup": "popup.html"
},

"author": "The uBlock Development Team",
"author": "All uBlock contributors",
"background": {
"page": "background.html"
},
Expand Down
4 changes: 2 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ return {

// read-only
systemSettings: {
compiledMagic: 'wertpszukpslklk',
selfieMagic: 'werthiasrslklk'
compiledMagic: 'wertpszukpslfds',
selfieMagic: 'werthiasrslfds'
},
restoreBackupSettings: {
lastRestoreFile: '',
Expand Down
487 changes: 295 additions & 192 deletions src/js/contentscript-end.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/js/contentscript-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ vAPI.contentscriptStartInjected = true;
vAPI.styles = vAPI.styles || [];
vAPI.userStyles = vAPI.userStyles || [];
vAPI.injectedProcedureCosmeticFilters = vAPI.injectedProcedureCosmeticFilters || [];
vAPI.shouldObserveAttributes = false;
vAPI.shouldObserveCharacterData = false;


/******************************************************************************/

Expand All @@ -80,6 +83,8 @@ var cosmeticFilters = function(details) {
vAPI.hideCosmeticFilters = details.cosmeticHide;
vAPI.injectedSelectors = details.injectedSelectors;
vAPI.hideProcedureFilters = hideProcedureFilters;
vAPI.shouldObserveAttributes = details.shouldObserveAttributes;
vAPI.shouldObserveCharacterData = details.shouldObserveCharacterData;
let highGenericsArray = [];
if(highGenerics) {
if(highGenerics.hideLow.length > 0) {
Expand Down
110 changes: 86 additions & 24 deletions src/js/cosmetic-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
[ ':contains', ["(", ")", [1, -1], ":-abp-contains"] ]
]);
this.extended = false;
this.snippet = false;
return this;
};

Expand Down Expand Up @@ -125,6 +126,21 @@
}
return str;
}
FilterParser.prototype.convertuBOStyleToABP = function(suffix, spos) {
let stylePrefix = suffix.slice(0, spos);
let styleSuffix = suffix.slice(spos);
let style = /:style\(([^)]+)\)/.exec(styleSuffix)[1];
return `${stylePrefix} {${style}}`;
}
FilterParser.prototype.convertuBOJsToABP = function(suffix) {
let invalid = false;
let arrParams = /^\+js\(([^)]+)\)/.exec(suffix)[1].replace(/,[\s]+/gi," ").replace(".js","").split(" ");
let snippetName = arrParams[0];
if(!supportedSnippet.has(snippetName)) {
invalid = true;
}
return [invalid, arrParams.join(" ")];
}
FilterParser.prototype.parse = function(s) {
// important!
this.reset();
Expand Down Expand Up @@ -154,21 +170,32 @@
if ( this.suffix.charAt(1) === '[' && this.suffix.slice(2, 9) === 'href^="' ) {
this.suffix = this.suffix.slice(1);
}

this.type = matches[2].charAt(1);
if(reAdguardExtCssSyntax.test(this.suffix)) {
this.suffix = this.convertAdGuardRule(this.suffix);
}

let spos = this.suffix.indexOf(":style");
if(spos !== -1) {
this.suffix = this.convertuBOStyleToABP(this.suffix, spos);
this.type = '$';
}
if(/^\+js\(/.test(this.suffix)) {
[this.invalid, this.suffix] = this.convertuBOJsToABP(this.suffix);
if(this.invalid) return this;
this.type = '$';
}
if(this.type == "$") {
if(reAdguardCssSyntax.test(this.suffix)) {
this.extended = false;
if(reprocSelector.test(this.suffix))
this.extended = true;
} else {
let m = /([^\s]+)/.exec(this.suffix);
if(!supportedSnippet.has(m[0])) {
this.invalid = true;
return this;
}
this.extended = true;
this.snippet = true;
}
}
this.unhide = this.type === '@' ? 1 : 0;
Expand Down Expand Up @@ -677,28 +704,29 @@
return {text: content.substring(startIndex, i), end: i};
}

const normalizedOperators = new Set(['-abp-contains', '-abp-has', '-abp-properties' , 'matches-css', 'matches-css-after', 'matches-css-before']);
const normalizedOperators = new Set(['-abp-contains', '-abp-has', '-abp-properties' , 'matches-css', 'matches-css-after', 'matches-css-before', 'not']);
const shortNames = new Map([
["pseudoCls", "ps"],
["prefix", "pf"],
["selectorText", "st"],
["_innerSelectors", "_is"],
["maybeContainsSiblingCombinators", "csc"],
["startsWithSiblingOperator", "sso"],
["hasParallelSiblingSelector", "pss"]
]);

FilterContainer.prototype.parseProcedure = function(expression) {
let tasks = [], prefix, remaining, parsed, selectorText, isValid = true, procSelector = null, pseudoClass = null;
let matches = pseudoClassReg.exec(expression);
if(!matches) {
this.shouldObserveAttributes = !this.shouldObserveAttributes ? /[#.]|\[.+\]/.test(expression) : true;
return [true,
[{
["plain"]: {
[shortNames.get('pseudoCls')]: null,
[shortNames.get('prefix')]: "",
[shortNames.get('selectorText')]: expression,
[shortNames.get('_innerSelectors')]: null,
[shortNames.get('maybeContainsSiblingCombinators')]: /[~+]/.test(expression),
[shortNames.get('startsWithSiblingOperator')]: /^\s*[+~]/.test(expression),
[shortNames.get('hasParallelSiblingSelector')]: false
}
}]
Expand All @@ -713,7 +741,12 @@
selectorText = parsed.text;
pseudoClass = (matches[3] == "matches-css-after" ? ":after" : (matches[3] == "matches-css-before" ? ":before" : null ));

if(matches[3] == "-abp-has") {
if(matches[3] == "-abp-contains")
this.shouldObserveCharacterData = true;

this.shouldObserveAttributes = !this.shouldObserveAttributes ? /[#.]|\[.+\]/.test(prefix) : true;

if(matches[3] == "-abp-has" || matches[3] == "not") {
[isValid, procSelector] = this.parseProcedure(selectorText);
} else if(normalizedOperators.has(matches[3])) {
isValid = true;
Expand All @@ -728,6 +761,7 @@
[shortNames.get('prefix')]: prefix,
[shortNames.get('selectorText')]: procSelector === null ? selectorText : null,
[shortNames.get('_innerSelectors')]: procSelector,
[shortNames.get('startsWithSiblingOperator')]: /^\s*[+~]/.test(prefix),
[shortNames.get('hasParallelSiblingSelector')]: false
}
});
Expand All @@ -736,11 +770,11 @@
let suffix;
[isValid, suffix] = this.parseProcedure(suffixtext);
if(isValid) {
if(Object.keys(suffix).length == 1) {
if(Object.keys(suffix)[0] == "plain" && suffix["plain"].maybeContainsSiblingCombinators) {
if(suffix.length > 0) {
if(Object.values(suffix[0])[0][shortNames.get('startsWithSiblingOperator')]) {
for (let task of tasks) {
if(Object.keys(task)[0] == "-abp-has" || Object.keys(task)[0] == "-abp-contains" || Object.keys(task)[0] == "-abp-properties") {
task[Object.keys(task)[0]].hasParallelSiblingSelector = true;
if(Object.keys(task)[0] != "plain") {
task[Object.keys(task)[0]][shortNames.get('hasParallelSiblingSelector')] = true;
}
}
}
Expand Down Expand Up @@ -772,19 +806,33 @@

let isValid;
this.pseudoClassExpression = false;
if(this.parser.type == "$" && this.parser.extended) {
isValid = true;
} else if(this.parser.type == "$" && !this.parser.extended) {
let matches = /(.+?)\s*\{(.*)\}\s*$/.exec(parsed.suffix);
isValid = this.isValidSelector(matches[1].trim()) && isValidStyle(matches[2].trim());
this.shouldObserveAttributes = false;
this.shouldObserveCharacterData = false;

if(this.parser.type == "$") {
if(this.parser.snippet)
isValid = true;
else if(this.parser.extended) {
let matches = /(.+?)\s*\{(.*)\}\s*$/.exec(parsed.suffix);
isValid = this.isValidSelector(matches[1].trim());
if(!isValid && reprocSelector.test(matches[1].trim()) && isValidStyle(matches[2].trim())) {
let tasks;
[isValid, tasks] = this.parseProcedure(matches[1].trim());
this.pseudoClassExpression = true;
parsed.suffix = JSON.stringify({'tasks': tasks, 'style': matches[2].trim(), 'attr': this.shouldObserveAttributes, 'data': this.shouldObserveCharacterData});
}
} else {
let matches = /(.+?)\s*\{(.*)\}\s*$/.exec(parsed.suffix);
isValid = this.isValidSelector(matches[1].trim()) && isValidStyle(matches[2].trim());
}
}
else {
isValid = this.isValidSelector(parsed.suffix);
if(!isValid && reprocSelector.test(parsed.suffix)) {
let tasks;
[isValid, tasks] = this.parseProcedure(parsed.suffix);
this.pseudoClassExpression = true;
parsed.suffix = JSON.stringify(tasks);
parsed.suffix = JSON.stringify({'tasks': tasks, 'style': "", 'attr': this.shouldObserveAttributes, 'data': this.shouldObserveCharacterData});
}
}
// For hostname- or entity-based filters, class- or id-based selectors are
Expand Down Expand Up @@ -911,9 +959,9 @@
hash = this.pseudoClassExpression ? makeHash(unhide, domain, this.domainHashMask, this.procedureMask) : makeHash(unhide, domain, this.domainHashMask);
}
let hshash = µb.tokenHash(hostname);
if(parsed.type == "$" && parsed.extended)
if(parsed.type == "$" && parsed.snippet)
out.push(['hs+', hash, hshash, parsed.suffix]);
else if(parsed.type == "$" && !parsed.extended)
else if(parsed.type == "$")
out.push(['hs', hash, hshash, parsed.suffix]);
else
out.push(['h', hash, hshash, parsed.suffix]);
Expand All @@ -923,9 +971,9 @@

FilterContainer.prototype.compileEntitySelector = function(hostname, parsed, out) {
let entity = hostname.slice(0, -2);
if(parsed.type == "$" && parsed.extended)
if(parsed.type == "$" && parsed.snippet)
out.push(['es+', entity, parsed.suffix]);
else if(parsed.type == "$" && !parsed.extended)
else if(parsed.type == "$")
out.push(['es', entity, parsed.suffix]);
else
out.push(['e', entity, parsed.suffix]);
Expand Down Expand Up @@ -1359,9 +1407,11 @@
cosmeticDonthide: [],
netHide: [],
netCollapse: µb.userSettings.collapseBlocked,
cosmeticUserCss: []
cosmeticUserCss: [],
shouldObserveAttributes: false,
shouldObserveCharacterData: false
};
if(options.skipCosmeticFiltering){
if(options.skipCosmeticFiltering) {
return r;
}

Expand Down Expand Up @@ -1401,6 +1451,9 @@
if(this.hostnameFilterDataView.hasOwnProperty("style")) {
hash = makeHash(0, domain, this.domainHashMask);
this.hostnameFilterDataView["style"].retrieve(hosthashes, hash, r.cosmeticUserCss);

hash = makeHash(0, domain, this.domainHashMask, this.procedureMask);
this.hostnameFilterDataView["style"].retrieve(hosthashes, hash, r.procedureHide);
}

// No entity exceptions as of now
Expand All @@ -1410,8 +1463,17 @@
hash = makeHash(0, domain, this.domainHashMask, this.procedureMask);
this.hostnameFilterDataView[flag].retrieve(hosthashes, hash, r.procedureHide);

if(r.procedureHide.length > 0) {
r.shouldObserveAttributes = r.procedureHide.some(selector => selector.indexOf("\"attr\":true") !== -1);
r.shouldObserveCharacterData = r.procedureHide.some(selector => selector.indexOf("\"data\":true") !== -1);
}

if(request.procedureSelectorsOnly) {
return r.procedureHide;
return {
procedureHide :r.procedureHide,
shouldObserveAttributes: r.shouldObserveAttributes,
shouldObserveCharacterData: r.shouldObserveCharacterData
};
}

// https://github.com/uBlockAdmin/uBlock/issues/188
Expand Down
2 changes: 1 addition & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ var onMessage = function(request, sender, callback) {
};
if(!response.shutdown && !pageStore.applyDocumentFiltering) {
if ( request.selectors != "" ) {
details.code = request.selectors + '\n{display:none!important;}';
details.code = request.selectors;
vAPI.insertCSS(request.tabId, details);
}
}
Expand Down
22 changes: 0 additions & 22 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,6 @@
µBlock.getAvailableLists = function(callback) {
var availableLists = {};
var relocationMap = {};
let tempFLChangeMap = new Map([
["assets/thirdparties/abp-filters-anti-cv/english.txt", "assets/thirdparties/raw.githubusercontent.com/abp-filters-anti-cv/english.txt"],
["assets/thirdparties/adblock-nocoin-list/nocoin.txt", "assets/thirdparties/raw.githubusercontent.com/adblock-nocoin-list/nocoin.txt"],
["assets/thirdparties/cjxlist1.googlecode.com/svn/cjxlist.txt", "assets/thirdparties/raw.githubusercontent.com/cjx82630/cjxlist/cjxlist.txt"],
["assets/thirdparties/dl.dropboxusercontent.com/u/1289327/abpxfiles/filtri.txt", "assets/thirdparties/raw.githubusercontent.com/gioxx/filtri.txt"],
["assets/thirdparties/gitorious.org/adblock-latvian/adblock-latvian/raw/master_lists/latvian-list.txt", "assets/thirdparties/adblock-latvian/latvian-list.txt"],
["assets/thirdparties/home.fredfiber.no/langsholt/adblock.txt", "assets/thirdparties/raw.githubusercontent.com/DandelionSprout/adfilt/NorwegianList.txt"],
["assets/thirdparties/indonesianadblockrules.googlecode.com/hg/subscriptions/abpindo.txt", "assets/thirdparties/raw.githubusercontent.com/indonesianadblockrules/subscriptions/abpindo.txt"],
["assets/thirdparties/liste-ar-adblock.googlecode.com/hg/Liste_AR.txt", "assets/thirdparties/easylist-downloads.adblockplus.org/Liste_AR.txt"],
["assets/thirdparties/raw.githubusercontent.com/AdBlockPlusIsrael/EasyListHebrew/master/EasyListHebrew.txt", "assets/thirdparties/raw.githubusercontent.com/EasyListHebrew/master/EasyListHebrew.txt"],
["assets/thirdparties/raw.githubusercontent.com/adblockpolska/Adblock_PL_List/master/adblock_polska.txt", "assets/thirdparties/raw.githubusercontent.com/polish-adblock-filters/adblock.txt"],
["assets/thirdparties/raw.githubusercontent.com/wiltteri/wiltteri.txt/master/wiltteri.txt", "assets/thirdparties/raw.githubusercontent.com/finnish-easylist-addition/Finland_adb.txt"],
["assets/thirdparties/spam404bl.com/spam404scamlist.txt", "assets/thirdparties/raw.githubusercontent.com/Spam404/lists/adblock-list.txt"],
["assets/thirdparties/www.fanboy.co.nz/fanboy-korean.txt", "assets/thirdparties/raw.githubusercontent.com/adblock-korea-contrib/filter.txt"],
["assets/thirdparties/www.fanboy.co.nz/fanboy-swedish.txt", "assets/thirdparties/raw.githubusercontent.com/Frellwits-filter-lists/Frellwits-Swedish-Filter.txt"],
["assets/thirdparties/www.fanboy.co.nz/fanboy-vietnam.txt", "assets/thirdparties/raw.githubusercontent.com/abpvn/abpvn.txt"],
["assets/thirdparties/www.zoso.ro/pages/rolist.txt", "assets/thirdparties/raw.githubusercontent.com/ROad-Block/road-block-filters-light.txt"]
]);

var locationOfAA = 'assets/thirdparties/easylist-downloads.adblockplus.org/exceptionrules.txt';
var fixLocation = function(location) {
// https://github.com/uBlockAdmin/uBlock/issues/418
Expand Down Expand Up @@ -244,9 +225,6 @@
off = lists[location].off === true;
}
}
if(tempFLChangeMap.has(location)) {
location = tempFLChangeMap.get(location);
}
availableEntry = availableLists[location];
if ( availableEntry === undefined ) {
µb.purgeFilterList(location);
Expand Down
2 changes: 1 addition & 1 deletion src/js/ublock.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ https://github.com/darkskyapp/string-hash/blob/master/index.js
reParams.lastIndex = 0;
let matches;
while ( matches = reParams.exec(scriptlets)) {
scriptlets = scriptlets.replace(matches[0], args[matches[2] - 1]);
scriptlets = scriptlets.replace(matches[0], args[matches[2] - 1] === undefined ? null : args[matches[2] - 1]);
}
return scriptlets;
}
Expand Down

0 comments on commit 4168ac8

Please sign in to comment.