mirror of https://github.com/gorhill/uBlock.git
parent
28aee88a7b
commit
46d36cb0b0
|
@ -204,6 +204,9 @@ const FilterContainer = function() {
|
||||||
// specific filters
|
// specific filters
|
||||||
this.specificFilters = new µb.staticExtFilteringEngine.HostnameBasedDB(2);
|
this.specificFilters = new µb.staticExtFilteringEngine.HostnameBasedDB(2);
|
||||||
|
|
||||||
|
// temporary filters
|
||||||
|
this.sessionFilterDB = new µb.staticExtFilteringEngine.SessionDB();
|
||||||
|
|
||||||
// low generic cosmetic filters, organized by id/class then simple/complex.
|
// low generic cosmetic filters, organized by id/class then simple/complex.
|
||||||
this.lowlyGeneric = Object.create(null);
|
this.lowlyGeneric = Object.create(null);
|
||||||
this.lowlyGeneric.id = {
|
this.lowlyGeneric.id = {
|
||||||
|
@ -827,7 +830,7 @@ FilterContainer.prototype.randomAlphaToken = function() {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
FilterContainer.prototype.getSession = function() {
|
FilterContainer.prototype.getSession = function() {
|
||||||
return this.specificFilters.session;
|
return this.sessionFilterDB;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -997,7 +1000,9 @@ FilterContainer.prototype.retrieveSpecificSelectors = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve temporary filters
|
// Retrieve temporary filters
|
||||||
this.specificFilters.session.retrieve([ dummySet, exceptionSet ]);
|
if ( this.sessionFilterDB.isNotEmpty ) {
|
||||||
|
this.sessionFilterDB.retrieve([ null, exceptionSet ]);
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve filters with a non-empty hostname
|
// Retrieve filters with a non-empty hostname
|
||||||
this.specificFilters.retrieve(
|
this.specificFilters.retrieve(
|
||||||
|
|
|
@ -28,10 +28,11 @@
|
||||||
const pselectors = new Map();
|
const pselectors = new Map();
|
||||||
const duplicates = new Set();
|
const duplicates = new Set();
|
||||||
|
|
||||||
let filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(2),
|
const filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(2);
|
||||||
acceptedCount = 0,
|
const sessionFilterDB = new µb.staticExtFilteringEngine.SessionDB();
|
||||||
discardedCount = 0,
|
let acceptedCount = 0;
|
||||||
docRegister;
|
let discardedCount = 0;
|
||||||
|
let docRegister;
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
get acceptedCount() {
|
get acceptedCount() {
|
||||||
|
@ -335,7 +336,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
api.getSession = function() {
|
api.getSession = function() {
|
||||||
return filterDB.session;
|
return sessionFilterDB;
|
||||||
};
|
};
|
||||||
|
|
||||||
api.retrieve = function(details) {
|
api.retrieve = function(details) {
|
||||||
|
@ -354,7 +355,9 @@
|
||||||
const procedurals = new Set();
|
const procedurals = new Set();
|
||||||
const exceptions = new Set();
|
const exceptions = new Set();
|
||||||
|
|
||||||
filterDB.session.retrieve([ new Set(), exceptions ]);
|
if ( sessionFilterDB.isNotEmpty ) {
|
||||||
|
sessionFilterDB.retrieve([ null, exceptions ]);
|
||||||
|
}
|
||||||
filterDB.retrieve(
|
filterDB.retrieve(
|
||||||
hostname,
|
hostname,
|
||||||
[ plains, exceptions, procedurals, exceptions ]
|
[ plains, exceptions, procedurals, exceptions ]
|
||||||
|
@ -415,7 +418,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
api.fromSelfie = function(selfie) {
|
api.fromSelfie = function(selfie) {
|
||||||
filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(2, selfie);
|
filterDB.fromSelfie(selfie);
|
||||||
pselectors.clear();
|
pselectors.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1451,14 +1451,11 @@ const reloadTab = function(ev) {
|
||||||
span.className = 'filter';
|
span.className = 'filter';
|
||||||
span.textContent = selector;
|
span.textContent = selector;
|
||||||
fragment.appendChild(span);
|
fragment.appendChild(span);
|
||||||
let isTemporaryException = false;
|
const isTemporaryException = await messaging.send('loggerUI', {
|
||||||
if ( match[0] === '#@#' ) {
|
|
||||||
isTemporaryException = await messaging.send('loggerUI', {
|
|
||||||
what: 'hasTemporaryException',
|
what: 'hasTemporaryException',
|
||||||
filter,
|
filter,
|
||||||
});
|
});
|
||||||
receiver.classList.toggle('exceptored', isTemporaryException);
|
receiver.classList.toggle('exceptored', isTemporaryException);
|
||||||
}
|
|
||||||
if ( match[0] === '##' || isTemporaryException ) {
|
if ( match[0] === '##' || isTemporaryException ) {
|
||||||
receiver.children[2].style.visibility = '';
|
receiver.children[2].style.visibility = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,15 @@
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
µBlock.scriptletFilteringEngine = (function() {
|
µBlock.scriptletFilteringEngine = (function() {
|
||||||
const µb = µBlock,
|
const µb = µBlock;
|
||||||
duplicates = new Set(),
|
const duplicates = new Set();
|
||||||
scriptletCache = new µb.MRUCache(32),
|
const scriptletCache = new µb.MRUCache(32);
|
||||||
reEscapeScriptArg = /[\\'"]/g;
|
const reEscapeScriptArg = /[\\'"]/g;
|
||||||
|
|
||||||
let acceptedCount = 0,
|
const scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(1);
|
||||||
discardedCount = 0,
|
const sessionScriptletDB = new µb.staticExtFilteringEngine.SessionDB();
|
||||||
scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(1);
|
let acceptedCount = 0;
|
||||||
|
let discardedCount = 0;
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
get acceptedCount() {
|
get acceptedCount() {
|
||||||
|
@ -343,7 +344,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
api.getSession = function() {
|
api.getSession = function() {
|
||||||
return scriptletDB.session;
|
return sessionScriptletDB;
|
||||||
};
|
};
|
||||||
|
|
||||||
const scriptlets$ = new Set();
|
const scriptlets$ = new Set();
|
||||||
|
@ -371,7 +372,9 @@
|
||||||
scriptlets$.clear();
|
scriptlets$.clear();
|
||||||
exceptions$.clear();
|
exceptions$.clear();
|
||||||
|
|
||||||
scriptletDB.session.retrieve([ scriptlets$, exceptions$ ]);
|
if ( sessionScriptletDB.isNotEmpty ) {
|
||||||
|
sessionScriptletDB.retrieve([ null, exceptions$ ]);
|
||||||
|
}
|
||||||
scriptletDB.retrieve(hostname, [ scriptlets$, exceptions$ ]);
|
scriptletDB.retrieve(hostname, [ scriptlets$, exceptions$ ]);
|
||||||
if ( request.entity !== '' ) {
|
if ( request.entity !== '' ) {
|
||||||
scriptletDB.retrieve(
|
scriptletDB.retrieve(
|
||||||
|
@ -464,7 +467,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
api.fromSelfie = function(selfie) {
|
api.fromSelfie = function(selfie) {
|
||||||
scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(1, selfie);
|
scriptletDB.fromSelfie(selfie);
|
||||||
};
|
};
|
||||||
|
|
||||||
api.benchmark = async function() {
|
api.benchmark = async function() {
|
||||||
|
|
|
@ -511,7 +511,6 @@
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
api.HostnameBasedDB = class {
|
api.HostnameBasedDB = class {
|
||||||
|
|
||||||
constructor(nBits, selfie = undefined) {
|
constructor(nBits, selfie = undefined) {
|
||||||
this.nBits = nBits;
|
this.nBits = nBits;
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
|
@ -524,41 +523,6 @@
|
||||||
// Array of strings (selectors and pseudo-selectors)
|
// Array of strings (selectors and pseudo-selectors)
|
||||||
this.strSlots = [];
|
this.strSlots = [];
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
// Temporary set
|
|
||||||
this.session = {
|
|
||||||
collection: new Map(),
|
|
||||||
add: function(bits, s) {
|
|
||||||
const bucket = this.collection.get(bits);
|
|
||||||
if ( bucket === undefined ) {
|
|
||||||
this.collection.set(bits, new Set([ s ]));
|
|
||||||
} else {
|
|
||||||
bucket.add(s);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
remove: function(bits, s) {
|
|
||||||
const bucket = this.collection.get(bits);
|
|
||||||
if ( bucket === undefined ) { return; }
|
|
||||||
bucket.delete(s);
|
|
||||||
if ( bucket.size !== 0 ) { return; }
|
|
||||||
this.collection.delete(bits);
|
|
||||||
},
|
|
||||||
retrieve(out) {
|
|
||||||
const mask = out.length - 1;
|
|
||||||
for ( const [ bits, bucket ] of this.collection ) {
|
|
||||||
for ( const s of bucket ) {
|
|
||||||
out[bits & mask].add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
has(bits, s) {
|
|
||||||
const selectors = this.collection.get(bits);
|
|
||||||
return selectors !== undefined && selectors.has(s);
|
|
||||||
},
|
|
||||||
clear() {
|
|
||||||
this.collection.clear();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( selfie !== undefined ) {
|
if ( selfie !== undefined ) {
|
||||||
this.fromSelfie(selfie);
|
this.fromSelfie(selfie);
|
||||||
}
|
}
|
||||||
|
@ -675,6 +639,47 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
api.SessionDB = class {
|
||||||
|
constructor() {
|
||||||
|
this.db = new Map();
|
||||||
|
}
|
||||||
|
add(bits, s) {
|
||||||
|
const bucket = this.db.get(bits);
|
||||||
|
if ( bucket === undefined ) {
|
||||||
|
this.db.set(bits, new Set([ s ]));
|
||||||
|
} else {
|
||||||
|
bucket.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remove(bits, s) {
|
||||||
|
const bucket = this.db.get(bits);
|
||||||
|
if ( bucket === undefined ) { return; }
|
||||||
|
bucket.delete(s);
|
||||||
|
if ( bucket.size !== 0 ) { return; }
|
||||||
|
this.db.delete(bits);
|
||||||
|
}
|
||||||
|
retrieve(out) {
|
||||||
|
const mask = out.length - 1;
|
||||||
|
for ( const [ bits, bucket ] of this.db ) {
|
||||||
|
const i = bits & mask;
|
||||||
|
if ( out[i] instanceof Object === false ) { continue; }
|
||||||
|
for ( const s of bucket ) {
|
||||||
|
out[i].add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
has(bits, s) {
|
||||||
|
const selectors = this.db.get(bits);
|
||||||
|
return selectors !== undefined && selectors.has(s);
|
||||||
|
}
|
||||||
|
clear() {
|
||||||
|
this.db.clear();
|
||||||
|
}
|
||||||
|
get isNotEmpty() {
|
||||||
|
return this.db.size !== 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
// Public methods
|
// Public methods
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue