1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-09 12:22:33 +01:00
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 // Read-only
systemSettings: { systemSettings: {
compiledMagic: 3, // Increase when compiled format changes compiledMagic: 4, // Increase when compiled format changes
selfieMagic: 4 // Increase when selfie format changes selfieMagic: 4 // Increase when selfie format changes
}, },

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock Origin - a browser extension to block requests. 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 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 it under the terms of the GNU General Public License as published by
@ -216,7 +216,7 @@
'cosmetic', 'cosmetic',
{ {
source: 'cosmetic', source: 'cosmetic',
raw: (isException ? '#@#' : '##') + 'script:inject(' + token + ')' raw: (isException ? '#@#' : '##') + '+js(' + token + ')'
}, },
'dom', 'dom',
details.url, details.url,
@ -253,14 +253,14 @@
// Ignore instances of exception filter with negated hostnames, // Ignore instances of exception filter with negated hostnames,
// because there is no way to create an exception to an exception. // 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 ) { for ( let hostname of parsed.hostnames ) {
var negated = hostname.charCodeAt(0) === 0x7E /* '~' */; let negated = hostname.charCodeAt(0) === 0x7E /* '~' */;
if ( negated ) { if ( negated ) {
hostname = hostname.slice(1); hostname = hostname.slice(1);
} }
var hash = µburi.domainFromHostname(hostname); let hash = µburi.domainFromHostname(hostname);
if ( parsed.exception ) { if ( parsed.exception ) {
if ( negated ) { continue; } if ( negated ) { continue; }
hash = '!' + hash; hash = '!' + hash;
@ -272,9 +272,9 @@
}; };
// 01234567890123456789 // 01234567890123456789
// script:inject(token[, arg[, ...]]) // +js(token[, arg[, ...]])
// ^ ^ // ^ ^
// 14 -1 // 4 -1
api.fromCompiledContent = function(reader) { api.fromCompiledContent = function(reader) {
// 1001 = scriptlet injection // 1001 = scriptlet injection
@ -282,17 +282,17 @@
while ( reader.next() ) { while ( reader.next() ) {
acceptedCount += 1; acceptedCount += 1;
var fingerprint = reader.fingerprint(); let fingerprint = reader.fingerprint();
if ( duplicates.has(fingerprint) ) { if ( duplicates.has(fingerprint) ) {
discardedCount += 1; discardedCount += 1;
continue; continue;
} }
duplicates.add(fingerprint); duplicates.add(fingerprint);
var args = reader.args(); let args = reader.args();
if ( args.length < 4 ) { continue; } if ( args.length < 4 ) { continue; }
scriptletDB.add( scriptletDB.add(
args[1], 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) { api.compile = function(raw, writer) {
var lpos = raw.indexOf('#'); let lpos = raw.indexOf('#');
if ( lpos === -1 ) { return false; } if ( lpos === -1 ) { return false; }
var rpos = lpos + 1; let rpos = lpos + 1;
if ( raw.charCodeAt(rpos) !== 0x23 /* '#' */ ) { if ( raw.charCodeAt(rpos) !== 0x23 /* '#' */ ) {
rpos = raw.indexOf('#', rpos + 1); rpos = raw.indexOf('#', rpos + 1);
if ( rpos === -1 ) { return false; } if ( rpos === -1 ) { return false; }
@ -618,7 +618,7 @@
if ( (rpos - lpos) > 3 ) { return false; } if ( (rpos - lpos) > 3 ) { return false; }
// Extract the selector. // Extract the selector.
var suffix = raw.slice(rpos + 1).trim(); let suffix = raw.slice(rpos + 1).trim();
if ( suffix.length === 0 ) { return false; } if ( suffix.length === 0 ) { return false; }
parsed.suffix = suffix; parsed.suffix = suffix;
@ -629,7 +629,7 @@
// We have an Adguard/ABP cosmetic filter if and only if the // We have an Adguard/ABP cosmetic filter if and only if the
// character is `$`, `%` or `?`, otherwise it's not a cosmetic // character is `$`, `%` or `?`, otherwise it's not a cosmetic
// filter. // filter.
var cCode = raw.charCodeAt(rpos - 1); let cCode = raw.charCodeAt(rpos - 1);
if ( cCode !== 0x23 /* '#' */ && cCode !== 0x40 /* '@' */ ) { if ( cCode !== 0x23 /* '#' */ && cCode !== 0x40 /* '@' */ ) {
// Adguard's scriptlet injection: not supported. // Adguard's scriptlet injection: not supported.
if ( cCode === 0x25 /* '%' */ ) { return true; } if ( cCode === 0x25 /* '%' */ ) { return true; }
@ -652,37 +652,26 @@
if ( lpos === 0 ) { if ( lpos === 0 ) {
parsed.hostnames = emptyArray; parsed.hostnames = emptyArray;
} else { } else {
var prefix = raw.slice(0, lpos); let prefix = raw.slice(0, lpos);
parsed.hostnames = prefix.split(reHostnameSeparator); parsed.hostnames = prefix.split(reHostnameSeparator);
if ( reHasUnicode.test(prefix) ) { if ( reHasUnicode.test(prefix) ) {
toASCIIHostnames(parsed.hostnames); toASCIIHostnames(parsed.hostnames);
} }
} }
// Backward compatibility with deprecated syntax.
if ( suffix.startsWith('script:') ) { if ( suffix.startsWith('script:') ) {
// Scriptlet injection engine.
if ( suffix.startsWith('script:inject') ) { if ( suffix.startsWith('script:inject') ) {
µb.scriptletFilteringEngine.compile(parsed, writer); suffix = parsed.suffix = '+js' + suffix.slice(13);
return true; } else if ( suffix.startsWith('script:contains') ) {
} suffix = parsed.suffix = '^script:has-text' + suffix.slice(15);
// 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;
} }
} }
var c0 = suffix.charCodeAt(0); let c0 = suffix.charCodeAt(0);
// New shorter syntax for scriptlet injection engine. // New shorter syntax for scriptlet injection engine.
if ( c0 === 0x2B /* '+' */ && suffix.startsWith('+js') ) { 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); µb.scriptletFilteringEngine.compile(parsed, writer);
return true; return true;
} }