Raymond Hill 2018-09-07 09:11:07 -04:00
parent 108fb425fc
commit 89c073f3e9
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 23 additions and 34 deletions

View File

@ -139,7 +139,7 @@ var µBlock = (function() { // jshint ignore:line
// Read-only
systemSettings: {
compiledMagic: 3, // Increase when compiled format changes
compiledMagic: 4, // Increase when compiled format changes
selfieMagic: 4 // Increase when selfie format changes
},

View File

@ -1,7 +1,7 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2017-2018 Raymond Hill
Copyright (C) 2017-present Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -216,7 +216,7 @@
'cosmetic',
{
source: 'cosmetic',
raw: (isException ? '#@#' : '##') + 'script:inject(' + token + ')'
raw: (isException ? '#@#' : '##') + '+js(' + token + ')'
},
'dom',
details.url,
@ -253,14 +253,14 @@
// Ignore instances of exception filter with negated hostnames,
// because there is no way to create an exception to an exception.
var µburi = µb.URI;
let µburi = µb.URI;
for ( var hostname of parsed.hostnames ) {
var negated = hostname.charCodeAt(0) === 0x7E /* '~' */;
for ( let hostname of parsed.hostnames ) {
let negated = hostname.charCodeAt(0) === 0x7E /* '~' */;
if ( negated ) {
hostname = hostname.slice(1);
}
var hash = µburi.domainFromHostname(hostname);
let hash = µburi.domainFromHostname(hostname);
if ( parsed.exception ) {
if ( negated ) { continue; }
hash = '!' + hash;
@ -272,9 +272,9 @@
};
// 01234567890123456789
// script:inject(token[, arg[, ...]])
// ^ ^
// 14 -1
// +js(token[, arg[, ...]])
// ^ ^
// 4 -1
api.fromCompiledContent = function(reader) {
// 1001 = scriptlet injection
@ -282,17 +282,17 @@
while ( reader.next() ) {
acceptedCount += 1;
var fingerprint = reader.fingerprint();
let fingerprint = reader.fingerprint();
if ( duplicates.has(fingerprint) ) {
discardedCount += 1;
continue;
}
duplicates.add(fingerprint);
var args = reader.args();
let args = reader.args();
if ( args.length < 4 ) { continue; }
scriptletDB.add(
args[1],
{ hostname: args[2], token: args[3].slice(14, -1) }
{ hostname: args[2], token: args[3].slice(4, -1) }
);
}
};

View File

@ -603,9 +603,9 @@
})();
api.compile = function(raw, writer) {
var lpos = raw.indexOf('#');
let lpos = raw.indexOf('#');
if ( lpos === -1 ) { return false; }
var rpos = lpos + 1;
let rpos = lpos + 1;
if ( raw.charCodeAt(rpos) !== 0x23 /* '#' */ ) {
rpos = raw.indexOf('#', rpos + 1);
if ( rpos === -1 ) { return false; }
@ -618,7 +618,7 @@
if ( (rpos - lpos) > 3 ) { return false; }
// Extract the selector.
var suffix = raw.slice(rpos + 1).trim();
let suffix = raw.slice(rpos + 1).trim();
if ( suffix.length === 0 ) { return false; }
parsed.suffix = suffix;
@ -629,7 +629,7 @@
// We have an Adguard/ABP cosmetic filter if and only if the
// character is `$`, `%` or `?`, otherwise it's not a cosmetic
// filter.
var cCode = raw.charCodeAt(rpos - 1);
let cCode = raw.charCodeAt(rpos - 1);
if ( cCode !== 0x23 /* '#' */ && cCode !== 0x40 /* '@' */ ) {
// Adguard's scriptlet injection: not supported.
if ( cCode === 0x25 /* '%' */ ) { return true; }
@ -652,37 +652,26 @@
if ( lpos === 0 ) {
parsed.hostnames = emptyArray;
} else {
var prefix = raw.slice(0, lpos);
let prefix = raw.slice(0, lpos);
parsed.hostnames = prefix.split(reHostnameSeparator);
if ( reHasUnicode.test(prefix) ) {
toASCIIHostnames(parsed.hostnames);
}
}
// Backward compatibility with deprecated syntax.
if ( suffix.startsWith('script:') ) {
// Scriptlet injection engine.
if ( suffix.startsWith('script:inject') ) {
µb.scriptletFilteringEngine.compile(parsed, writer);
return true;
}
// Script tag filtering: courtesy-conversion to HTML filtering.
if ( suffix.startsWith('script:contains') ) {
console.info(
'uBO: ##script:contains(...) is deprecated, ' +
'converting to ##^script:has-text(...)'
);
suffix = suffix.replace(/^script:contains/, '^script:has-text');
parsed.suffix = suffix;
suffix = parsed.suffix = '+js' + suffix.slice(13);
} else if ( suffix.startsWith('script:contains') ) {
suffix = parsed.suffix = '^script:has-text' + suffix.slice(15);
}
}
var c0 = suffix.charCodeAt(0);
let c0 = suffix.charCodeAt(0);
// New shorter syntax for scriptlet injection engine.
if ( c0 === 0x2B /* '+' */ && suffix.startsWith('+js') ) {
// Convert to deprecated syntax for now. Once 1.15.12 is
// widespread, `+js` form will be the official syntax.
parsed.suffix = 'script:inject' + parsed.suffix.slice(3);
µb.scriptletFilteringEngine.compile(parsed, writer);
return true;
}