2020-01-25 15:24:59 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
uBlock Origin - a browser extension to block requests.
|
|
|
|
Copyright (C) 2014-present Raymond Hill
|
|
|
|
|
|
|
|
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/uBlock
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global punycode, uDom */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
{
|
|
|
|
// >>>>> start of local scope
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-05-16 13:36:03 +02:00
|
|
|
|
|
|
|
let popupFontSize = 'unset';
|
2020-02-21 21:34:54 +01:00
|
|
|
vAPI.localStorage.getItemAsync('popupFontSize').then(value => {
|
|
|
|
if ( typeof value !== 'string' || value === 'unset' ) { return; }
|
2020-05-17 14:49:37 +02:00
|
|
|
document.body.style.setProperty('--font-size', value);
|
2020-02-21 21:34:54 +01:00
|
|
|
popupFontSize = value;
|
|
|
|
});
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/996
|
2020-02-21 21:34:54 +01:00
|
|
|
// Experimental: mitigate glitchy popup UI: immediately set the firewall
|
|
|
|
// pane visibility to its last known state. By default the pane is hidden.
|
2020-04-30 12:54:51 +02:00
|
|
|
vAPI.localStorage.getItemAsync('popupPanelSections').then(bits => {
|
|
|
|
if ( typeof bits !== 'number' ) { return; }
|
|
|
|
sectionBitsToAttribute(bits);
|
2020-02-21 21:34:54 +01:00
|
|
|
});
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const messaging = vAPI.messaging;
|
|
|
|
const scopeToSrcHostnameMap = {
|
|
|
|
'/': '*',
|
|
|
|
'.': ''
|
|
|
|
};
|
|
|
|
const hostnameToSortableTokenMap = new Map();
|
|
|
|
const statsStr = vAPI.i18n('popupBlockedStats');
|
|
|
|
const domainsHitStr = vAPI.i18n('popupHitDomainCount');
|
|
|
|
|
|
|
|
let popupData = {};
|
|
|
|
let dfPaneBuilt = false;
|
|
|
|
let dfHotspots = null;
|
|
|
|
let allHostnameRows = [];
|
|
|
|
let cachedPopupHash = '';
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/2550
|
|
|
|
// Solution inspired from
|
|
|
|
// - https://bugs.chromium.org/p/chromium/issues/detail?id=683314
|
|
|
|
// - https://bugzilla.mozilla.org/show_bug.cgi?id=1332714#c17
|
|
|
|
// Confusable character set from:
|
|
|
|
// - http://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5B%D0%B0%D1%81%D4%81%D0%B5%D2%BB%D1%96%D1%98%D3%8F%D0%BE%D1%80%D4%9B%D1%95%D4%9D%D1%85%D1%83%D1%8A%D0%AC%D2%BD%D0%BF%D0%B3%D1%B5%D1%A1%5D&g=gc&i=
|
|
|
|
// Linked from:
|
|
|
|
// - https://www.chromium.org/developers/design-documents/idn-in-google-chrome
|
|
|
|
const reCyrillicNonAmbiguous = /[\u0400-\u042b\u042d-\u042f\u0431\u0432\u0434\u0436-\u043d\u0442\u0444\u0446-\u0449\u044b-\u0454\u0457\u0459-\u0460\u0462-\u0474\u0476-\u04ba\u04bc\u04be-\u04ce\u04d0-\u0500\u0502-\u051a\u051c\u051e-\u052f]/;
|
|
|
|
const reCyrillicAmbiguous = /[\u042c\u0430\u0433\u0435\u043e\u043f\u0440\u0441\u0443\u0445\u044a\u0455\u0456\u0458\u0461\u0475\u04bb\u04bd\u04cf\u0501\u051b\u051d]/;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const cachePopupData = function(data) {
|
|
|
|
popupData = {};
|
|
|
|
scopeToSrcHostnameMap['.'] = '';
|
|
|
|
hostnameToSortableTokenMap.clear();
|
|
|
|
|
|
|
|
if ( typeof data !== 'object' ) {
|
|
|
|
return popupData;
|
|
|
|
}
|
|
|
|
popupData = data;
|
2020-02-06 16:18:15 +01:00
|
|
|
popupData.cnameMap = new Map(popupData.cnameMap);
|
2020-01-25 15:24:59 +01:00
|
|
|
scopeToSrcHostnameMap['.'] = popupData.pageHostname || '';
|
|
|
|
const hostnameDict = popupData.hostnameDict;
|
|
|
|
if ( typeof hostnameDict !== 'object' ) {
|
|
|
|
return popupData;
|
|
|
|
}
|
|
|
|
for ( const hostname in hostnameDict ) {
|
|
|
|
if ( hostnameDict.hasOwnProperty(hostname) === false ) { continue; }
|
|
|
|
let domain = hostnameDict[hostname].domain;
|
|
|
|
let prefix = hostname.slice(0, 0 - domain.length - 1);
|
|
|
|
// Prefix with space char for 1st-party hostnames: this ensure these
|
|
|
|
// will come first in list.
|
|
|
|
if ( domain === popupData.pageDomain ) {
|
|
|
|
domain = '\u0020';
|
|
|
|
}
|
|
|
|
hostnameToSortableTokenMap.set(
|
|
|
|
hostname,
|
|
|
|
domain + ' ' + prefix.split('.').reverse().join('.')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return popupData;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-05-16 14:16:13 +02:00
|
|
|
const hashFromPopupData = function(reset = false) {
|
2020-01-25 15:24:59 +01:00
|
|
|
// It makes no sense to offer to refresh the behind-the-scene scope
|
|
|
|
if ( popupData.pageHostname === 'behind-the-scene' ) {
|
|
|
|
document.body.classList.remove('needReload');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasher = [];
|
|
|
|
const rules = popupData.firewallRules;
|
|
|
|
for ( const key in rules ) {
|
|
|
|
const rule = rules[key];
|
2021-02-15 12:52:31 +01:00
|
|
|
if ( rule === undefined ) { continue; }
|
|
|
|
hasher.push(rule);
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
hasher.sort();
|
|
|
|
hasher.push(uDom('body').hasClass('off'));
|
|
|
|
hasher.push(uDom.nodeFromId('no-large-media').classList.contains('on'));
|
|
|
|
hasher.push(uDom.nodeFromId('no-cosmetic-filtering').classList.contains('on'));
|
|
|
|
hasher.push(uDom.nodeFromId('no-remote-fonts').classList.contains('on'));
|
|
|
|
hasher.push(uDom.nodeFromId('no-scripting').classList.contains('on'));
|
|
|
|
|
|
|
|
const hash = hasher.join('');
|
|
|
|
if ( reset ) {
|
|
|
|
cachedPopupHash = hash;
|
|
|
|
}
|
|
|
|
document.body.classList.toggle('needReload', hash !== cachedPopupHash);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
// greater-than-zero test
|
|
|
|
|
|
|
|
const gtz = n => typeof n === 'number' && n > 0;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
const formatNumber = function(count) {
|
2020-04-23 14:45:43 +02:00
|
|
|
if ( typeof count !== 'number' ) { return ''; }
|
|
|
|
if ( count < 1e6 ) { return count.toLocaleString(); }
|
2020-05-16 23:51:01 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
intlNumberFormat === undefined &&
|
|
|
|
Intl.NumberFormat instanceof Function
|
|
|
|
) {
|
|
|
|
const intl = new Intl.NumberFormat(undefined, {
|
|
|
|
notation: 'compact',
|
|
|
|
maximumSignificantDigits: 4
|
|
|
|
});
|
|
|
|
if (
|
|
|
|
intl.resolvedOptions instanceof Function &&
|
|
|
|
intl.resolvedOptions().hasOwnProperty('notation')
|
|
|
|
) {
|
|
|
|
intlNumberFormat = intl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( intlNumberFormat ) {
|
|
|
|
return intlNumberFormat.format(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1027#issuecomment-629696676
|
|
|
|
// For platforms which do not support proper number formatting, use
|
|
|
|
// a poor's man compact form, which unfortunately is not i18n-friendly.
|
|
|
|
count /= 1000000;
|
|
|
|
if ( count >= 100 ) {
|
|
|
|
count = Math.floor(count * 10) / 10;
|
|
|
|
} else if ( count > 10 ) {
|
|
|
|
count = Math.floor(count * 100) / 100;
|
|
|
|
} else {
|
|
|
|
count = Math.floor(count * 1000) / 1000;
|
|
|
|
}
|
2020-05-17 14:49:37 +02:00
|
|
|
return (count).toLocaleString(undefined) + '\u2009M';
|
|
|
|
};
|
2020-05-16 23:51:01 +02:00
|
|
|
|
|
|
|
let intlNumberFormat;
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-04-28 01:01:16 +02:00
|
|
|
const safePunycodeToUnicode = function(hn) {
|
|
|
|
const pretty = punycode.toUnicode(hn);
|
|
|
|
return pretty === hn ||
|
|
|
|
reCyrillicAmbiguous.test(pretty) === false ||
|
|
|
|
reCyrillicNonAmbiguous.test(pretty)
|
|
|
|
? pretty
|
|
|
|
: hn;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
const updateFirewallCellCount = function(cells, allowed, blocked) {
|
|
|
|
for ( const cell of cells ) {
|
|
|
|
if ( gtz(allowed) ) {
|
|
|
|
cell.setAttribute(
|
|
|
|
'data-acount',
|
|
|
|
Math.min(Math.ceil(Math.log(allowed + 1) / Math.LN10), 3)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
cell.setAttribute('data-acount', '0');
|
|
|
|
}
|
|
|
|
if ( gtz(blocked) ) {
|
|
|
|
cell.setAttribute(
|
|
|
|
'data-bcount',
|
|
|
|
Math.min(Math.ceil(Math.log(blocked + 1) / Math.LN10), 3)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
cell.setAttribute('data-bcount', '0');
|
|
|
|
}
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
const updateFirewallCellRule = function(cells, scope, des, type, rule) {
|
|
|
|
const ruleParts = rule !== undefined ? rule.split(' ') : undefined;
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
for ( const cell of cells ) {
|
|
|
|
if ( ruleParts === undefined ) {
|
|
|
|
cell.removeAttribute('class');
|
|
|
|
continue;
|
|
|
|
}
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
const action = updateFirewallCellRule.actionNames[ruleParts[3]];
|
|
|
|
cell.setAttribute('class', `${action}Rule`);
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
// Use dark shade visual cue if the rule is specific to the cell.
|
|
|
|
if (
|
|
|
|
(ruleParts[1] !== '*' || ruleParts[2] === type) &&
|
|
|
|
(ruleParts[1] === des) &&
|
|
|
|
(ruleParts[0] === scopeToSrcHostnameMap[scope])
|
|
|
|
|
|
|
|
) {
|
|
|
|
cell.classList.add('ownRule');
|
|
|
|
}
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
2021-02-15 12:52:31 +01:00
|
|
|
};
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
updateFirewallCellRule.actionNames = { '1': 'block', '2': 'allow', '3': 'noop' };
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
/******************************************************************************/
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
const updateAllFirewallCells = function(doRules = true, doCounts = true) {
|
|
|
|
const { pageDomain } = popupData;
|
|
|
|
const rowContainer = document.getElementById('firewall');
|
|
|
|
const rows = rowContainer.querySelectorAll('#firewall > [data-des][data-type]');
|
|
|
|
|
|
|
|
let a1pScript = 0, b1pScript = 0;
|
|
|
|
let a3pScript = 0, b3pScript = 0;
|
|
|
|
let a3pFrame = 0, b3pFrame = 0;
|
|
|
|
|
|
|
|
for ( const row of rows ) {
|
|
|
|
const des = row.getAttribute('data-des');
|
|
|
|
const type = row.getAttribute('data-type');
|
|
|
|
if ( doRules ) {
|
|
|
|
updateFirewallCellRule(
|
|
|
|
row.querySelectorAll(`:scope > span[data-src="/"]`),
|
|
|
|
'/',
|
|
|
|
des,
|
|
|
|
type,
|
|
|
|
popupData.firewallRules[`/ ${des} ${type}`]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const cells = row.querySelectorAll(`:scope > span[data-src="."]`);
|
|
|
|
if ( doRules ) {
|
|
|
|
updateFirewallCellRule(
|
|
|
|
cells,
|
|
|
|
'.',
|
|
|
|
des,
|
|
|
|
type,
|
|
|
|
popupData.firewallRules[`. ${des} ${type}`]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( des === '*' || type !== '*' ) { continue; }
|
|
|
|
if ( doCounts === false ) { continue; }
|
|
|
|
const hnDetails = popupData.hostnameDict[des];
|
|
|
|
if ( hnDetails === undefined ) {
|
|
|
|
updateFirewallCellCount(cells);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const { allowed, blocked } = hnDetails.counts;
|
|
|
|
updateFirewallCellCount([ cells[0] ], allowed.any, blocked.any);
|
|
|
|
const { totals } = hnDetails;
|
|
|
|
if ( totals !== undefined ) {
|
|
|
|
updateFirewallCellCount([ cells[1] ], totals.allowed.any, totals.blocked.any);
|
|
|
|
}
|
|
|
|
if ( hnDetails.domain === pageDomain ) {
|
|
|
|
a1pScript += allowed.script; b1pScript += blocked.script;
|
|
|
|
} else {
|
|
|
|
a3pScript += allowed.script; b3pScript += blocked.script;
|
|
|
|
a3pFrame += allowed.frame; b3pFrame += blocked.frame;
|
|
|
|
}
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
if ( doCounts ) {
|
|
|
|
const fromType = type =>
|
|
|
|
document.querySelectorAll(
|
|
|
|
`#firewall > [data-des="*"][data-type="${type}"] > [data-src="."]`
|
|
|
|
);
|
|
|
|
updateFirewallCellCount(fromType('1p-script'), a1pScript, b1pScript);
|
|
|
|
updateFirewallCellCount(fromType('3p-script'), a3pScript, b3pScript);
|
|
|
|
rowContainer.classList.toggle('has3pScript', a3pScript !== 0 || b3pScript !== 0);
|
|
|
|
updateFirewallCellCount(fromType('3p-frame'), a3pFrame, b3pFrame);
|
|
|
|
rowContainer.classList.toggle('has3pFrame', a3pFrame !== 0 || b3pFrame !== 0);
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
document.body.classList.toggle('needSave', popupData.matrixIsDirty === true);
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
// Compute statistics useful only to firewall entries -- we need to call
|
|
|
|
// this only when overview pane needs to be rendered.
|
|
|
|
|
|
|
|
const expandHostnameStats = ( ) => {
|
|
|
|
let dnDetails;
|
|
|
|
for ( const des of allHostnameRows ) {
|
|
|
|
const hnDetails = popupData.hostnameDict[des];
|
|
|
|
const { domain, counts } = hnDetails;
|
|
|
|
const isDomain = des === domain;
|
|
|
|
const { allowed: hnAllowed, blocked: hnBlocked } = counts;
|
|
|
|
if ( isDomain ) {
|
|
|
|
dnDetails = hnDetails;
|
|
|
|
dnDetails.totals = JSON.parse(JSON.stringify(dnDetails.counts));
|
|
|
|
} else {
|
|
|
|
const { allowed: dnAllowed, blocked: dnBlocked } = dnDetails.totals;
|
|
|
|
dnAllowed.any += hnAllowed.any;
|
|
|
|
dnBlocked.any += hnBlocked.any;
|
|
|
|
}
|
|
|
|
hnDetails.hasScript = hnAllowed.script !== 0 || hnBlocked.script !== 0;
|
|
|
|
dnDetails.hasScript = dnDetails.hasScript || hnDetails.hasScript;
|
|
|
|
hnDetails.hasFrame = hnAllowed.frame !== 0 || hnBlocked.frame !== 0;
|
|
|
|
dnDetails.hasFrame = dnDetails.hasFrame || hnDetails.hasFrame;
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const buildAllFirewallRows = function() {
|
|
|
|
// Do this before removing the rows
|
|
|
|
if ( dfHotspots === null ) {
|
2020-05-23 12:37:04 +02:00
|
|
|
dfHotspots = uDom.nodeFromId('actionSelector');
|
|
|
|
dfHotspots.addEventListener('click', setFirewallRuleHandler);
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
2020-04-13 15:19:58 +02:00
|
|
|
dfHotspots.remove();
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
// This must be called before we create the rows.
|
|
|
|
expandHostnameStats();
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
// Update incrementally: reuse existing rows if possible.
|
2020-04-18 15:48:53 +02:00
|
|
|
const rowContainer = document.getElementById('firewall');
|
2020-01-25 15:24:59 +01:00
|
|
|
const toAppend = document.createDocumentFragment();
|
2021-02-15 12:52:31 +01:00
|
|
|
const rowTemplate = document.querySelector(
|
|
|
|
'#templates > div[data-des=""][data-type="*"]'
|
|
|
|
);
|
|
|
|
const { cnameMap, hostnameDict, pageDomain, pageHostname } = popupData;
|
|
|
|
|
|
|
|
let row = rowContainer.querySelector(
|
|
|
|
'div[data-des="*"][data-type="3p-frame"] + div'
|
|
|
|
);
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
for ( const des of allHostnameRows ) {
|
|
|
|
if ( row === null ) {
|
|
|
|
row = rowTemplate.cloneNode(true);
|
|
|
|
toAppend.appendChild(row);
|
|
|
|
}
|
|
|
|
row.setAttribute('data-des', des);
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
const hnDetails = hostnameDict[des] || {};
|
2020-01-25 15:24:59 +01:00
|
|
|
const isDomain = des === hnDetails.domain;
|
|
|
|
const prettyDomainName = punycode.toUnicode(des);
|
|
|
|
const isPunycoded = prettyDomainName !== des;
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
if ( isDomain && row.childElementCount < 4 ) {
|
|
|
|
row.append(row.children[2].cloneNode(true));
|
|
|
|
} else if ( isDomain === false && row.childElementCount === 4 ) {
|
|
|
|
row.children[3].remove();
|
|
|
|
}
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
const span = row.querySelector('span:first-of-type');
|
|
|
|
span.querySelector('span').textContent = prettyDomainName;
|
|
|
|
|
|
|
|
const classList = row.classList;
|
2020-02-10 14:06:36 +01:00
|
|
|
|
|
|
|
let desExtra = '';
|
2021-02-15 12:52:31 +01:00
|
|
|
if ( classList.toggle('isCname', cnameMap.has(des)) ) {
|
|
|
|
desExtra = punycode.toUnicode(cnameMap.get(des));
|
2020-02-10 14:06:36 +01:00
|
|
|
} else if (
|
|
|
|
isDomain && isPunycoded &&
|
|
|
|
reCyrillicAmbiguous.test(prettyDomainName) &&
|
|
|
|
reCyrillicNonAmbiguous.test(prettyDomainName) === false
|
|
|
|
) {
|
|
|
|
desExtra = des;
|
|
|
|
}
|
|
|
|
span.querySelector('sub').textContent = desExtra;
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
classList.toggle('isRootContext', des === pageHostname);
|
|
|
|
classList.toggle('is3p', hnDetails.domain !== pageDomain);
|
2020-01-25 15:24:59 +01:00
|
|
|
classList.toggle('isDomain', isDomain);
|
|
|
|
classList.toggle('isSubDomain', !isDomain);
|
2021-02-15 12:52:31 +01:00
|
|
|
const { counts } = hnDetails;
|
|
|
|
classList.toggle('allowed', gtz(counts.allowed.any));
|
|
|
|
classList.toggle('blocked', gtz(counts.blocked.any));
|
|
|
|
const { totals } = hnDetails;
|
|
|
|
classList.toggle('totalAllowed', gtz(totals && totals.allowed.any));
|
|
|
|
classList.toggle('totalBlocked', gtz(totals && totals.blocked.any));
|
|
|
|
classList.toggle('hasScript', hnDetails.hasScript === true);
|
|
|
|
classList.toggle('hasFrame', hnDetails.hasFrame === true);
|
2020-01-25 15:24:59 +01:00
|
|
|
classList.toggle('expandException', expandExceptions.has(hnDetails.domain));
|
|
|
|
|
|
|
|
row = row.nextElementSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove unused trailing rows
|
|
|
|
if ( row !== null ) {
|
|
|
|
while ( row.nextElementSibling !== null ) {
|
2021-02-15 12:52:31 +01:00
|
|
|
row.nextElementSibling.remove();
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
2021-02-15 12:52:31 +01:00
|
|
|
row.remove();
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add new rows all at once
|
|
|
|
if ( toAppend.childElementCount !== 0 ) {
|
2021-02-15 12:52:31 +01:00
|
|
|
rowContainer.append(toAppend);
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( dfPaneBuilt !== true && popupData.advancedUserEnabled ) {
|
2020-04-18 15:48:53 +02:00
|
|
|
uDom('#firewall')
|
2020-01-25 15:24:59 +01:00
|
|
|
.on('click', 'span[data-src]', unsetFirewallRuleHandler)
|
|
|
|
.on('mouseenter', '[data-src]', mouseenterCellHandler)
|
|
|
|
.on('mouseleave', '[data-src]', mouseleaveCellHandler);
|
|
|
|
dfPaneBuilt = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateAllFirewallCells();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
const hostnameCompare = function(a, b) {
|
|
|
|
let ha = a;
|
|
|
|
if ( !reIP.test(ha) ) {
|
|
|
|
ha = hostnameToSortableTokenMap.get(ha) || ' ';
|
|
|
|
}
|
|
|
|
let hb = b;
|
|
|
|
if ( !reIP.test(hb) ) {
|
|
|
|
hb = hostnameToSortableTokenMap.get(hb) || ' ';
|
|
|
|
}
|
|
|
|
const ca = ha.charCodeAt(0);
|
|
|
|
const cb = hb.charCodeAt(0);
|
|
|
|
return ca !== cb ? ca - cb : ha.localeCompare(hb);
|
|
|
|
};
|
|
|
|
|
|
|
|
const reIP = /(\d|\])$/;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
const renderPrivacyExposure = function() {
|
2021-02-15 12:52:31 +01:00
|
|
|
const allDomains = {};
|
|
|
|
let allDomainCount = 0;
|
|
|
|
let touchedDomainCount = 0;
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
allHostnameRows = [];
|
|
|
|
|
|
|
|
// Sort hostnames. First-party hostnames must always appear at the top
|
|
|
|
// of the list.
|
|
|
|
const desHostnameDone = {};
|
2021-02-15 12:52:31 +01:00
|
|
|
const keys = Object.keys(popupData.hostnameDict)
|
|
|
|
.sort(hostnameCompare);
|
|
|
|
for ( const des of keys ) {
|
2020-01-25 15:24:59 +01:00
|
|
|
// Specific-type rules -- these are built-in
|
|
|
|
if ( des === '*' || desHostnameDone.hasOwnProperty(des) ) { continue; }
|
2021-02-15 12:52:31 +01:00
|
|
|
const hnDetails = popupData.hostnameDict[des];
|
|
|
|
const { domain, counts } = hnDetails;
|
|
|
|
if ( allDomains.hasOwnProperty(domain) === false ) {
|
|
|
|
allDomains[domain] = false;
|
2020-01-25 15:24:59 +01:00
|
|
|
allDomainCount += 1;
|
|
|
|
}
|
2021-02-15 12:52:31 +01:00
|
|
|
if ( gtz(counts.allowed.any) ) {
|
|
|
|
if ( allDomains[domain] === false ) {
|
|
|
|
allDomains[domain] = true;
|
2020-01-25 15:24:59 +01:00
|
|
|
touchedDomainCount += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
allHostnameRows.push(des);
|
|
|
|
desHostnameDone[des] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const summary = domainsHitStr
|
2021-02-15 12:52:31 +01:00
|
|
|
.replace('{{count}}', touchedDomainCount.toLocaleString())
|
|
|
|
.replace('{{total}}', allDomainCount.toLocaleString());
|
|
|
|
uDom.nodeFromSelector(
|
|
|
|
'[data-i18n^="popupDomainsConnected"] + span'
|
|
|
|
).textContent = summary;
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const updateHnSwitches = function() {
|
2020-05-03 00:27:53 +02:00
|
|
|
uDom.nodeFromId('no-popups').classList.toggle(
|
|
|
|
'on', popupData.noPopups === true
|
|
|
|
);
|
2020-01-25 15:24:59 +01:00
|
|
|
uDom.nodeFromId('no-large-media').classList.toggle(
|
|
|
|
'on', popupData.noLargeMedia === true
|
|
|
|
);
|
|
|
|
uDom.nodeFromId('no-cosmetic-filtering').classList.toggle(
|
|
|
|
'on',
|
|
|
|
popupData.noCosmeticFiltering === true
|
|
|
|
);
|
|
|
|
uDom.nodeFromId('no-remote-fonts').classList.toggle(
|
|
|
|
'on',
|
|
|
|
popupData.noRemoteFonts === true
|
|
|
|
);
|
|
|
|
uDom.nodeFromId('no-scripting').classList.toggle(
|
|
|
|
'on',
|
|
|
|
popupData.noScripting === true
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// Assume everything has to be done incrementally.
|
|
|
|
|
|
|
|
const renderPopup = function() {
|
|
|
|
if ( popupData.tabTitle ) {
|
|
|
|
document.title = popupData.appName + ' - ' + popupData.tabTitle;
|
|
|
|
}
|
|
|
|
|
2020-04-28 01:01:16 +02:00
|
|
|
const isFiltering = popupData.netFilteringSwitch;
|
|
|
|
|
|
|
|
const body = document.body;
|
|
|
|
body.classList.toggle('advancedUser', popupData.advancedUserEnabled === true);
|
|
|
|
body.classList.toggle('off', popupData.pageURL === '' || isFiltering !== true);
|
2020-05-01 13:51:45 +02:00
|
|
|
body.classList.toggle('needSave', popupData.matrixIsDirty === true);
|
2020-04-28 01:01:16 +02:00
|
|
|
|
|
|
|
// The hostname information below the power switch
|
|
|
|
{
|
|
|
|
const [ elemHn, elemDn ] = uDom.nodeFromId('hostname').children;
|
|
|
|
const { pageDomain, pageHostname } = popupData;
|
|
|
|
if ( pageDomain !== '' ) {
|
|
|
|
elemDn.textContent = safePunycodeToUnicode(pageDomain);
|
|
|
|
elemHn.textContent = pageHostname !== pageDomain
|
|
|
|
? safePunycodeToUnicode(pageHostname.slice(0, -pageDomain.length - 1)) + '.'
|
|
|
|
: '';
|
|
|
|
} else {
|
|
|
|
elemHn.textContent = elemDn.textContent = '';
|
|
|
|
}
|
|
|
|
}
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2020-04-28 01:01:16 +02:00
|
|
|
const canElementPicker = popupData.canElementPicker === true && isFiltering;
|
2020-01-25 15:24:59 +01:00
|
|
|
uDom.nodeFromId('gotoPick').classList.toggle('enabled', canElementPicker);
|
|
|
|
uDom.nodeFromId('gotoZap').classList.toggle('enabled', canElementPicker);
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
let blocked, total;
|
|
|
|
if ( popupData.pageCounts !== undefined ) {
|
|
|
|
const counts = popupData.pageCounts;
|
|
|
|
blocked = counts.blocked.any;
|
|
|
|
total = blocked + counts.allowed.any;
|
|
|
|
} else {
|
|
|
|
blocked = 0;
|
|
|
|
total = 0;
|
|
|
|
}
|
2020-04-23 14:45:43 +02:00
|
|
|
let text;
|
2020-01-25 15:24:59 +01:00
|
|
|
if ( total === 0 ) {
|
|
|
|
text = formatNumber(0);
|
|
|
|
} else {
|
|
|
|
text = statsStr.replace('{{count}}', formatNumber(blocked))
|
|
|
|
.replace('{{percent}}', formatNumber(Math.floor(blocked * 100 / total)));
|
|
|
|
}
|
|
|
|
uDom.nodeFromSelector('[data-i18n^="popupBlockedOnThisPage"] + span').textContent = text;
|
|
|
|
|
|
|
|
blocked = popupData.globalBlockedRequestCount;
|
|
|
|
total = popupData.globalAllowedRequestCount + blocked;
|
|
|
|
if ( total === 0 ) {
|
|
|
|
text = formatNumber(0);
|
|
|
|
} else {
|
|
|
|
text = statsStr.replace('{{count}}', formatNumber(blocked))
|
|
|
|
.replace('{{percent}}', formatNumber(Math.floor(blocked * 100 / total)));
|
|
|
|
}
|
|
|
|
uDom.nodeFromSelector('[data-i18n^="popupBlockedSinceInstall"] + span').textContent = text;
|
|
|
|
|
|
|
|
// This will collate all domains, touched or not
|
|
|
|
renderPrivacyExposure();
|
|
|
|
|
|
|
|
// Extra tools
|
|
|
|
updateHnSwitches();
|
|
|
|
|
2020-05-03 00:27:53 +02:00
|
|
|
// Report popup count on badge
|
|
|
|
total = popupData.popupBlockedCount;
|
|
|
|
uDom.nodeFromSelector('#no-popups .fa-icon-badge')
|
|
|
|
.textContent = total ? Math.min(total, 99).toLocaleString() : '';
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
// Report large media count on badge
|
|
|
|
total = popupData.largeMediaCount;
|
|
|
|
uDom.nodeFromSelector('#no-large-media .fa-icon-badge')
|
|
|
|
.textContent = total ? Math.min(total, 99).toLocaleString() : '';
|
|
|
|
|
|
|
|
// Report remote font count on badge
|
|
|
|
total = popupData.remoteFontCount;
|
|
|
|
uDom.nodeFromSelector('#no-remote-fonts .fa-icon-badge')
|
|
|
|
.textContent = total ? Math.min(total, 99).toLocaleString() : '';
|
|
|
|
|
2020-04-13 15:19:58 +02:00
|
|
|
document.documentElement.classList.toggle(
|
2020-01-25 15:24:59 +01:00
|
|
|
'colorBlind',
|
|
|
|
popupData.colorBlindFriendly === true
|
|
|
|
);
|
|
|
|
|
|
|
|
setGlobalExpand(popupData.firewallPaneMinimized === false, true);
|
|
|
|
|
|
|
|
// Build dynamic filtering pane only if in use
|
2020-05-06 16:39:03 +02:00
|
|
|
if ( (computedSections() & sectionFirewallBit) !== 0 ) {
|
2020-01-25 15:24:59 +01:00
|
|
|
buildAllFirewallRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTooltips();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/2889
|
|
|
|
// Use tooltip for ARIA purpose.
|
|
|
|
|
|
|
|
const renderTooltips = function(selector) {
|
2020-04-27 16:33:49 +02:00
|
|
|
for ( const [ key, details ] of tooltipTargetSelectors ) {
|
|
|
|
if ( selector !== undefined && key !== selector ) { continue; }
|
|
|
|
const elem = uDom.nodeFromSelector(key);
|
|
|
|
if ( elem.hasAttribute('title') === false ) { continue; }
|
2020-01-25 15:24:59 +01:00
|
|
|
const text = vAPI.i18n(
|
2020-04-27 16:33:49 +02:00
|
|
|
details.i18n +
|
|
|
|
(uDom.nodeFromSelector(details.state) === null ? '1' : '2')
|
2020-01-25 15:24:59 +01:00
|
|
|
);
|
|
|
|
elem.setAttribute('aria-label', text);
|
2020-04-27 16:33:49 +02:00
|
|
|
elem.setAttribute('title', text);
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const tooltipTargetSelectors = new Map([
|
|
|
|
[
|
|
|
|
'#switch',
|
|
|
|
{
|
|
|
|
state: 'body.off',
|
|
|
|
i18n: 'popupPowerSwitchInfo',
|
|
|
|
}
|
|
|
|
],
|
2020-04-27 16:33:49 +02:00
|
|
|
[
|
|
|
|
'#no-popups',
|
|
|
|
{
|
|
|
|
state: '#no-popups.on',
|
|
|
|
i18n: 'popupTipNoPopups'
|
|
|
|
}
|
|
|
|
],
|
2020-01-25 15:24:59 +01:00
|
|
|
[
|
|
|
|
'#no-large-media',
|
|
|
|
{
|
|
|
|
state: '#no-large-media.on',
|
|
|
|
i18n: 'popupTipNoLargeMedia'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'#no-cosmetic-filtering',
|
|
|
|
{
|
|
|
|
state: '#no-cosmetic-filtering.on',
|
|
|
|
i18n: 'popupTipNoCosmeticFiltering'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'#no-remote-fonts',
|
|
|
|
{
|
|
|
|
state: '#no-remote-fonts.on',
|
|
|
|
i18n: 'popupTipNoRemoteFonts'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'#no-scripting',
|
|
|
|
{
|
|
|
|
state: '#no-scripting.on',
|
|
|
|
i18n: 'popupTipNoScripting'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// All rendering code which need to be executed only once.
|
|
|
|
|
|
|
|
let renderOnce = function() {
|
|
|
|
renderOnce = function(){};
|
|
|
|
|
2020-04-21 22:33:08 +02:00
|
|
|
const body = document.body;
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
if ( popupData.fontSize !== popupFontSize ) {
|
|
|
|
popupFontSize = popupData.fontSize;
|
|
|
|
if ( popupFontSize !== 'unset' ) {
|
2020-05-17 14:49:37 +02:00
|
|
|
body.style.setProperty('--font-size', popupFontSize);
|
2020-01-25 15:24:59 +01:00
|
|
|
vAPI.localStorage.setItem('popupFontSize', popupFontSize);
|
|
|
|
} else {
|
2020-05-17 14:49:37 +02:00
|
|
|
body.style.removeProperty('--font-size');
|
2020-01-25 15:24:59 +01:00
|
|
|
vAPI.localStorage.removeItem('popupFontSize');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 12:54:51 +02:00
|
|
|
uDom.nodeFromId('version').textContent = popupData.appVersion;
|
|
|
|
|
2020-05-02 01:47:01 +02:00
|
|
|
sectionBitsToAttribute(computedSections());
|
2020-04-21 22:33:08 +02:00
|
|
|
|
2020-04-27 16:33:49 +02:00
|
|
|
if ( popupData.uiPopupConfig !== undefined ) {
|
|
|
|
document.body.setAttribute('data-ui', popupData.uiPopupConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
body.classList.toggle('no-tooltips', popupData.tooltipsDisabled === true);
|
|
|
|
if ( popupData.tooltipsDisabled === true ) {
|
|
|
|
uDom('[title]').removeAttr('title');
|
|
|
|
}
|
2020-04-30 12:54:51 +02:00
|
|
|
|
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/22
|
|
|
|
if ( popupData.advancedUserEnabled !== true ) {
|
|
|
|
uDom('#firewall [title][data-src]').removeAttr('title');
|
|
|
|
}
|
2020-05-22 14:47:51 +02:00
|
|
|
|
|
|
|
// This must be done the firewall is populated
|
|
|
|
if ( popupData.popupPanelHeightMode === 1 ) {
|
|
|
|
body.classList.add('vMin');
|
|
|
|
}
|
2020-05-22 17:35:44 +02:00
|
|
|
|
|
|
|
// Prevent non-advanced user opting into advanced user mode from harming
|
|
|
|
// themselves by disabling by default features generally suitable to
|
|
|
|
// filter list maintainers and actual advanced users.
|
|
|
|
if ( popupData.godMode ) {
|
|
|
|
body.classList.add('godMode');
|
|
|
|
}
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const renderPopupLazy = (( ) => {
|
|
|
|
let mustRenderCosmeticFilteringBadge = true;
|
|
|
|
|
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/756
|
|
|
|
// Launch potentially expensive hidden elements-counting scriptlet on
|
|
|
|
// demand only.
|
|
|
|
{
|
|
|
|
const sw = uDom.nodeFromId('no-cosmetic-filtering');
|
|
|
|
const badge = sw.querySelector(':scope .fa-icon-badge');
|
|
|
|
badge.textContent = '\u22EF';
|
|
|
|
|
|
|
|
const render = ( ) => {
|
|
|
|
if ( mustRenderCosmeticFilteringBadge === false ) { return; }
|
|
|
|
mustRenderCosmeticFilteringBadge = false;
|
|
|
|
if ( sw.classList.contains('hnSwitchBusy') ) { return; }
|
|
|
|
sw.classList.add('hnSwitchBusy');
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'getHiddenElementCount',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
}).then(count => {
|
|
|
|
let text;
|
|
|
|
if ( (count || 0) === 0 ) {
|
|
|
|
text = '';
|
|
|
|
} else if ( count === -1 ) {
|
|
|
|
text = '?';
|
|
|
|
} else {
|
|
|
|
text = Math.min(count, 99).toLocaleString();
|
|
|
|
}
|
|
|
|
badge.textContent = text;
|
|
|
|
sw.classList.remove('hnSwitchBusy');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
sw.addEventListener('mouseenter', render, { passive: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
return async function() {
|
|
|
|
const count = await messaging.send('popupPanel', {
|
|
|
|
what: 'getScriptCount',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
});
|
|
|
|
uDom.nodeFromSelector('#no-scripting .fa-icon-badge')
|
|
|
|
.textContent = (count || 0) !== 0
|
|
|
|
? Math.min(count, 99).toLocaleString()
|
|
|
|
: '';
|
|
|
|
mustRenderCosmeticFilteringBadge = true;
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const toggleNetFilteringSwitch = function(ev) {
|
|
|
|
if ( !popupData || !popupData.pageURL ) { return; }
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'toggleNetFiltering',
|
|
|
|
url: popupData.pageURL,
|
|
|
|
scope: ev.ctrlKey || ev.metaKey ? 'page' : '',
|
|
|
|
state: !uDom('body').toggleClass('off').hasClass('off'),
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
});
|
|
|
|
renderTooltips('#switch');
|
|
|
|
hashFromPopupData();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const gotoZap = function() {
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'launchElementPicker',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
zap: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
vAPI.closePopup();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const gotoPick = function() {
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'launchElementPicker',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
});
|
|
|
|
|
|
|
|
vAPI.closePopup();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const gotoURL = function(ev) {
|
|
|
|
if ( this.hasAttribute('href') === false ) { return; }
|
|
|
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
let url = this.getAttribute('href');
|
|
|
|
if (
|
|
|
|
url === 'logger-ui.html#_' &&
|
|
|
|
typeof popupData.tabId === 'number'
|
|
|
|
) {
|
|
|
|
url += '+' + popupData.tabId;
|
|
|
|
}
|
|
|
|
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: {
|
|
|
|
url: url,
|
|
|
|
select: true,
|
|
|
|
index: -1,
|
|
|
|
shiftKey: ev.shiftKey
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
vAPI.closePopup();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-04-30 12:54:51 +02:00
|
|
|
// The popup panel is made of sections. Visiblity of sections can
|
|
|
|
// be toggle on/off.
|
|
|
|
|
2020-05-02 01:47:01 +02:00
|
|
|
const maxNumberOfSections = 6;
|
2020-05-06 16:39:03 +02:00
|
|
|
const sectionFirewallBit = 0b10000;
|
2020-05-02 01:47:01 +02:00
|
|
|
|
|
|
|
const computedSections = ( ) =>
|
|
|
|
popupData.popupPanelSections &
|
|
|
|
~popupData.popupPanelDisabledSections |
|
|
|
|
popupData.popupPanelLockedSections;
|
2020-04-30 12:54:51 +02:00
|
|
|
|
|
|
|
const sectionBitsFromAttribute = function() {
|
|
|
|
const attr = document.body.dataset.more;
|
|
|
|
if ( attr === '' ) { return 0; }
|
|
|
|
let bits = 0;
|
|
|
|
for ( const c of attr.split(' ') ) {
|
|
|
|
bits |= 1 << (c.charCodeAt(0) - 97);
|
|
|
|
}
|
|
|
|
return bits;
|
|
|
|
};
|
2020-01-25 15:24:59 +01:00
|
|
|
|
2020-04-30 12:54:51 +02:00
|
|
|
const sectionBitsToAttribute = function(bits) {
|
|
|
|
const attr = [];
|
|
|
|
for ( let i = 0; i < maxNumberOfSections; i++ ) {
|
|
|
|
const bit = 1 << i;
|
|
|
|
if ( (bits & bit) === 0 ) { continue; }
|
|
|
|
attr.push(String.fromCharCode(97 + i));
|
|
|
|
}
|
|
|
|
document.body.dataset.more = attr.join(' ');
|
|
|
|
};
|
|
|
|
|
|
|
|
const toggleSections = function(more) {
|
2020-05-02 01:47:01 +02:00
|
|
|
const offbits = ~popupData.popupPanelDisabledSections;
|
|
|
|
const onbits = popupData.popupPanelLockedSections;
|
2020-04-30 12:54:51 +02:00
|
|
|
let currentBits = sectionBitsFromAttribute();
|
|
|
|
let newBits = currentBits;
|
|
|
|
for ( let i = 0; i < maxNumberOfSections; i++ ) {
|
|
|
|
const bit = 1 << (more ? i : maxNumberOfSections - i - 1);
|
|
|
|
if ( more ) {
|
|
|
|
newBits |= bit;
|
|
|
|
} else {
|
|
|
|
newBits &= ~bit;
|
|
|
|
}
|
2020-05-02 01:47:01 +02:00
|
|
|
newBits = newBits & offbits | onbits;
|
2020-04-30 12:54:51 +02:00
|
|
|
if ( newBits !== currentBits ) { break; }
|
|
|
|
}
|
|
|
|
if ( newBits === currentBits ) { return; }
|
|
|
|
|
|
|
|
sectionBitsToAttribute(newBits);
|
|
|
|
|
|
|
|
popupData.popupPanelSections = newBits;
|
2020-01-25 15:24:59 +01:00
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'userSettings',
|
2020-04-30 12:54:51 +02:00
|
|
|
name: 'popupPanelSections',
|
|
|
|
value: newBits,
|
2020-01-25 15:24:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/996
|
2020-04-30 12:54:51 +02:00
|
|
|
// Remember the last state of the firewall pane. This allows to
|
|
|
|
// configure the popup size early next time it is opened, which means a
|
|
|
|
// less glitchy popup at open time.
|
|
|
|
vAPI.localStorage.setItem('popupPanelSections', newBits);
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
// Dynamic filtering pane may not have been built yet
|
2020-05-06 16:39:03 +02:00
|
|
|
if ( (newBits & sectionFirewallBit) !== 0 && dfPaneBuilt === false ) {
|
2020-01-25 15:24:59 +01:00
|
|
|
buildAllFirewallRows();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-30 12:54:51 +02:00
|
|
|
uDom('#moreButton').on('click', ( ) => { toggleSections(true); });
|
|
|
|
uDom('#lessButton').on('click', ( ) => { toggleSections(false); });
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-05-23 12:37:04 +02:00
|
|
|
const mouseenterCellHandler = function(ev) {
|
|
|
|
const target = ev.target;
|
|
|
|
if ( target.classList.contains('ownRule') ) { return; }
|
|
|
|
target.appendChild(dfHotspots);
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const mouseleaveCellHandler = function() {
|
2020-04-13 15:19:58 +02:00
|
|
|
dfHotspots.remove();
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const setFirewallRule = async function(src, des, type, action, persist) {
|
|
|
|
// This can happen on pages where uBlock does not work
|
|
|
|
if (
|
|
|
|
typeof popupData.pageHostname !== 'string' ||
|
|
|
|
popupData.pageHostname === ''
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await messaging.send('popupPanel', {
|
|
|
|
what: 'toggleFirewallRule',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
pageHostname: popupData.pageHostname,
|
|
|
|
srcHostname: src,
|
|
|
|
desHostname: des,
|
|
|
|
requestType: type,
|
|
|
|
action: action,
|
|
|
|
persist: persist,
|
|
|
|
});
|
|
|
|
|
2020-04-13 15:19:58 +02:00
|
|
|
// Remove action widget if an own rule has been set, this allows to click
|
|
|
|
// again immediately to remove the rule.
|
|
|
|
if ( action !== 0 ) {
|
|
|
|
dfHotspots.remove();
|
|
|
|
}
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
cachePopupData(response);
|
2021-02-15 12:52:31 +01:00
|
|
|
updateAllFirewallCells(true, false);
|
2020-01-25 15:24:59 +01:00
|
|
|
hashFromPopupData();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const unsetFirewallRuleHandler = function(ev) {
|
|
|
|
const cell = ev.target;
|
|
|
|
const row = cell.closest('[data-des]');
|
|
|
|
setFirewallRule(
|
|
|
|
cell.getAttribute('data-src') === '/' ? '*' : popupData.pageHostname,
|
|
|
|
row.getAttribute('data-des'),
|
|
|
|
row.getAttribute('data-type'),
|
|
|
|
0,
|
|
|
|
ev.ctrlKey || ev.metaKey
|
|
|
|
);
|
2020-05-23 12:37:04 +02:00
|
|
|
cell.appendChild(dfHotspots);
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const setFirewallRuleHandler = function(ev) {
|
|
|
|
const hotspot = ev.target;
|
|
|
|
const cell = hotspot.closest('[data-src]');
|
|
|
|
if ( cell === null ) { return; }
|
|
|
|
const row = cell.closest('[data-des]');
|
|
|
|
let action = 0;
|
|
|
|
if ( hotspot.id === 'dynaAllow' ) {
|
|
|
|
action = 2;
|
|
|
|
} else if ( hotspot.id === 'dynaNoop' ) {
|
|
|
|
action = 3;
|
|
|
|
} else {
|
|
|
|
action = 1;
|
|
|
|
}
|
|
|
|
setFirewallRule(
|
|
|
|
cell.getAttribute('data-src') === '/' ? '*' : popupData.pageHostname,
|
|
|
|
row.getAttribute('data-des'),
|
|
|
|
row.getAttribute('data-type'),
|
|
|
|
action,
|
|
|
|
ev.ctrlKey || ev.metaKey
|
|
|
|
);
|
2020-04-13 15:19:58 +02:00
|
|
|
dfHotspots.remove();
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const reloadTab = function(ev) {
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'reloadTab',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
select: vAPI.webextFlavor.soup.has('mobile'),
|
|
|
|
bypassCache: ev.ctrlKey || ev.metaKey || ev.shiftKey,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Polling will take care of refreshing the popup content
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/748
|
|
|
|
// User forces a reload, assume the popup has to be updated regardless
|
|
|
|
// if there were changes or not.
|
|
|
|
popupData.contentLastModified = -1;
|
|
|
|
|
2021-05-15 16:45:31 +02:00
|
|
|
// Reset popup state hash to current state.
|
|
|
|
hashFromPopupData(true);
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
uDom('#refresh').on('click', reloadTab);
|
|
|
|
|
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/672
|
|
|
|
document.addEventListener(
|
|
|
|
'keydown',
|
|
|
|
ev => {
|
|
|
|
if ( ev.code !== 'F5' ) { return; }
|
|
|
|
reloadTab(ev);
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
},
|
|
|
|
{ capture: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const expandExceptions = new Set();
|
|
|
|
|
2020-02-21 21:34:54 +01:00
|
|
|
vAPI.localStorage.getItemAsync('popupExpandExceptions').then(exceptions => {
|
2020-01-25 15:24:59 +01:00
|
|
|
try {
|
|
|
|
if ( Array.isArray(exceptions) === false ) { return; }
|
|
|
|
for ( const exception of exceptions ) {
|
|
|
|
expandExceptions.add(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
}
|
2020-02-21 21:34:54 +01:00
|
|
|
});
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
const saveExpandExceptions = function() {
|
|
|
|
vAPI.localStorage.setItem(
|
|
|
|
'popupExpandExceptions',
|
2020-02-21 21:34:54 +01:00
|
|
|
Array.from(expandExceptions)
|
2020-01-25 15:24:59 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const setGlobalExpand = function(state, internal = false) {
|
|
|
|
uDom('.expandException').removeClass('expandException');
|
|
|
|
if ( state ) {
|
2020-04-18 15:48:53 +02:00
|
|
|
uDom('#firewall').addClass('expanded');
|
2020-01-25 15:24:59 +01:00
|
|
|
} else {
|
2020-04-18 15:48:53 +02:00
|
|
|
uDom('#firewall').removeClass('expanded');
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
if ( internal ) { return; }
|
|
|
|
popupData.firewallPaneMinimized = !state;
|
|
|
|
expandExceptions.clear();
|
|
|
|
saveExpandExceptions();
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'userSettings',
|
|
|
|
name: 'firewallPaneMinimized',
|
|
|
|
value: popupData.firewallPaneMinimized,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const setSpecificExpand = function(domain, state, internal = false) {
|
|
|
|
const unodes = uDom(`[data-des="${domain}"],[data-des$=".${domain}"]`);
|
|
|
|
if ( state ) {
|
|
|
|
unodes.addClass('expandException');
|
|
|
|
} else {
|
|
|
|
unodes.removeClass('expandException');
|
|
|
|
}
|
|
|
|
if ( internal ) { return; }
|
|
|
|
if ( state ) {
|
|
|
|
expandExceptions.add(domain);
|
|
|
|
} else {
|
|
|
|
expandExceptions.delete(domain);
|
|
|
|
}
|
|
|
|
saveExpandExceptions();
|
|
|
|
};
|
|
|
|
|
|
|
|
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', ev => {
|
|
|
|
// Special display mode: in its own tab/window, with no vertical restraint.
|
|
|
|
// Useful to take snapshots of the whole list of domains -- example:
|
|
|
|
// https://github.com/gorhill/uBlock/issues/736#issuecomment-178879944
|
|
|
|
if ( ev.shiftKey && ev.ctrlKey ) {
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: {
|
2020-10-18 16:00:55 +02:00
|
|
|
url: `popup-fenix.html?tabId=${popupData.tabId}&intab=1`,
|
2020-01-25 15:24:59 +01:00
|
|
|
select: true,
|
|
|
|
index: -1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
vAPI.closePopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setGlobalExpand(
|
2020-04-18 15:48:53 +02:00
|
|
|
uDom('#firewall').hasClass('expanded') === false
|
2020-01-25 15:24:59 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-18 15:48:53 +02:00
|
|
|
uDom('#firewall').on(
|
2020-01-25 15:24:59 +01:00
|
|
|
'click', '.isDomain[data-type="*"] > span:first-of-type',
|
|
|
|
ev => {
|
|
|
|
const div = ev.target.closest('[data-des]');
|
|
|
|
if ( div === null ) { return; }
|
|
|
|
setSpecificExpand(
|
|
|
|
div.getAttribute('data-des'),
|
|
|
|
div.classList.contains('expandException') === false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const saveFirewallRules = function() {
|
|
|
|
messaging.send('popupPanel', {
|
|
|
|
what: 'saveFirewallRules',
|
|
|
|
srcHostname: popupData.pageHostname,
|
|
|
|
desHostnames: popupData.hostnameDict,
|
|
|
|
});
|
|
|
|
document.body.classList.remove('needSave');
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const revertFirewallRules = async function() {
|
|
|
|
document.body.classList.remove('needSave');
|
|
|
|
const response = await messaging.send('popupPanel', {
|
|
|
|
what: 'revertFirewallRules',
|
|
|
|
srcHostname: popupData.pageHostname,
|
|
|
|
desHostnames: popupData.hostnameDict,
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
});
|
|
|
|
cachePopupData(response);
|
2021-02-15 12:52:31 +01:00
|
|
|
updateAllFirewallCells(true, false);
|
2021-02-19 18:32:07 +01:00
|
|
|
updateHnSwitches();
|
2020-01-25 15:24:59 +01:00
|
|
|
hashFromPopupData();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const toggleHostnameSwitch = async function(ev) {
|
|
|
|
const target = ev.currentTarget;
|
|
|
|
const switchName = target.getAttribute('id');
|
|
|
|
if ( !switchName ) { return; }
|
|
|
|
// For touch displays, process click only if the switch is not "busy".
|
|
|
|
if (
|
|
|
|
vAPI.webextFlavor.soup.has('mobile') &&
|
|
|
|
target.classList.contains('hnSwitchBusy')
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
target.classList.toggle('on');
|
2020-04-27 16:33:49 +02:00
|
|
|
renderTooltips(`#${switchName}`);
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
const response = await messaging.send('popupPanel', {
|
|
|
|
what: 'toggleHostnameSwitch',
|
|
|
|
name: switchName,
|
|
|
|
hostname: popupData.pageHostname,
|
|
|
|
state: target.classList.contains('on'),
|
|
|
|
tabId: popupData.tabId,
|
2020-02-10 14:06:36 +01:00
|
|
|
persist: ev.ctrlKey || ev.metaKey,
|
2020-01-25 15:24:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
cachePopupData(response);
|
|
|
|
hashFromPopupData();
|
2021-02-15 12:52:31 +01:00
|
|
|
|
|
|
|
document.body.classList.toggle('needSave', popupData.matrixIsDirty === true);
|
2020-01-25 15:24:59 +01:00
|
|
|
};
|
|
|
|
|
2020-05-23 12:37:04 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2020-05-24 01:48:28 +02:00
|
|
|
Double tap ctrl key: toggle god mode
|
2020-05-23 12:37:04 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-05-24 01:48:28 +02:00
|
|
|
{
|
|
|
|
let eventCount = 0;
|
|
|
|
let eventTime = 0;
|
|
|
|
|
|
|
|
document.addEventListener('keydown', ev => {
|
|
|
|
if ( ev.key !== 'Control' ) {
|
|
|
|
eventCount = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const now = Date.now();
|
|
|
|
if ( (now - eventTime) >= 500 ) {
|
|
|
|
eventCount = 0;
|
|
|
|
}
|
|
|
|
eventCount += 1;
|
|
|
|
eventTime = now;
|
|
|
|
if ( eventCount < 2 ) { return; }
|
|
|
|
eventCount = 0;
|
2020-05-23 12:37:04 +02:00
|
|
|
document.body.classList.toggle('godMode');
|
2020-05-24 01:48:28 +02:00
|
|
|
});
|
|
|
|
}
|
2020-05-23 12:37:04 +02:00
|
|
|
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// Poll for changes.
|
|
|
|
//
|
|
|
|
// I couldn't find a better way to be notified of changes which can affect
|
|
|
|
// popup content, as the messaging API doesn't support firing events accurately
|
|
|
|
// from the main extension process to a specific auxiliary extension process:
|
|
|
|
//
|
|
|
|
// - broadcasting() is not an option given there could be a lot of tabs opened,
|
|
|
|
// and maybe even many frames within these tabs, i.e. unacceptable overhead
|
|
|
|
// regardless of whether the popup is opened or not.
|
|
|
|
//
|
|
|
|
// - Modifying the messaging API is not an option, as this would require
|
|
|
|
// revisiting all platform-specific code to support targeted broadcasting,
|
|
|
|
// which who knows could be not so trivial for some platforms.
|
|
|
|
//
|
|
|
|
// A well done polling is a better anyways IMO, I prefer that data is pulled
|
|
|
|
// on demand rather than forcing the main process to assume a client may need
|
|
|
|
// it and thus having to push it all the time unconditionally.
|
|
|
|
|
|
|
|
const pollForContentChange = (( ) => {
|
|
|
|
let pollTimer;
|
|
|
|
|
|
|
|
const pollCallback = async function() {
|
|
|
|
pollTimer = undefined;
|
|
|
|
const response = await messaging.send('popupPanel', {
|
|
|
|
what: 'hasPopupContentChanged',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
contentLastModified: popupData.contentLastModified,
|
|
|
|
});
|
|
|
|
queryCallback(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
const queryCallback = function(response) {
|
|
|
|
if ( response ) {
|
|
|
|
getPopupData(popupData.tabId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
poll();
|
|
|
|
};
|
|
|
|
|
|
|
|
const poll = function() {
|
|
|
|
if ( pollTimer !== undefined ) { return; }
|
|
|
|
pollTimer = vAPI.setTimeout(pollCallback, 1500);
|
|
|
|
};
|
|
|
|
|
|
|
|
return poll;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-05-15 16:45:31 +02:00
|
|
|
const getPopupData = async function(tabId, first = false) {
|
2020-01-25 15:24:59 +01:00
|
|
|
const response = await messaging.send('popupPanel', {
|
|
|
|
what: 'getPopupData',
|
|
|
|
tabId,
|
|
|
|
});
|
|
|
|
|
|
|
|
cachePopupData(response);
|
|
|
|
renderOnce();
|
|
|
|
renderPopup();
|
|
|
|
renderPopupLazy(); // low priority rendering
|
2021-05-15 16:45:31 +02:00
|
|
|
hashFromPopupData(first);
|
2020-01-25 15:24:59 +01:00
|
|
|
pollForContentChange();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// Popup DOM is assumed to be loaded at this point -- because this script
|
2020-08-21 14:23:36 +02:00
|
|
|
// is loaded after everything else.
|
2020-01-25 15:24:59 +01:00
|
|
|
|
|
|
|
{
|
2020-08-21 14:23:36 +02:00
|
|
|
// Extract the tab id of the page for this popup. If there's no tab id
|
|
|
|
// specified in the query string, it will default to current tab.
|
|
|
|
const selfURL = new URL(self.location.href);
|
|
|
|
const tabId = parseInt(selfURL.searchParams.get('tabId'), 10) || null;
|
2020-04-21 22:33:08 +02:00
|
|
|
|
2020-05-07 21:42:30 +02:00
|
|
|
const nextFrames = async n => {
|
|
|
|
for ( let i = 0; i < n; i++ ) {
|
2020-05-08 15:16:20 +02:00
|
|
|
await new Promise(resolve => {
|
|
|
|
self.requestAnimationFrame(( ) => { resolve(); });
|
|
|
|
});
|
2020-05-07 21:42:30 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-21 22:33:08 +02:00
|
|
|
// The purpose of the following code is to reset to a vertical layout
|
2020-05-03 15:18:53 +02:00
|
|
|
// should the viewport not be enough wide to accomodate the horizontal
|
2020-04-21 22:33:08 +02:00
|
|
|
// layout.
|
2020-05-03 15:18:53 +02:00
|
|
|
// To avoid querying a spurious viewport width -- it happens sometimes,
|
|
|
|
// somehow -- we delay layout-changing operations to the next paint
|
|
|
|
// frames.
|
2020-05-06 16:39:03 +02:00
|
|
|
// Force a layout recalculation by querying the body width. To be
|
|
|
|
// honest, I have no clue if this makes a difference in the end.
|
|
|
|
// https://gist.github.com/paulirish/5d52fb081b3570c81e3a
|
|
|
|
// Use a tolerance proportional to the sum of the width of the panes
|
|
|
|
// when testing against viewport width.
|
2020-05-03 15:18:53 +02:00
|
|
|
const checkViewport = async function() {
|
2020-04-21 22:33:08 +02:00
|
|
|
const root = document.querySelector(':root');
|
2020-08-21 14:23:36 +02:00
|
|
|
if (
|
|
|
|
root.classList.contains('mobile') ||
|
|
|
|
selfURL.searchParams.get('portrait')
|
|
|
|
) {
|
|
|
|
root.classList.add('portrait');
|
|
|
|
} else if ( root.classList.contains('desktop') ) {
|
2020-05-08 15:16:20 +02:00
|
|
|
await nextFrames(4);
|
2020-05-17 14:49:37 +02:00
|
|
|
const main = document.getElementById('main');
|
2020-04-21 22:33:08 +02:00
|
|
|
const firewall = document.getElementById('firewall');
|
2020-05-06 16:39:03 +02:00
|
|
|
const minWidth = (main.offsetWidth + firewall.offsetWidth) / 1.1;
|
2020-08-21 14:23:36 +02:00
|
|
|
if (
|
|
|
|
selfURL.searchParams.get('portrait') ||
|
|
|
|
window.innerWidth < minWidth
|
|
|
|
) {
|
2020-05-17 14:49:37 +02:00
|
|
|
root.classList.add('portrait');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( root.classList.contains('portrait') ) {
|
|
|
|
const panes = document.getElementById('panes');
|
|
|
|
const sticky = document.getElementById('sticky');
|
|
|
|
const stickyParent = sticky.parentElement;
|
|
|
|
if ( stickyParent !== panes ) {
|
|
|
|
panes.prepend(sticky);
|
2020-04-21 22:33:08 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-18 16:00:55 +02:00
|
|
|
if ( selfURL.searchParams.get('intab') !== null ) {
|
|
|
|
root.classList.add('intab');
|
|
|
|
}
|
2020-05-08 15:16:20 +02:00
|
|
|
await nextFrames(1);
|
2020-05-03 15:18:53 +02:00
|
|
|
document.body.classList.remove('loading');
|
2020-04-21 22:33:08 +02:00
|
|
|
};
|
|
|
|
|
2021-05-15 16:45:31 +02:00
|
|
|
getPopupData(tabId, true).then(( ) => {
|
2020-04-21 22:33:08 +02:00
|
|
|
if ( document.readyState !== 'complete' ) {
|
2020-05-03 15:18:53 +02:00
|
|
|
self.addEventListener('load', ( ) => { checkViewport(); }, { once: true });
|
2020-04-21 22:33:08 +02:00
|
|
|
} else {
|
|
|
|
checkViewport();
|
|
|
|
}
|
|
|
|
});
|
2020-01-25 15:24:59 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
uDom('#switch').on('click', toggleNetFilteringSwitch);
|
|
|
|
uDom('#gotoZap').on('click', gotoZap);
|
|
|
|
uDom('#gotoPick').on('click', gotoPick);
|
|
|
|
uDom('.hnSwitch').on('click', ev => { toggleHostnameSwitch(ev); });
|
|
|
|
uDom('#saveRules').on('click', saveFirewallRules);
|
|
|
|
uDom('#revertRules').on('click', ( ) => { revertFirewallRules(); });
|
|
|
|
uDom('a[href]').on('click', gotoURL);
|
|
|
|
|
2021-04-13 15:08:53 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-02-15 12:52:31 +01:00
|
|
|
// Toggle emphasis of rows with[out] 3rd-party scripts/frames
|
2021-04-13 15:08:53 +02:00
|
|
|
document.querySelector('#firewall > [data-type="3p-script"] .filter')
|
|
|
|
.addEventListener('click', ( ) => {
|
|
|
|
document.getElementById('firewall').classList.toggle('show3pScript');
|
|
|
|
});
|
2021-02-15 12:52:31 +01:00
|
|
|
|
2021-04-13 15:08:53 +02:00
|
|
|
// Toggle visibility of rows with[out] 3rd-party frames
|
|
|
|
document.querySelector('#firewall > [data-type="3p-frame"] .filter')
|
|
|
|
.addEventListener('click', ( ) => {
|
|
|
|
document.getElementById('firewall').classList.toggle('show3pFrame');
|
|
|
|
});
|
2021-02-15 12:52:31 +01:00
|
|
|
|
2020-01-25 15:24:59 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// <<<<< end of local scope
|
|
|
|
}
|