1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-02 10:24:59 +12:00
uMatrix/src/js/background.js

161 lines
4.5 KiB
JavaScript
Raw Normal View History

2014-10-18 08:01:09 +13:00
/*******************************************************************************
uMatrix - a browser extension to black/white list requests.
Copyright (C) 2014-2017 Raymond Hill
2014-10-18 08:01:09 +13:00
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uMatrix
*/
'use strict';
2014-10-18 08:01:09 +13:00
/******************************************************************************/
var µMatrix = (function() { // jshint ignore:line
2014-10-18 08:01:09 +13:00
/******************************************************************************/
var oneSecond = 1000;
var oneMinute = 60 * oneSecond;
var oneHour = 60 * oneMinute;
var oneDay = 24 * oneHour;
2015-05-14 06:32:16 +12:00
/******************************************************************************/
/******************************************************************************/
2015-05-14 06:32:16 +12:00
var _RequestStats = function() {
this.reset();
};
_RequestStats.prototype.reset = function() {
this.all =
this.doc =
this.frame =
this.script =
this.css =
this.image =
2017-04-28 00:10:54 +12:00
this.media =
2015-05-14 06:32:16 +12:00
this.xhr =
this.other =
this.cookie = 0;
};
/******************************************************************************/
var RequestStats = function() {
this.allowed = new _RequestStats();
this.blocked = new _RequestStats();
};
RequestStats.prototype.reset = function() {
this.blocked.reset();
this.allowed.reset();
};
RequestStats.prototype.record = function(type, blocked) {
// Remember: always test against **false**
if ( blocked !== false ) {
this.blocked[type] += 1;
this.blocked.all += 1;
} else {
this.allowed[type] += 1;
this.allowed.all += 1;
}
};
var requestStatsFactory = function() {
return new RequestStats();
};
/******************************************************************************/
/******************************************************************************/
2014-10-18 08:01:09 +13:00
return {
onBeforeStartQueue: [],
2014-10-18 08:01:09 +13:00
userSettings: {
alwaysDetachLogger: false,
2014-10-24 12:40:48 +13:00
autoUpdate: false,
2014-10-18 08:01:09 +13:00
clearBrowserCache: true,
clearBrowserCacheAfter: 60,
cloudStorageEnabled: false,
collapseBlacklisted: true,
collapseBlocked: false,
2014-10-18 08:01:09 +13:00
colorBlindFriendly: false,
deleteCookies: false,
deleteUnusedSessionCookies: false,
deleteUnusedSessionCookiesAfter: 60,
deleteLocalStorage: false,
displayTextSize: '13px',
2014-10-24 12:40:48 +13:00
externalHostsFiles: '',
2015-05-08 10:38:29 +12:00
iconBadgeEnabled: false,
maxLoggedRequests: 1000,
2017-11-30 08:40:18 +13:00
popupCollapseAllDomains: false,
popupCollapseBlacklistedDomains: false,
2014-10-24 12:40:48 +13:00
popupScopeLevel: 'domain',
2014-10-18 08:01:09 +13:00
processHyperlinkAuditing: true,
processReferer: false
2014-10-18 08:01:09 +13:00
},
clearBrowserCacheCycle: 0,
updateAssetsEvery: 11 * oneDay + 1 * oneHour + 1 * oneMinute + 1 * oneSecond,
firstUpdateAfter: 11 * oneMinute,
nextUpdateAfter: 11 * oneHour,
assetsBootstrapLocation: 'assets/assets.json',
pslAssetKey: 'public_suffix_list.dat',
2014-10-24 12:40:48 +13:00
// list of live hosts files
liveHostsFiles: {
},
2014-10-18 08:01:09 +13:00
// urls stats are kept on the back burner while waiting to be reactivated
// in a tab or another.
pageStores: {},
pageStoresToken: 0,
pageStoreCemetery: {},
2014-10-18 08:01:09 +13:00
// page url => permission scope
tMatrix: null,
pMatrix: null,
ubiquitousBlacklist: null,
// various stats
2015-05-14 06:32:16 +12:00
requestStatsFactory: requestStatsFactory,
requestStats: requestStatsFactory(),
2014-10-18 08:01:09 +13:00
cookieRemovedCounter: 0,
localStorageRemovedCounter: 0,
cookieHeaderFoiledCounter: 0,
refererHeaderFoiledCounter: 0,
hyperlinkAuditingFoiledCounter: 0,
browserCacheClearedCounter: 0,
storageUsed: 0,
// record what the browser is doing behind the scene
behindTheSceneScope: 'behind-the-scene',
2014-10-18 08:01:09 +13:00
2014-10-24 12:40:48 +13:00
noopFunc: function(){},
2014-10-18 08:01:09 +13:00
// so that I don't have to care for last comma
dummy: 0
};
/******************************************************************************/
})();
/******************************************************************************/