/******************************************************************************* ηMatrix - a browser extension to black/white list requests. Copyright (C) 2014-2019 Raymond Hill Copyright (C) 2019-2020 Alessio Vanni 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://libregit.spks.xyz/heckyel/ematrix uMatrix Home: https://github.com/gorhill/uMatrix */ 'use strict'; // Default handler (function () { Cu.import('chrome://ematrix/content/lib/Tools.jsm'); let ηm = ηMatrix; // Default is for commonly used message. function onMessage(request, sender, callback) { // Async switch (request.what) { case 'getAssetContent': ηm.assets.get(request.url, { dontCache: true, }, callback); return; case 'selectHostsFiles': ηm.selectHostsFiles(request, callback); return; default: break; } // Sync let response; switch (request.what) { case 'forceReloadTab': ηm.forceReload(request.tabId, request.bypassCache); break; case 'forceUpdateAssets': ηm.scheduleAssetUpdater(0); ηm.assets.updateStart({ delay: 2000, }); break; case 'getUserSettings': response = { userSettings: ηm.userSettings, matrixSwitches: { 'https-strict': ηm.pMatrix.evaluateSwitch('https-strict', '*') === 1, 'referrer-spoof': ηm.pMatrix.evaluateSwitch('referrer-spoof', '*') === 1, 'noscript-spoof': ηm.pMatrix.evaluateSwitch('noscript-spoof', '*') === 1, }, }; break; case 'gotoExtensionURL': Tools.gotoExtensionURL({ api: vAPI, details: request, matrix: ηm, }); break; case 'gotoURL': Tools.gotoURL({ api: vAPI, details: request, }); break; case 'mustBlock': response = ηm.mustBlock(request.scope, request.hostname,request.type); break; case 'readRawSettings': response = ηm.stringFromRawSettings(); break; case 'reloadHostsFiles': ηm.reloadHostsFiles(); break; case 'setMatrixSwitch': ηm.tMatrix.setSwitch(request.switchName, '*', request.state); if (ηm.pMatrix.setSwitch(request.switchName, '*', request.state)) { ηm.saveMatrix(); } break; case 'userSettings': if (request.hasOwnProperty('value') === false) { request.value = undefined; } response = ηm.changeUserSettings(request.name, request.value); break; case 'writeRawSettings': ηm.rawSettingsFromString(request.content); break; default: return vAPI.messaging.UNHANDLED; } callback(response); } vAPI.messaging.setup(onMessage); })(); (function () { // popup.js let ηm = ηMatrix; // Constructor is faster than object literal // ηMatrix: really? I'll take your word for it... let RowSnapshot = function(srcHostname, desHostname, desDomain) { this.domain = desDomain; this.temporary = ηm.tMatrix.evaluateRowZXY(srcHostname, desHostname); this.permanent = ηm.pMatrix.evaluateRowZXY(srcHostname, desHostname); this.counts = RowSnapshot.counts.slice(); this.totals = RowSnapshot.counts.slice(); }; RowSnapshot.counts = (function () { let aa = []; let n = ηm.Matrix.columnHeaderIndices.size for (let i=0; i