|
|
@ -19,31 +19,19 @@
|
|
|
|
Home: https://github.com/gorhill/uMatrix
|
|
|
|
Home: https://github.com/gorhill/uMatrix
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* jshint bitwise: false, boss: true */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
A PageRequestStats object is used to store distinct network requests.
|
|
|
|
|
|
|
|
This is used to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- remember which hostname/type were seen
|
|
|
|
|
|
|
|
- count the number of distinct URLs for any given hostname-type pair
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
µMatrix.pageRequestStatsFactory = (function() {
|
|
|
|
µMatrix.pageStoreFactory = (function() {
|
|
|
|
|
|
|
|
|
|
|
|
var µm = µMatrix;
|
|
|
|
var µm = µMatrix;
|
|
|
|
var µmuri;
|
|
|
|
var pageStoreJunkyard = [];
|
|
|
|
var pageRequestStoreJunkyard = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ref: Given a URL, returns a (somewhat) unique 32-bit value
|
|
|
|
// Ref: Given a URL, returns a (somewhat) unique 32-bit value
|
|
|
|
// Based on: FNV32a
|
|
|
|
// Based on: FNV32a
|
|
|
|
// http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-reference-source
|
|
|
|
// http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-reference-source
|
|
|
|
// The rest is custom, suited for µMatrix.
|
|
|
|
// The rest is custom, suited for µMatrix.
|
|
|
|
|
|
|
|
|
|
|
|
var uidFromURL = function(uri) {
|
|
|
|
var uidFromURL = function(uri) {
|
|
|
|
var hint = 0x811c9dc5;
|
|
|
|
var hint = 0x811c9dc5;
|
|
|
|
var i = uri.length;
|
|
|
|
var i = uri.length;
|
|
|
@ -55,50 +43,6 @@
|
|
|
|
return hint;
|
|
|
|
return hint;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var PageRequestStats = function() {
|
|
|
|
|
|
|
|
this.hostnameTypeCells = new Map();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PageRequestStats.prototype = {
|
|
|
|
|
|
|
|
dispose: function() {
|
|
|
|
|
|
|
|
this.hostnameTypeCells.clear();
|
|
|
|
|
|
|
|
if ( pageRequestStoreJunkyard.length < 8 ) {
|
|
|
|
|
|
|
|
pageRequestStoreJunkyard.push(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
createEntryIfNotExists: function(url, type) {
|
|
|
|
|
|
|
|
var hn = µmuri.hostnameFromURI(url),
|
|
|
|
|
|
|
|
key = hn + ' ' + type,
|
|
|
|
|
|
|
|
uids = this.hostnameTypeCells.get(key);
|
|
|
|
|
|
|
|
if ( uids === undefined ) {
|
|
|
|
|
|
|
|
this.hostnameTypeCells.set(key, (uids = new Set()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ( uids.size > 99 ) { return false; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var uid = uidFromURL(url);
|
|
|
|
|
|
|
|
if ( uids.has(uid) ) { return false; }
|
|
|
|
|
|
|
|
uids.add(uid);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return function pageRequestStatsFactory() {
|
|
|
|
|
|
|
|
if ( pageRequestStoreJunkyard.length !== 0 ) {
|
|
|
|
|
|
|
|
return pageRequestStoreJunkyard.pop();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( µmuri === undefined ) { µmuri = µm.URI; }
|
|
|
|
|
|
|
|
return new PageRequestStats();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
µMatrix.pageStoreFactory = (function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var µm = µMatrix;
|
|
|
|
|
|
|
|
var pageStoreJunkyard = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function PageStore(tabContext) {
|
|
|
|
function PageStore(tabContext) {
|
|
|
|
this.requestStats = µm.requestStatsFactory();
|
|
|
|
this.requestStats = µm.requestStatsFactory();
|
|
|
|
this.off = false;
|
|
|
|
this.off = false;
|
|
|
@ -113,8 +57,8 @@
|
|
|
|
this.pageHostname = tabContext.rootHostname;
|
|
|
|
this.pageHostname = tabContext.rootHostname;
|
|
|
|
this.pageDomain = tabContext.rootDomain;
|
|
|
|
this.pageDomain = tabContext.rootDomain;
|
|
|
|
this.title = '';
|
|
|
|
this.title = '';
|
|
|
|
this.requests = µm.pageRequestStatsFactory();
|
|
|
|
this.hostnameTypeCells = new Map();
|
|
|
|
this.domains = {};
|
|
|
|
this.domains = new Set();
|
|
|
|
this.allHostnamesString = ' ';
|
|
|
|
this.allHostnamesString = ' ';
|
|
|
|
this.requestStats.reset();
|
|
|
|
this.requestStats.reset();
|
|
|
|
this.distinctRequestCount = 0;
|
|
|
|
this.distinctRequestCount = 0;
|
|
|
@ -126,13 +70,13 @@
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dispose: function() {
|
|
|
|
dispose: function() {
|
|
|
|
this.requests.dispose();
|
|
|
|
this.hostnameTypeCells.clear();
|
|
|
|
this.rawUrl = '';
|
|
|
|
this.rawUrl = '';
|
|
|
|
this.pageUrl = '';
|
|
|
|
this.pageUrl = '';
|
|
|
|
this.pageHostname = '';
|
|
|
|
this.pageHostname = '';
|
|
|
|
this.pageDomain = '';
|
|
|
|
this.pageDomain = '';
|
|
|
|
this.title = '';
|
|
|
|
this.title = '';
|
|
|
|
this.domains = {};
|
|
|
|
this.domains.clear();
|
|
|
|
this.allHostnamesString = ' ';
|
|
|
|
this.allHostnamesString = ' ';
|
|
|
|
if ( this.incinerationTimer !== null ) {
|
|
|
|
if ( this.incinerationTimer !== null ) {
|
|
|
|
clearTimeout(this.incinerationTimer);
|
|
|
|
clearTimeout(this.incinerationTimer);
|
|
|
@ -143,9 +87,22 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
recordRequest: function(type, url, block) {
|
|
|
|
recordRequest: function(type, url, block) {
|
|
|
|
if ( this.requests.createEntryIfNotExists(url, type) === false ) {
|
|
|
|
var hostname = µm.URI.hostnameFromURI(url);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Store distinct network requests. This is used to:
|
|
|
|
|
|
|
|
// - remember which hostname/type were seen
|
|
|
|
|
|
|
|
// - count the number of distinct URLs for any given
|
|
|
|
|
|
|
|
// hostname-type pair
|
|
|
|
|
|
|
|
var key = hostname + ' ' + type,
|
|
|
|
|
|
|
|
uids = this.hostnameTypeCells.get(key);
|
|
|
|
|
|
|
|
if ( uids === undefined ) {
|
|
|
|
|
|
|
|
this.hostnameTypeCells.set(key, (uids = new Set()));
|
|
|
|
|
|
|
|
} else if ( uids.size > 99 ) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var uid = uidFromURL(url);
|
|
|
|
|
|
|
|
if ( uids.has(uid) ) { return; }
|
|
|
|
|
|
|
|
uids.add(uid);
|
|
|
|
|
|
|
|
|
|
|
|
// Count blocked/allowed requests
|
|
|
|
// Count blocked/allowed requests
|
|
|
|
this.requestStats.record(type, block);
|
|
|
|
this.requestStats.record(type, block);
|
|
|
@ -161,13 +118,11 @@
|
|
|
|
this.perLoadAllowedRequestCount++;
|
|
|
|
this.perLoadAllowedRequestCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var hostname = µm.URI.hostnameFromURI(url);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.distinctRequestCount++;
|
|
|
|
this.distinctRequestCount++;
|
|
|
|
this.mtxCountModifiedTime = Date.now();
|
|
|
|
this.mtxCountModifiedTime = Date.now();
|
|
|
|
|
|
|
|
|
|
|
|
if ( this.domains.hasOwnProperty(hostname) === false ) {
|
|
|
|
if ( this.domains.has(hostname) === false ) {
|
|
|
|
this.domains[hostname] = true;
|
|
|
|
this.domains.add(hostname);
|
|
|
|
this.allHostnamesString += hostname + ' ';
|
|
|
|
this.allHostnamesString += hostname + ' ';
|
|
|
|
this.mtxContentModifiedTime = Date.now();
|
|
|
|
this.mtxContentModifiedTime = Date.now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|