xiMatrix

filter net requests according to source, destination and type  https://addons.mozilla.org/firefox/addon/ximatrix/
git clone https://git.ce9e.org/xiMatrix.git

commit
6cf01e07e35afbe3f4657c6bac7fc173c4110ccd
parent
28599984dab45e2c748e41182cd8e80b15dc6f78
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-10-04 18:23
lint: use const over var in a few places

Diffstat

M src/bg.js 22 +++++++++++-----------
M src/popup.js 22 +++++++++++-----------
M src/settings.js 6 +++---
M src/shared.js 2 +-
M src/storage.js 14 +++++++-------

5 files changed, 33 insertions, 33 deletions


diff --git a/src/bg.js b/src/bg.js

@@ -3,12 +3,12 @@
    3     3 import * as shared from './shared.js';
    4     4 import * as storage from './storage.js';
    5     5 
    6    -1 var glob = function(s, pattern) {
   -1     6 const glob = function(s, pattern) {
    7     7     var p = pattern.split('*');
    8     8     return s.startsWith(p[0]) && s.endsWith(p.at(-1));
    9     9 };
   10    10 
   11    -1 var getHostname = function(url, patterns) {
   -1    11 const getHostname = function(url, patterns) {
   12    12     var u = new URL(url);
   13    13 
   14    14     for (var pattern of patterns) {
@@ -20,7 +20,7 @@ var getHostname = function(url, patterns) {
   20    20     return u.hostname;
   21    21 };
   22    22 
   23    -1 var setRule = async function(context, hostname, type, rule) {
   -1    23 const setRule = async function(context, hostname, type, rule) {
   24    24     var savedRules = await storage.get('savedRules');
   25    25     await storage.change('rules', rules => {
   26    26         if (hostname === 'first-party') {
@@ -47,12 +47,12 @@ var setRule = async function(context, hostname, type, rule) {
   47    47     });
   48    48 };
   49    49 
   50    -1 var getPatterns = async function() {
   -1    50 const getPatterns = async function() {
   51    51     var savedRules = await storage.get('savedRules');
   52    52     return savedRules._patterns || [];
   53    53 };
   54    54 
   55    -1 var getRules = async function(context) {
   -1    55 const getRules = async function(context) {
   56    56     var [rules, savedRules] = await Promise.all([
   57    57         storage.get('rules'),
   58    58         storage.get('savedRules'),
@@ -64,7 +64,7 @@ var getRules = async function(context) {
   64    64     return restricted;
   65    65 };
   66    66 
   67    -1 var increaseTotals = async function(tabId) {
   -1    67 const increaseTotals = async function(tabId) {
   68    68     var value = 0;
   69    69     await storage.change('totals', totals => {
   70    70         value = (totals[tabId] || 0) + 1;
@@ -75,7 +75,7 @@ var increaseTotals = async function(tabId) {
   75    75     await browser.action.setBadgeText({text: '' + value, tabId: tabId});
   76    76 };
   77    77 
   78    -1 var pushRequest = async function(tabId, hostname, type, allowed) {
   -1    78 const pushRequest = async function(tabId, hostname, type, allowed) {
   79    79     await storage.change('requests', requests => {
   80    80         if (!requests[tabId]) {
   81    81             requests[tabId] = {};
@@ -94,7 +94,7 @@ var pushRequest = async function(tabId, hostname, type, allowed) {
   94    94     }
   95    95 };
   96    96 
   97    -1 var clearRequests = async function(tabId) {
   -1    97 const clearRequests = async function(tabId) {
   98    98     await Promise.all([
   99    99         storage.change('requests', requests => {
  100   100             if (requests[tabId]) {
@@ -111,7 +111,7 @@ var clearRequests = async function(tabId) {
  111   111     ]);
  112   112 };
  113   113 
  114    -1 var getCurrentTab = async function() {
   -1   114 const getCurrentTab = async function() {
  115   115     var tabs = await browser.tabs.query({
  116   116         active: true,
  117   117         currentWindow: true,
@@ -192,13 +192,13 @@ browser.webRequest.onBeforeSendHeaders.addListener(async details => {
  192   192     var rules = await getRules(context);
  193   193 
  194   194     if (details.type !== 'main_frame') {
  195    -1         var allowed = shared.shouldAllow(rules, context, hostname, type);
   -1   195         const allowed = shared.shouldAllow(rules, context, hostname, type);
  196   196         await pushRequest(details.tabId, hostname, type, allowed);
  197   197     }
  198   198 
  199   199     var isCookie = h => h.name.toLowerCase() === 'cookie';
  200   200     if (details.requestHeaders.some(isCookie)) {
  201    -1         var allowed = shared.shouldAllow(rules, context, hostname, 'cookie');
   -1   201         const allowed = shared.shouldAllow(rules, context, hostname, 'cookie');
  202   202         await pushRequest(details.tabId, hostname, 'cookie', allowed);
  203   203     }
  204   204 

diff --git a/src/popup.js b/src/popup.js

@@ -6,15 +6,15 @@ var context;
    6     6 var requests;
    7     7 var rules;
    8     8 
    9    -1 var table = document.querySelector('table');
   10    -1 var commitButton = document.querySelector('[name="commit"]');
   11    -1 var resetButton = document.querySelector('[name="reset"]');
   -1     9 const table = document.querySelector('table');
   -1    10 const commitButton = document.querySelector('[name="commit"]');
   -1    11 const resetButton = document.querySelector('[name="reset"]');
   12    12 
   13    -1 var sendMessage = async function(type, data) {
   -1    13 const sendMessage = async function(type, data) {
   14    14     return await browser.runtime.sendMessage({type: type, data: data});
   15    15 };
   16    16 
   17    -1 var getHostnames = function() {
   -1    17 const getHostnames = function() {
   18    18     var hostnames = [];
   19    19 
   20    20     var addSubdomains = function(h) {
@@ -52,7 +52,7 @@ var getHostnames = function() {
   52    52     return hostnames.filter((value, i) => hostnames.indexOf(value) === i);
   53    53 };
   54    54 
   55    -1 var updateInherit = function(type) {
   -1    55 const updateInherit = function(type) {
   56    56     var selector = 'input';
   57    57     if (type !== '*') {
   58    58         selector += `[data-type="${type}"]`;
@@ -67,7 +67,7 @@ var updateInherit = function(type) {
   67    67     });
   68    68 };
   69    69 
   70    -1 var createCheckbox = function(hostname, type) {
   -1    70 const createCheckbox = function(hostname, type) {
   71    71     var input = document.createElement('input');
   72    72     input.type = 'checkbox';
   73    73     input.dataset.hostname = hostname;
@@ -92,7 +92,7 @@ var createCheckbox = function(hostname, type) {
   92    92     return input;
   93    93 };
   94    94 
   95    -1 var createCell = function(tag, hostname, type, text) {
   -1    95 const createCell = function(tag, hostname, type, text) {
   96    96     const cell = document.createElement(tag);
   97    97     cell.append(createCheckbox(hostname, type));
   98    98 
@@ -103,7 +103,7 @@ var createCell = function(tag, hostname, type, text) {
  103   103     return cell;
  104   104 };
  105   105 
  106    -1 var createHeader = function() {
   -1   106 const createHeader = function() {
  107   107     var tr = document.createElement('tr');
  108   108 
  109   109     var th = document.createElement('th');
@@ -116,7 +116,7 @@ var createHeader = function() {
  116   116     return tr;
  117   117 };
  118   118 
  119    -1 var createRow = function(hostname) {
   -1   119 const createRow = function(hostname) {
  120   120     var tr = document.createElement('tr');
  121   121     tr.append(createCell('th', hostname, '*', hostname));
  122   122     for (const type of shared.TYPES) {
@@ -133,7 +133,7 @@ var createRow = function(hostname) {
  133   133     return tr;
  134   134 };
  135   135 
  136    -1 var loadContext = async function() {
   -1   136 const loadContext = async function() {
  137   137     var data = await sendMessage('get');
  138   138     context = data.context;
  139   139     requests = data.requests;

diff --git a/src/settings.js b/src/settings.js

@@ -1,8 +1,8 @@
    1     1 import * as storage from './storage.js';
    2     2 
    3    -1 var form = document.querySelector('form');
    4    -1 var textarea1 = document.querySelector('textarea.rules');
    5    -1 var textarea2 = document.querySelector('textarea.savedRules');
   -1     3 const form = document.querySelector('form');
   -1     4 const textarea1 = document.querySelector('textarea.rules');
   -1     5 const textarea2 = document.querySelector('textarea.savedRules');
    6     6 
    7     7 Promise.all([
    8     8     storage.get('rules'),

diff --git a/src/shared.js b/src/shared.js

@@ -12,7 +12,7 @@ export const TYPE_MAP = {
   12    12     'sub_frame': 'frame',
   13    13 };
   14    14 
   15    -1 export var shouldAllow = function(rules, context, hostname, type) {
   -1    15 export const shouldAllow = function(rules, context, hostname, type) {
   16    16     var hostnames = ['*', hostname];
   17    17     var parts = hostname.split('.');
   18    18     while (parts.length > 2) {

diff --git a/src/storage.js b/src/storage.js

@@ -1,33 +1,33 @@
    1     1 /* global browser */
    2     2 
    3    -1 var STORAGE_DEFAULTS = {
   -1     3 const STORAGE_DEFAULTS = {
    4     4     'rules': {},
    5     5     'savedRules': {},
    6     6     'requests': {},
    7     7     'totals': {},
    8     8 };
    9    -1 var STORAGE_AREAS = {
   -1     9 const STORAGE_AREAS = {
   10    10     'rules': browser.storage.local,
   11    11     'savedRules': browser.storage.local,
   12    12     'requests': browser.storage.session,
   13    13     'totals': browser.storage.session,
   14    14 };
   15    15 var lock = Promise.resolve();
   16    -1 var cache = {};
   -1    16 const cache = {};
   17    17 
   18    -1 var _get = async function(key) {
   -1    18 const _get = async function(key) {
   19    19     var data = await STORAGE_AREAS[key].get(key);
   20    20     return data[key] ?? STORAGE_DEFAULTS[key];
   21    21 };
   22    22 
   23    -1 export var get = function(key) {
   -1    23 export const get = function(key) {
   24    24     if (!cache[key]) {
   25    25         cache[key] = _get(key);
   26    26     }
   27    27     return cache[key];
   28    28 };
   29    29 
   30    -1 var _change = async function(key, fn) {
   -1    30 const _change = async function(key, fn) {
   31    31     var oldValue = await get(key);
   32    32     var data = {};
   33    33     data[key] = fn(oldValue);
@@ -35,7 +35,7 @@ var _change = async function(key, fn) {
   35    35     await STORAGE_AREAS[key].set(data);
   36    36 };
   37    37 
   38    -1 export var change = async function(key, fn) {
   -1    38 export const change = async function(key, fn) {
   39    39     lock = lock.then(() => _change(key, fn));
   40    40     await lock;
   41    41 };