2014-06-24 00:42:43 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2018-09-01 00:47:02 +02:00
|
|
|
Copyright (C) 2014-present Raymond Hill
|
2014-06-24 00:42:43 +02: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/uBlock
|
|
|
|
*/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
/* global punycode, uDom */
|
2014-07-07 03:52:16 +02:00
|
|
|
|
2016-08-06 18:05:01 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-07-21 17:50:15 +02:00
|
|
|
(( ) => {
|
2015-03-16 14:20:58 +01:00
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
let popupFontSize = vAPI.localStorage.getItem('popupFontSize');
|
2016-11-06 22:27:21 +01:00
|
|
|
if ( typeof popupFontSize === 'string' && popupFontSize !== 'unset' ) {
|
|
|
|
document.body.style.setProperty('font-size', popupFontSize);
|
|
|
|
}
|
|
|
|
|
2018-05-05 12:28:16 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/3032
|
2018-05-04 14:44:54 +02:00
|
|
|
// Popup panel can be in one of two modes:
|
|
|
|
// - not responsive: viewport is expected to adjust to popup panel size
|
2018-05-05 12:28:16 +02:00
|
|
|
// - responsive: popup panel must adjust to viewport size -- this happens
|
|
|
|
// when the viewport is not resized by the browser to perfectly fits uBO's
|
|
|
|
// popup panel.
|
|
|
|
if (
|
|
|
|
vAPI.webextFlavor.soup.has('mobile') ||
|
|
|
|
/[\?&]responsive=1/.test(window.location.search)
|
|
|
|
) {
|
2018-05-04 14:44:54 +02:00
|
|
|
document.body.classList.add('responsive');
|
2016-12-29 05:39:15 +01:00
|
|
|
}
|
2015-03-22 13:51:31 +01:00
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/996
|
2018-05-05 12:28:16 +02:00
|
|
|
// Experimental: mitigate glitchy popup UI: immediately set the firewall
|
|
|
|
// pane visibility to its last known state. By default the pane is hidden.
|
|
|
|
let dfPaneVisibleStored =
|
|
|
|
vAPI.localStorage.getItem('popupFirewallPane') === 'true';
|
2015-03-22 13:51:31 +01:00
|
|
|
if ( dfPaneVisibleStored ) {
|
|
|
|
document.getElementById('panes').classList.add('dfEnabled');
|
|
|
|
}
|
2015-03-14 22:30:44 +01:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const messaging = vAPI.messaging;
|
|
|
|
const reIP = /^\d+(?:\.\d+){1,3}$/;
|
|
|
|
const scopeToSrcHostnameMap = {
|
2014-12-30 22:36:29 +01:00
|
|
|
'/': '*',
|
|
|
|
'.': ''
|
|
|
|
};
|
2018-12-22 17:19:44 +01:00
|
|
|
const hostnameToSortableTokenMap = new Map();
|
|
|
|
const statsStr = vAPI.i18n('popupBlockedStats');
|
|
|
|
const domainsHitStr = vAPI.i18n('popupHitDomainCount');
|
|
|
|
|
|
|
|
let popupData = {};
|
|
|
|
let dfPaneBuilt = false;
|
|
|
|
let dfHotspots = null;
|
|
|
|
let allDomains = {};
|
|
|
|
let allDomainCount = 0;
|
|
|
|
let allHostnameRows = [];
|
|
|
|
let touchedDomainCount = 0;
|
|
|
|
let cachedPopupHash = '';
|
2017-04-22 20:26:17 +02:00
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/2550
|
|
|
|
// Solution inspired from
|
2017-04-23 01:23:11 +02:00
|
|
|
// - https://bugs.chromium.org/p/chromium/issues/detail?id=683314
|
2017-04-22 20:26:17 +02:00
|
|
|
// - 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
|
2018-12-22 17:19:44 +01:00
|
|
|
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]/;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-05-04 14:44:54 +02:00
|
|
|
// The padlock/eraser must be manually positioned:
|
|
|
|
// - Its vertical position depends on the height of the popup title bar
|
|
|
|
// - Its horizontal position depends on whether there is a vertical scrollbar.
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const positionRulesetTools = function() {
|
|
|
|
const vpos = document.getElementById('appinfo')
|
|
|
|
.getBoundingClientRect()
|
|
|
|
.bottom + window.scrollY + 3;
|
|
|
|
const hpos = document.getElementById('firewallContainer')
|
|
|
|
.getBoundingClientRect()
|
|
|
|
.left + window.scrollX + 3;
|
|
|
|
const style = document.getElementById('rulesetTools').style;
|
2018-05-04 14:44:54 +02:00
|
|
|
style.setProperty('top', (vpos >>> 0) + 'px');
|
|
|
|
style.setProperty('left', (hpos >>> 0) + 'px');
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const cachePopupData = function(data) {
|
2015-01-06 14:01:15 +01:00
|
|
|
popupData = {};
|
2014-12-31 23:26:17 +01:00
|
|
|
scopeToSrcHostnameMap['.'] = '';
|
2018-07-04 15:38:37 +02:00
|
|
|
hostnameToSortableTokenMap.clear();
|
2015-01-07 01:51:50 +01:00
|
|
|
|
2014-12-31 23:26:17 +01:00
|
|
|
if ( typeof data !== 'object' ) {
|
2015-01-06 14:01:15 +01:00
|
|
|
return popupData;
|
2014-12-25 14:53:30 +01:00
|
|
|
}
|
2015-01-06 14:01:15 +01:00
|
|
|
popupData = data;
|
|
|
|
scopeToSrcHostnameMap['.'] = popupData.pageHostname || '';
|
2018-12-22 17:19:44 +01:00
|
|
|
const hostnameDict = popupData.hostnameDict;
|
2015-01-07 01:51:50 +01:00
|
|
|
if ( typeof hostnameDict !== 'object' ) {
|
|
|
|
return popupData;
|
|
|
|
}
|
2018-12-22 17:19:44 +01:00
|
|
|
for ( const hostname in hostnameDict ) {
|
2018-07-04 15:38:37 +02:00
|
|
|
if ( hostnameDict.hasOwnProperty(hostname) === false ) { continue; }
|
|
|
|
let domain = hostnameDict[hostname].domain;
|
|
|
|
let prefix = hostname.slice(0, 0 - domain.length - 1);
|
2015-10-25 13:18:10 +01:00
|
|
|
// Prefix with space char for 1st-party hostnames: this ensure these
|
|
|
|
// will come first in list.
|
2015-01-07 01:51:50 +01:00
|
|
|
if ( domain === popupData.pageDomain ) {
|
|
|
|
domain = '\u0020';
|
|
|
|
}
|
2018-07-04 15:38:37 +02:00
|
|
|
hostnameToSortableTokenMap.set(
|
|
|
|
hostname,
|
|
|
|
domain + ' ' + prefix.split('.').reverse().join('.')
|
|
|
|
);
|
2014-12-30 22:36:29 +01:00
|
|
|
}
|
2015-01-06 14:01:15 +01:00
|
|
|
return popupData;
|
2014-12-30 22:36:29 +01:00
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const hashFromPopupData = function(reset) {
|
2015-01-24 18:06:22 +01:00
|
|
|
// It makes no sense to offer to refresh the behind-the-scene scope
|
|
|
|
if ( popupData.pageHostname === 'behind-the-scene' ) {
|
|
|
|
uDom('body').toggleClass('dirty', false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const hasher = [];
|
|
|
|
const rules = popupData.firewallRules;
|
|
|
|
for ( const key in rules ) {
|
|
|
|
const rule = rules[key];
|
|
|
|
if ( rule === null ) { continue; }
|
|
|
|
hasher.push(
|
|
|
|
rule.src + ' ' +
|
|
|
|
rule.des + ' ' +
|
|
|
|
rule.type + ' ' +
|
|
|
|
rule.action
|
|
|
|
);
|
2014-06-24 07:20:59 +02:00
|
|
|
}
|
2015-04-05 18:03:14 +02:00
|
|
|
hasher.sort();
|
2015-02-09 21:24:24 +01:00
|
|
|
hasher.push(uDom('body').hasClass('off'));
|
2016-01-17 19:30:43 +01:00
|
|
|
hasher.push(uDom.nodeFromId('no-large-media').classList.contains('on'));
|
2015-06-10 15:23:48 +02:00
|
|
|
hasher.push(uDom.nodeFromId('no-cosmetic-filtering').classList.contains('on'));
|
|
|
|
hasher.push(uDom.nodeFromId('no-remote-fonts').classList.contains('on'));
|
2018-09-01 00:47:02 +02:00
|
|
|
hasher.push(uDom.nodeFromId('no-scripting').classList.contains('on'));
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const hash = hasher.join('');
|
2015-01-10 17:23:28 +01:00
|
|
|
if ( reset ) {
|
|
|
|
cachedPopupHash = hash;
|
|
|
|
}
|
|
|
|
uDom('body').toggleClass('dirty', hash !== cachedPopupHash);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const formatNumber = function(count) {
|
2015-01-10 17:23:28 +01:00
|
|
|
return typeof count === 'number' ? count.toLocaleString() : '';
|
2014-06-24 07:20:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const rulekeyCompare = function(a, b) {
|
|
|
|
let ha = a.slice(2, a.indexOf(' ', 2));
|
2014-12-30 22:36:29 +01:00
|
|
|
if ( !reIP.test(ha) ) {
|
2018-07-04 15:38:37 +02:00
|
|
|
ha = hostnameToSortableTokenMap.get(ha) || ' ';
|
2014-12-30 22:36:29 +01:00
|
|
|
}
|
2018-12-22 17:19:44 +01:00
|
|
|
let hb = b.slice(2, b.indexOf(' ', 2));
|
2014-12-30 22:36:29 +01:00
|
|
|
if ( !reIP.test(hb) ) {
|
2018-07-04 15:38:37 +02:00
|
|
|
hb = hostnameToSortableTokenMap.get(hb) || ' ';
|
2015-10-25 14:38:48 +01:00
|
|
|
}
|
2018-12-22 17:19:44 +01:00
|
|
|
const ca = ha.charCodeAt(0);
|
|
|
|
const cb = hb.charCodeAt(0);
|
2015-10-25 14:38:48 +01:00
|
|
|
if ( ca !== cb ) {
|
|
|
|
return ca - cb;
|
2014-12-30 22:36:29 +01:00
|
|
|
}
|
|
|
|
return ha.localeCompare(hb);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const updateFirewallCell = function(scope, des, type, rule) {
|
2018-12-29 12:54:05 +01:00
|
|
|
const row = document.querySelector(
|
|
|
|
`#firewallContainer div[data-des="${des}"][data-type="${type}"]`
|
|
|
|
);
|
|
|
|
if ( row === null ) { return; }
|
|
|
|
|
|
|
|
const cells = row.querySelectorAll(`:scope > span[data-src="${scope}"]`);
|
2018-12-22 17:19:44 +01:00
|
|
|
if ( cells.length === 0 ) { return; }
|
2014-12-30 22:36:29 +01:00
|
|
|
|
2017-05-12 16:35:11 +02:00
|
|
|
if ( rule !== null ) {
|
2018-12-29 12:54:05 +01:00
|
|
|
cells.forEach(el => { el.setAttribute('class', rule.action + 'Rule'); });
|
|
|
|
} else {
|
|
|
|
cells.forEach(el => { el.removeAttribute('class'); });
|
2014-12-31 16:47:19 +01:00
|
|
|
}
|
2014-10-27 17:14:57 +01:00
|
|
|
|
2016-09-27 14:31:12 +02:00
|
|
|
// Use dark shade visual cue if the rule is specific to the cell.
|
2018-12-29 12:54:05 +01:00
|
|
|
if (
|
|
|
|
(rule !== null) &&
|
|
|
|
(rule.des !== '*' || rule.type === type) &&
|
|
|
|
(rule.des === des) &&
|
|
|
|
(rule.src === scopeToSrcHostnameMap[scope])
|
|
|
|
|
|
|
|
) {
|
|
|
|
cells.forEach(el => { el.classList.add('ownRule'); });
|
2014-10-27 17:14:57 +01:00
|
|
|
}
|
2014-12-30 22:36:29 +01:00
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
if ( scope !== '.' || des === '*' ) { return; }
|
2015-02-07 21:39:46 +01:00
|
|
|
|
|
|
|
// Remember this may be a cell from a reused row, we need to clear text
|
2015-02-07 21:32:20 +01:00
|
|
|
// content if we can't compute request counts.
|
2015-02-07 21:39:46 +01:00
|
|
|
if ( popupData.hostnameDict.hasOwnProperty(des) === false ) {
|
2018-12-29 12:54:05 +01:00
|
|
|
cells.forEach(el => {
|
|
|
|
el.removeAttribute('data-acount');
|
|
|
|
el.removeAttribute('data-bcount');
|
|
|
|
});
|
2014-12-30 22:36:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-02-07 21:32:20 +01:00
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const hnDetails = popupData.hostnameDict[des];
|
2018-12-29 12:54:05 +01:00
|
|
|
let cell = cells[0];
|
2016-11-05 19:48:42 +01:00
|
|
|
if ( hnDetails.allowCount !== 0 ) {
|
|
|
|
cell.setAttribute('data-acount', Math.min(Math.ceil(Math.log(hnDetails.allowCount + 1) / Math.LN10), 3));
|
2015-02-17 03:15:09 +01:00
|
|
|
} else {
|
2016-11-05 19:48:42 +01:00
|
|
|
cell.removeAttribute('data-acount');
|
|
|
|
}
|
|
|
|
if ( hnDetails.blockCount !== 0 ) {
|
|
|
|
cell.setAttribute('data-bcount', Math.min(Math.ceil(Math.log(hnDetails.blockCount + 1) / Math.LN10), 3));
|
|
|
|
} else {
|
|
|
|
cell.removeAttribute('data-bcount');
|
2015-02-17 03:15:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( hnDetails.domain !== des ) {
|
2015-01-01 13:29:28 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-02-07 21:32:20 +01:00
|
|
|
|
2018-12-29 12:54:05 +01:00
|
|
|
cell = cells[1];
|
2016-11-05 19:48:42 +01:00
|
|
|
if ( hnDetails.totalAllowCount !== 0 ) {
|
|
|
|
cell.setAttribute('data-acount', Math.min(Math.ceil(Math.log(hnDetails.totalAllowCount + 1) / Math.LN10), 3));
|
|
|
|
} else {
|
|
|
|
cell.removeAttribute('data-acount');
|
|
|
|
}
|
|
|
|
if ( hnDetails.totalBlockCount !== 0 ) {
|
|
|
|
cell.setAttribute('data-bcount', Math.min(Math.ceil(Math.log(hnDetails.totalBlockCount + 1) / Math.LN10), 3));
|
2015-02-17 03:15:09 +01:00
|
|
|
} else {
|
2016-11-05 19:48:42 +01:00
|
|
|
cell.removeAttribute('data-bcount');
|
2015-02-17 03:15:09 +01:00
|
|
|
}
|
2014-10-06 20:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const updateAllFirewallCells = function() {
|
|
|
|
const rules = popupData.firewallRules;
|
|
|
|
for ( const key in rules ) {
|
|
|
|
if ( rules.hasOwnProperty(key) === false ) { continue; }
|
2015-02-11 06:26:45 +01:00
|
|
|
updateFirewallCell(
|
2015-01-10 17:23:28 +01:00
|
|
|
key.charAt(0),
|
|
|
|
key.slice(2, key.indexOf(' ', 2)),
|
|
|
|
key.slice(key.lastIndexOf(' ') + 1),
|
|
|
|
rules[key]
|
|
|
|
);
|
|
|
|
}
|
2015-02-11 06:26:45 +01:00
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const dirty = popupData.matrixIsDirty === true;
|
2018-04-04 14:17:53 +02:00
|
|
|
if ( dirty ) {
|
|
|
|
positionRulesetTools();
|
|
|
|
}
|
|
|
|
uDom.nodeFromId('firewallContainer').classList.toggle('dirty', dirty);
|
2015-01-10 17:23:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-19 20:05:19 +01:00
|
|
|
const buildAllFirewallRows = function() {
|
2015-01-10 17:23:28 +01:00
|
|
|
// Do this before removing the rows
|
|
|
|
if ( dfHotspots === null ) {
|
2015-04-22 16:46:10 +02:00
|
|
|
dfHotspots = uDom('#actionSelector')
|
|
|
|
.toggleClass('colorBlind', popupData.colorBlindFriendly)
|
|
|
|
.on('click', 'span', setFirewallRuleHandler);
|
2014-12-30 22:36:29 +01:00
|
|
|
}
|
2015-01-10 17:23:28 +01:00
|
|
|
dfHotspots.detach();
|
|
|
|
|
2018-12-29 14:43:44 +01:00
|
|
|
// Update incrementally: reuse existing rows if possible.
|
|
|
|
let rowContainer = document.getElementById('firewallContainer');
|
|
|
|
let toAppend = document.createDocumentFragment();
|
|
|
|
let rowTemplate = document.querySelector('#templates > div:nth-of-type(1)');
|
|
|
|
let row = rowContainer.querySelector('div:nth-of-type(7) + div');
|
|
|
|
|
|
|
|
for ( const des of allHostnameRows ) {
|
|
|
|
if ( row === null ) {
|
|
|
|
row = rowTemplate.cloneNode(true);
|
|
|
|
toAppend.appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
row.setAttribute('data-des', des);
|
|
|
|
|
|
|
|
const hnDetails = popupData.hostnameDict[des] || {};
|
|
|
|
const isDomain = des === hnDetails.domain;
|
|
|
|
const prettyDomainName = punycode.toUnicode(des);
|
|
|
|
const isPunycoded = prettyDomainName !== des;
|
|
|
|
|
|
|
|
const span = row.querySelector('span:first-of-type');
|
|
|
|
span.classList.toggle(
|
|
|
|
'isIDN',
|
|
|
|
isPunycoded &&
|
|
|
|
reCyrillicAmbiguous.test(prettyDomainName) === true &&
|
|
|
|
reCyrillicNonAmbiguous.test(prettyDomainName) === false
|
|
|
|
);
|
|
|
|
span.querySelector('span').textContent = prettyDomainName;
|
|
|
|
span.title = isDomain && isPunycoded ? des : '';
|
|
|
|
|
|
|
|
const classList = row.classList;
|
|
|
|
classList.toggle('isDomain', isDomain);
|
|
|
|
classList.toggle('isSubDomain', !isDomain);
|
|
|
|
classList.toggle('allowed', hnDetails.allowCount !== 0);
|
|
|
|
classList.toggle('blocked', hnDetails.blockCount !== 0);
|
|
|
|
classList.toggle('totalAllowed', hnDetails.totalAllowCount !== 0);
|
|
|
|
classList.toggle('totalBlocked', hnDetails.totalBlockCount !== 0);
|
|
|
|
|
|
|
|
row = row.nextElementSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove unused trailing rows
|
|
|
|
if ( row !== null ) {
|
|
|
|
while ( row.nextElementSibling !== null ) {
|
|
|
|
rowContainer.removeChild(row.nextElementSibling);
|
|
|
|
}
|
|
|
|
rowContainer.removeChild(row);
|
|
|
|
}
|
2015-02-06 23:42:09 +01:00
|
|
|
|
2018-12-29 14:43:44 +01:00
|
|
|
// Add new rows all at once
|
|
|
|
if ( toAppend.childElementCount !== 0 ) {
|
|
|
|
rowContainer.appendChild(toAppend);
|
2015-02-06 23:42:09 +01:00
|
|
|
}
|
|
|
|
|
2016-11-05 19:48:42 +01:00
|
|
|
if ( dfPaneBuilt !== true && popupData.advancedUserEnabled ) {
|
2015-02-11 06:26:45 +01:00
|
|
|
uDom('#firewallContainer')
|
|
|
|
.on('click', 'span[data-src]', unsetFirewallRuleHandler)
|
2015-02-06 23:42:09 +01:00
|
|
|
.on('mouseenter', '[data-src]', mouseenterCellHandler)
|
|
|
|
.on('mouseleave', '[data-src]', mouseleaveCellHandler);
|
|
|
|
dfPaneBuilt = true;
|
|
|
|
}
|
|
|
|
|
2015-02-11 06:26:45 +01:00
|
|
|
updateAllFirewallCells();
|
2015-02-06 23:42:09 +01:00
|
|
|
};
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2015-02-06 23:42:09 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-19 20:05:19 +01:00
|
|
|
const renderPrivacyExposure = function() {
|
2015-01-10 17:23:28 +01:00
|
|
|
allDomains = {};
|
|
|
|
allDomainCount = touchedDomainCount = 0;
|
2015-02-06 23:46:20 +01:00
|
|
|
allHostnameRows = [];
|
2014-12-30 22:36:29 +01:00
|
|
|
|
|
|
|
// Sort hostnames. First-party hostnames must always appear at the top
|
|
|
|
// of the list.
|
2018-12-19 20:05:19 +01:00
|
|
|
const desHostnameDone = {};
|
|
|
|
const keys = Object.keys(popupData.firewallRules)
|
2015-01-10 17:23:28 +01:00
|
|
|
.sort(rulekeyCompare);
|
2018-12-19 20:05:19 +01:00
|
|
|
for ( const key of keys ) {
|
|
|
|
const des = key.slice(2, key.indexOf(' ', 2));
|
2015-02-04 15:03:34 +01:00
|
|
|
// Specific-type rules -- these are built-in
|
2018-12-19 20:05:19 +01:00
|
|
|
if ( des === '*' || desHostnameDone.hasOwnProperty(des) ) { continue; }
|
|
|
|
const hnDetails = popupData.hostnameDict[des] || {};
|
2015-02-06 23:42:09 +01:00
|
|
|
if ( allDomains.hasOwnProperty(hnDetails.domain) === false ) {
|
|
|
|
allDomains[hnDetails.domain] = false;
|
|
|
|
allDomainCount += 1;
|
|
|
|
}
|
|
|
|
if ( hnDetails.allowCount !== 0 ) {
|
|
|
|
if ( allDomains[hnDetails.domain] === false ) {
|
|
|
|
allDomains[hnDetails.domain] = true;
|
|
|
|
touchedDomainCount += 1;
|
|
|
|
}
|
|
|
|
}
|
2015-02-06 23:46:20 +01:00
|
|
|
allHostnameRows.push(des);
|
2015-01-10 17:23:28 +01:00
|
|
|
desHostnameDone[des] = true;
|
2014-10-06 20:02:44 +02:00
|
|
|
}
|
2014-12-30 22:36:29 +01:00
|
|
|
|
2018-12-19 20:05:19 +01:00
|
|
|
const summary = domainsHitStr
|
|
|
|
.replace('{{count}}', touchedDomainCount.toLocaleString())
|
|
|
|
.replace('{{total}}', allDomainCount.toLocaleString());
|
2015-06-10 15:23:48 +02:00
|
|
|
uDom.nodeFromId('popupHitDomainCount').textContent = summary;
|
2014-10-06 20:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-19 20:05:19 +01:00
|
|
|
const updateHnSwitches = function() {
|
2018-09-03 20:06:49 +02:00
|
|
|
uDom.nodeFromId('no-popups').classList.toggle(
|
|
|
|
'on',
|
|
|
|
popupData.noPopups === true
|
|
|
|
);
|
|
|
|
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
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-01-10 17:23:28 +01:00
|
|
|
// Assume everything has to be done incrementally.
|
|
|
|
|
2018-12-19 20:05:19 +01:00
|
|
|
const renderPopup = function() {
|
2015-03-12 18:48:43 +01:00
|
|
|
if ( popupData.tabTitle ) {
|
|
|
|
document.title = popupData.appName + ' - ' + popupData.tabTitle;
|
2015-03-02 19:49:34 +01:00
|
|
|
}
|
2015-03-12 18:48:43 +01:00
|
|
|
|
2018-09-07 16:52:10 +02:00
|
|
|
let elem = document.body;
|
2018-09-18 21:21:00 +02:00
|
|
|
elem.classList.toggle(
|
|
|
|
'advancedUser',
|
|
|
|
popupData.advancedUserEnabled === true
|
|
|
|
);
|
2017-11-07 22:38:26 +01:00
|
|
|
elem.classList.toggle(
|
|
|
|
'off',
|
2018-09-18 21:21:00 +02:00
|
|
|
popupData.pageURL === '' || popupData.netFilteringSwitch !== true
|
2017-11-07 22:38:26 +01:00
|
|
|
);
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2018-09-18 21:21:00 +02:00
|
|
|
let canElementPicker = popupData.canElementPicker === true &&
|
|
|
|
popupData.netFilteringSwitch === true;
|
2018-09-07 16:52:10 +02:00
|
|
|
uDom.nodeFromId('gotoPick').classList.toggle('enabled', canElementPicker);
|
|
|
|
uDom.nodeFromId('gotoZap').classList.toggle('enabled', canElementPicker);
|
2014-07-02 18:02:29 +02:00
|
|
|
|
2018-09-07 16:52:10 +02:00
|
|
|
let blocked = popupData.pageBlockedRequestCount,
|
|
|
|
total = popupData.pageAllowedRequestCount + blocked,
|
|
|
|
text;
|
2014-06-24 00:42:43 +02:00
|
|
|
if ( total === 0 ) {
|
2015-03-11 16:21:29 +01:00
|
|
|
text = formatNumber(0);
|
2014-06-24 00:42:43 +02:00
|
|
|
} else {
|
2015-03-11 16:21:29 +01:00
|
|
|
text = statsStr.replace('{{count}}', formatNumber(blocked))
|
|
|
|
.replace('{{percent}}', formatNumber(Math.floor(blocked * 100 / total)));
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
2015-06-10 15:23:48 +02:00
|
|
|
uDom.nodeFromId('page-blocked').textContent = text;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
blocked = popupData.globalBlockedRequestCount;
|
|
|
|
total = popupData.globalAllowedRequestCount + blocked;
|
2014-06-24 00:42:43 +02:00
|
|
|
if ( total === 0 ) {
|
2015-03-11 16:21:29 +01:00
|
|
|
text = formatNumber(0);
|
2014-06-24 00:42:43 +02:00
|
|
|
} else {
|
2015-03-11 16:21:29 +01:00
|
|
|
text = statsStr.replace('{{count}}', formatNumber(blocked))
|
|
|
|
.replace('{{percent}}', formatNumber(Math.floor(blocked * 100 / total)));
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
2015-06-10 15:23:48 +02:00
|
|
|
uDom.nodeFromId('total-blocked').textContent = text;
|
2015-02-06 23:42:09 +01:00
|
|
|
|
|
|
|
// This will collate all domains, touched or not
|
|
|
|
renderPrivacyExposure();
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2015-03-27 18:00:55 +01:00
|
|
|
// Extra tools
|
2018-09-03 20:06:49 +02:00
|
|
|
updateHnSwitches();
|
2015-06-10 15:23:48 +02:00
|
|
|
|
2016-01-04 16:48:28 +01:00
|
|
|
// Report blocked popup count on badge
|
|
|
|
total = popupData.popupBlockedCount;
|
2018-12-18 19:35:44 +01:00
|
|
|
uDom.nodeFromSelector('#no-popups > span.fa-icon-badge')
|
2018-12-22 17:19:44 +01:00
|
|
|
.textContent = total ? Math.min(total, 99).toLocaleString() : '';
|
2016-01-04 16:48:28 +01:00
|
|
|
|
2016-01-17 19:30:43 +01:00
|
|
|
// Report large media count on badge
|
|
|
|
total = popupData.largeMediaCount;
|
2018-12-18 19:35:44 +01:00
|
|
|
uDom.nodeFromSelector('#no-large-media > span.fa-icon-badge')
|
2018-12-22 17:19:44 +01:00
|
|
|
.textContent = total ? Math.min(total, 99).toLocaleString() : '';
|
2016-01-17 19:30:43 +01:00
|
|
|
|
2015-06-10 15:23:48 +02:00
|
|
|
// Report remote font count on badge
|
|
|
|
total = popupData.remoteFontCount;
|
2018-12-18 19:35:44 +01:00
|
|
|
uDom.nodeFromSelector('#no-remote-fonts > span.fa-icon-badge')
|
2018-12-22 17:19:44 +01:00
|
|
|
.textContent = total ? Math.min(total, 99).toLocaleString() : '';
|
2015-03-27 18:00:55 +01:00
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/470
|
2015-01-10 17:23:28 +01:00
|
|
|
// This must be done here, to be sure the popup is resized properly
|
2018-12-19 20:05:19 +01:00
|
|
|
const dfPaneVisible = popupData.dfEnabled;
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/1068
|
2015-03-22 13:51:31 +01: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.
|
|
|
|
if ( dfPaneVisible !== dfPaneVisibleStored ) {
|
|
|
|
dfPaneVisibleStored = dfPaneVisible;
|
|
|
|
vAPI.localStorage.setItem('popupFirewallPane', dfPaneVisibleStored);
|
|
|
|
}
|
|
|
|
|
2018-09-18 21:21:00 +02:00
|
|
|
uDom.nodeFromId('panes').classList.toggle(
|
|
|
|
'dfEnabled',
|
|
|
|
dfPaneVisible === true
|
|
|
|
);
|
2017-11-07 22:38:26 +01:00
|
|
|
|
|
|
|
elem = uDom.nodeFromId('firewallContainer');
|
2018-09-18 21:21:00 +02:00
|
|
|
elem.classList.toggle(
|
|
|
|
'minimized',
|
|
|
|
popupData.firewallPaneMinimized === true
|
|
|
|
);
|
|
|
|
elem.classList.toggle(
|
|
|
|
'colorBlind',
|
|
|
|
popupData.colorBlindFriendly === true
|
|
|
|
);
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
// Build dynamic filtering pane only if in use
|
2015-01-10 17:23:28 +01:00
|
|
|
if ( dfPaneVisible ) {
|
2015-02-11 06:26:45 +01:00
|
|
|
buildAllFirewallRows();
|
2015-01-06 14:01:15 +01:00
|
|
|
}
|
2017-11-07 22:38:26 +01:00
|
|
|
|
|
|
|
renderTooltips();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/2889
|
|
|
|
// Use tooltip for ARIA purpose.
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const renderTooltips = function(selector) {
|
|
|
|
for ( const entry of tooltipTargetSelectors ) {
|
2017-11-08 13:34:22 +01:00
|
|
|
if ( selector !== undefined && entry[0] !== selector ) { continue; }
|
2018-12-22 17:19:44 +01:00
|
|
|
const text = vAPI.i18n(
|
2017-11-08 13:34:22 +01:00
|
|
|
entry[1].i18n +
|
|
|
|
(uDom.nodeFromSelector(entry[1].state) === null ? '1' : '2')
|
|
|
|
);
|
2018-12-22 17:19:44 +01:00
|
|
|
const elem = uDom.nodeFromSelector(entry[0]);
|
2017-11-07 22:38:26 +01:00
|
|
|
elem.setAttribute('aria-label', text);
|
|
|
|
elem.setAttribute('data-tip', text);
|
2017-11-08 13:34:22 +01:00
|
|
|
if ( selector !== undefined ) {
|
|
|
|
uDom.nodeFromId('tooltip').textContent =
|
|
|
|
elem.getAttribute('data-tip');
|
|
|
|
}
|
2017-11-07 23:03:24 +01:00
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const tooltipTargetSelectors = new Map([
|
2017-11-08 13:34:22 +01:00
|
|
|
[
|
|
|
|
'#switch',
|
|
|
|
{
|
|
|
|
state: 'body.off',
|
|
|
|
i18n: 'popupPowerSwitchInfo',
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'#no-popups',
|
|
|
|
{
|
|
|
|
state: '#no-popups.on',
|
|
|
|
i18n: 'popupTipNoPopups'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'#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'
|
|
|
|
}
|
2018-09-01 00:47:02 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'#no-scripting',
|
|
|
|
{
|
|
|
|
state: '#no-scripting.on',
|
|
|
|
i18n: 'popupTipNoScripting'
|
|
|
|
}
|
|
|
|
],
|
2017-11-08 13:34:22 +01:00
|
|
|
]);
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-12-29 05:39:15 +01:00
|
|
|
// All rendering code which need to be executed only once.
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
let renderOnce = function() {
|
2016-12-29 20:43:20 +01:00
|
|
|
renderOnce = function(){};
|
|
|
|
|
2016-12-29 05:39:15 +01:00
|
|
|
if ( popupData.fontSize !== popupFontSize ) {
|
|
|
|
popupFontSize = popupData.fontSize;
|
|
|
|
if ( popupFontSize !== 'unset' ) {
|
|
|
|
document.body.style.setProperty('font-size', popupFontSize);
|
|
|
|
vAPI.localStorage.setItem('popupFontSize', popupFontSize);
|
|
|
|
} else {
|
|
|
|
document.body.style.removeProperty('font-size');
|
|
|
|
vAPI.localStorage.removeItem('popupFontSize');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uDom.nodeFromId('appname').textContent = popupData.appName;
|
|
|
|
uDom.nodeFromId('version').textContent = popupData.appVersion;
|
|
|
|
|
2018-04-25 05:21:54 +02:00
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/22
|
|
|
|
if ( popupData.advancedUserEnabled !== true ) {
|
|
|
|
uDom('#firewallContainer [data-i18n-tip][data-src]').removeAttr('data-tip');
|
|
|
|
}
|
|
|
|
|
2018-05-04 14:44:54 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/2274
|
|
|
|
// Make use of the whole viewport when in responsive mode.
|
|
|
|
if ( document.body.classList.contains('responsive') ) { return; }
|
|
|
|
|
2016-12-29 20:43:20 +01:00
|
|
|
// For large displays: we do not want the left pane -- optional and
|
|
|
|
// hidden by defaut -- to dictate the height of the popup. The right pane
|
|
|
|
// dictates the height of the popup, and the left pane will have a
|
|
|
|
// scrollbar if ever its height is more than what is available.
|
|
|
|
// For small displays: we use the whole viewport.
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const rpane = uDom.nodeFromSelector('#panes > div:first-of-type');
|
|
|
|
const lpane = uDom.nodeFromSelector('#panes > div:last-of-type');
|
2016-12-29 05:39:15 +01:00
|
|
|
|
2018-05-04 14:44:54 +02:00
|
|
|
lpane.style.setProperty('height', rpane.offsetHeight + 'px');
|
|
|
|
|
|
|
|
// Be prepared to fall into responsive mode if ever it is found the
|
|
|
|
// viewport is not a perfect match for the popup panel.
|
|
|
|
|
|
|
|
let resizeTimer;
|
2018-12-22 17:19:44 +01:00
|
|
|
const resize = function() {
|
2018-05-04 14:44:54 +02:00
|
|
|
resizeTimer = undefined;
|
|
|
|
// Do not use equality, fractional pixel dimension occurs and must
|
|
|
|
// be ignored.
|
2018-06-14 14:29:38 +02:00
|
|
|
// https://www.reddit.com/r/uBlockOrigin/comments/8qodpw/how_to_hide_the_info_shown_of_what_is_currently/e0lglrr/
|
|
|
|
// Tolerance of 2px fixes the issue.
|
2018-05-04 14:44:54 +02:00
|
|
|
if (
|
2018-06-14 14:29:38 +02:00
|
|
|
Math.abs(document.body.offsetWidth - window.innerWidth) <= 2 &&
|
|
|
|
Math.abs(document.body.offsetHeight - window.innerHeight) <= 2
|
2018-05-04 14:44:54 +02:00
|
|
|
) {
|
|
|
|
return;
|
2017-09-20 05:25:08 +02:00
|
|
|
}
|
2018-05-04 14:44:54 +02:00
|
|
|
document.body.classList.add('responsive');
|
|
|
|
lpane.style.removeProperty('height');
|
|
|
|
window.removeEventListener('resize', resizeAsync);
|
|
|
|
};
|
2018-12-22 17:19:44 +01:00
|
|
|
const resizeAsync = function() {
|
2018-05-04 14:44:54 +02:00
|
|
|
if ( resizeTimer !== undefined ) {
|
|
|
|
clearTimeout(resizeTimer);
|
2017-09-20 05:25:08 +02:00
|
|
|
}
|
2018-05-04 14:44:54 +02:00
|
|
|
resizeTimer = vAPI.setTimeout(resize, 67);
|
2016-12-29 20:43:20 +01:00
|
|
|
};
|
2018-05-04 14:44:54 +02:00
|
|
|
window.addEventListener('resize', resizeAsync);
|
|
|
|
resizeAsync();
|
2016-12-29 05:39:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const renderPopupLazy = function() {
|
2018-02-27 12:54:48 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{ what: 'getPopupLazyData', tabId: popupData.tabId }
|
|
|
|
);
|
2016-08-06 18:05:01 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const onPopupMessage = function(data) {
|
2016-08-06 18:05:01 +02:00
|
|
|
if ( !data ) { return; }
|
|
|
|
if ( data.tabId !== popupData.tabId ) { return; }
|
|
|
|
|
|
|
|
switch ( data.what ) {
|
2018-09-01 00:47:02 +02:00
|
|
|
case 'domSurveyFinalReport':
|
|
|
|
let count = data.affectedElementCount || '';
|
2018-12-18 19:35:44 +01:00
|
|
|
uDom.nodeFromSelector('#no-cosmetic-filtering > span.fa-icon-badge')
|
2018-12-22 17:19:44 +01:00
|
|
|
.textContent = typeof count === 'number'
|
|
|
|
? Math.min(count, 99).toLocaleString()
|
|
|
|
: count;
|
2018-09-01 00:47:02 +02:00
|
|
|
count = data.scriptCount || '';
|
2018-12-18 19:35:44 +01:00
|
|
|
uDom.nodeFromSelector('#no-scripting > span.fa-icon-badge')
|
2018-12-22 17:19:44 +01:00
|
|
|
.textContent = typeof count === 'number'
|
|
|
|
? Math.min(count, 99).toLocaleString()
|
|
|
|
: count;
|
2016-08-06 18:05:01 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-04-05 18:03:14 +02:00
|
|
|
};
|
|
|
|
|
2016-08-06 18:05:01 +02:00
|
|
|
messaging.addChannelListener('popup', onPopupMessage);
|
|
|
|
|
2015-04-05 18:03:14 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const toggleNetFilteringSwitch = function(ev) {
|
2017-11-07 22:38:26 +01:00
|
|
|
if ( !popupData || !popupData.pageURL ) { return; }
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'toggleNetFiltering',
|
|
|
|
url: popupData.pageURL,
|
|
|
|
scope: ev.ctrlKey || ev.metaKey ? 'page' : '',
|
|
|
|
state: !uDom('body').toggleClass('off').hasClass('off'),
|
|
|
|
tabId: popupData.tabId
|
|
|
|
}
|
|
|
|
);
|
2017-11-07 23:03:24 +01:00
|
|
|
renderTooltips('#switch');
|
2015-01-10 17:23:28 +01:00
|
|
|
hashFromPopupData();
|
2014-06-24 00:42:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const gotoZap = function() {
|
2017-05-27 17:51:24 +02:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'launchElementPicker',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
zap: true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
vAPI.closePopup();
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const gotoPick = function() {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'launchElementPicker',
|
|
|
|
tabId: popupData.tabId
|
|
|
|
}
|
|
|
|
);
|
2014-12-25 14:53:30 +01:00
|
|
|
|
|
|
|
vAPI.closePopup();
|
2014-07-13 02:32:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const gotoURL = function(ev) {
|
2018-05-27 14:31:17 +02:00
|
|
|
if ( this.hasAttribute('href') === false ) { return; }
|
2014-10-20 17:40:52 +02:00
|
|
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
let url = this.getAttribute('href');
|
|
|
|
if (
|
2019-01-12 22:36:20 +01:00
|
|
|
url === 'logger-ui.html#_' &&
|
2018-05-27 14:31:17 +02:00
|
|
|
typeof popupData.tabId === 'number'
|
|
|
|
) {
|
|
|
|
url += '+' + popupData.tabId;
|
|
|
|
}
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: {
|
2018-05-27 14:31:17 +02:00
|
|
|
url: url,
|
2016-03-06 16:51:06 +01:00
|
|
|
select: true,
|
|
|
|
index: -1,
|
2016-09-16 23:41:17 +02:00
|
|
|
shiftKey: ev.shiftKey
|
2016-03-06 16:51:06 +01:00
|
|
|
}
|
2014-10-20 17:40:52 +02:00
|
|
|
}
|
2016-03-06 16:51:06 +01:00
|
|
|
);
|
2014-12-25 14:53:30 +01:00
|
|
|
|
|
|
|
vAPI.closePopup();
|
2014-07-02 18:02:29 +02:00
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const toggleFirewallPane = function() {
|
2015-01-06 14:01:15 +01:00
|
|
|
popupData.dfEnabled = !popupData.dfEnabled;
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'userSettings',
|
|
|
|
name: 'dynamicFilteringEnabled',
|
|
|
|
value: popupData.dfEnabled
|
|
|
|
}
|
|
|
|
);
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2015-04-07 03:26:05 +02:00
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/996
|
2015-03-22 13:51:31 +01: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.
|
|
|
|
dfPaneVisibleStored = popupData.dfEnabled;
|
|
|
|
vAPI.localStorage.setItem('popupFirewallPane', dfPaneVisibleStored);
|
|
|
|
|
2015-01-10 17:23:28 +01:00
|
|
|
// Dynamic filtering pane may not have been built yet
|
2015-06-10 15:23:48 +02:00
|
|
|
uDom.nodeFromId('panes').classList.toggle('dfEnabled', popupData.dfEnabled);
|
2015-01-10 17:23:28 +01:00
|
|
|
if ( popupData.dfEnabled && dfPaneBuilt === false ) {
|
2015-02-11 06:26:45 +01:00
|
|
|
buildAllFirewallRows();
|
2015-01-10 17:23:28 +01:00
|
|
|
}
|
2014-12-31 16:47:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const mouseenterCellHandler = function() {
|
2014-12-31 16:47:19 +01:00
|
|
|
if ( uDom(this).hasClass('ownRule') === false ) {
|
2015-01-06 14:01:15 +01:00
|
|
|
dfHotspots.appendTo(this);
|
2014-12-31 16:47:19 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const mouseleaveCellHandler = function() {
|
2015-01-06 14:01:15 +01:00
|
|
|
dfHotspots.detach();
|
2014-12-31 16:47:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const setFirewallRule = function(src, des, type, action, persist) {
|
2014-12-28 16:07:43 +01:00
|
|
|
// This can happen on pages where uBlock does not work
|
2018-09-03 20:06:49 +02:00
|
|
|
if (
|
|
|
|
typeof popupData.pageHostname !== 'string' ||
|
|
|
|
popupData.pageHostname === ''
|
|
|
|
) {
|
2014-12-28 16:07:43 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-09-03 20:06:49 +02:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'toggleFirewallRule',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
pageHostname: popupData.pageHostname,
|
|
|
|
srcHostname: src,
|
|
|
|
desHostname: des,
|
|
|
|
requestType: type,
|
|
|
|
action: action,
|
|
|
|
persist: persist
|
|
|
|
},
|
2018-09-03 20:06:49 +02:00
|
|
|
response => {
|
|
|
|
cachePopupData(response);
|
|
|
|
updateAllFirewallCells();
|
|
|
|
hashFromPopupData();
|
|
|
|
}
|
2016-03-06 16:51:06 +01:00
|
|
|
);
|
2014-10-06 20:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const unsetFirewallRuleHandler = function(ev) {
|
2018-12-29 12:54:05 +01:00
|
|
|
const cell = ev.target;
|
|
|
|
const row = cell.closest('[data-des]');
|
2015-02-11 06:26:45 +01:00
|
|
|
setFirewallRule(
|
2018-12-29 12:54:05 +01:00
|
|
|
cell.getAttribute('data-src') === '/' ? '*' : popupData.pageHostname,
|
|
|
|
row.getAttribute('data-des'),
|
|
|
|
row.getAttribute('data-type'),
|
2015-02-11 21:48:39 +01:00
|
|
|
0,
|
|
|
|
ev.ctrlKey || ev.metaKey
|
2014-12-31 16:47:19 +01:00
|
|
|
);
|
2015-01-06 14:01:15 +01:00
|
|
|
dfHotspots.appendTo(cell);
|
2014-12-31 16:47:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const setFirewallRuleHandler = function(ev) {
|
2018-12-29 12:54:05 +01:00
|
|
|
const hotspot = ev.target;
|
|
|
|
const cell = hotspot.closest('[data-src]');
|
|
|
|
if ( cell === null ) { return; }
|
|
|
|
const row = cell.closest('[data-des]');
|
2018-09-03 20:06:49 +02:00
|
|
|
let action = 0;
|
2018-12-29 12:54:05 +01:00
|
|
|
if ( hotspot.id === 'dynaAllow' ) {
|
2014-12-31 16:47:19 +01:00
|
|
|
action = 2;
|
2018-12-29 12:54:05 +01:00
|
|
|
} else if ( hotspot.id === 'dynaNoop' ) {
|
2015-01-10 17:44:37 +01:00
|
|
|
action = 3;
|
2014-12-31 16:47:19 +01:00
|
|
|
} else {
|
|
|
|
action = 1;
|
|
|
|
}
|
2015-02-11 06:26:45 +01:00
|
|
|
setFirewallRule(
|
2018-12-29 12:54:05 +01:00
|
|
|
cell.getAttribute('data-src') === '/' ? '*' : popupData.pageHostname,
|
|
|
|
row.getAttribute('data-des'),
|
|
|
|
row.getAttribute('data-type'),
|
2015-02-11 21:48:39 +01:00
|
|
|
action,
|
|
|
|
ev.ctrlKey || ev.metaKey
|
2014-12-31 16:47:19 +01:00
|
|
|
);
|
2015-01-06 14:01:15 +01:00
|
|
|
dfHotspots.detach();
|
2014-10-06 20:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const reloadTab = function(ev) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'reloadTab',
|
|
|
|
tabId: popupData.tabId,
|
2019-07-21 17:50:15 +02:00
|
|
|
select: vAPI.webextFlavor.soup.has('mobile'),
|
2018-01-08 13:33:38 +01:00
|
|
|
bypassCache: ev.ctrlKey || ev.metaKey || ev.shiftKey
|
2016-03-06 16:51:06 +01:00
|
|
|
}
|
|
|
|
);
|
2015-01-06 14:01:15 +01:00
|
|
|
|
2015-01-10 17:23:28 +01:00
|
|
|
// Polling will take care of refreshing the popup content
|
2015-04-07 03:26:05 +02:00
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/748
|
2019-07-21 17:50:15 +02:00
|
|
|
// User forces a reload, assume the popup has to be updated regardless
|
|
|
|
// if there were changes or not.
|
2015-02-09 21:24:24 +01:00
|
|
|
popupData.contentLastModified = -1;
|
|
|
|
|
2015-02-09 21:35:47 +01:00
|
|
|
// No need to wait to remove this.
|
2015-02-09 21:24:24 +01:00
|
|
|
uDom('body').toggleClass('dirty', false);
|
2015-01-10 17:23:28 +01:00
|
|
|
};
|
|
|
|
|
2019-07-21 17:50:15 +02: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 }
|
|
|
|
);
|
|
|
|
|
2015-01-10 17:23:28 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const toggleMinimize = function(ev) {
|
2016-02-06 15:50:02 +01:00
|
|
|
// 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 ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: {
|
2018-05-04 14:44:54 +02:00
|
|
|
url: 'popup.html?tabId=' + popupData.tabId + '&responsive=1',
|
2016-03-06 16:51:06 +01:00
|
|
|
select: true,
|
|
|
|
index: -1
|
|
|
|
}
|
2016-02-06 15:50:02 +01:00
|
|
|
}
|
2016-03-06 16:51:06 +01:00
|
|
|
);
|
2016-02-06 15:50:02 +01:00
|
|
|
vAPI.closePopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-03 20:06:49 +02:00
|
|
|
popupData.firewallPaneMinimized =
|
|
|
|
uDom.nodeFromId('firewallContainer').classList.toggle('minimized');
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'userSettings',
|
|
|
|
name: 'firewallPaneMinimized',
|
|
|
|
value: popupData.firewallPaneMinimized
|
|
|
|
}
|
|
|
|
);
|
2015-05-23 13:31:46 +02:00
|
|
|
positionRulesetTools();
|
2015-02-17 03:15:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const saveFirewallRules = function() {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'saveFirewallRules',
|
|
|
|
srcHostname: popupData.pageHostname,
|
|
|
|
desHostnames: popupData.hostnameDict
|
|
|
|
}
|
|
|
|
);
|
2015-06-10 15:23:48 +02:00
|
|
|
uDom.nodeFromId('firewallContainer').classList.remove('dirty');
|
2015-02-11 06:26:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const revertFirewallRules = function() {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'revertFirewallRules',
|
|
|
|
srcHostname: popupData.pageHostname,
|
|
|
|
desHostnames: popupData.hostnameDict,
|
|
|
|
tabId: popupData.tabId
|
|
|
|
},
|
2018-09-03 20:06:49 +02:00
|
|
|
response => {
|
|
|
|
cachePopupData(response);
|
|
|
|
updateAllFirewallCells();
|
|
|
|
updateHnSwitches();
|
|
|
|
hashFromPopupData();
|
|
|
|
}
|
2016-03-06 16:51:06 +01:00
|
|
|
);
|
2015-06-10 15:23:48 +02:00
|
|
|
uDom.nodeFromId('firewallContainer').classList.remove('dirty');
|
2015-04-24 14:36:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const toggleHostnameSwitch = function(ev) {
|
|
|
|
const target = ev.currentTarget;
|
|
|
|
const switchName = target.getAttribute('id');
|
2017-11-08 13:34:22 +01:00
|
|
|
if ( !switchName ) { return; }
|
2016-01-17 19:30:43 +01:00
|
|
|
target.classList.toggle('on');
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{
|
|
|
|
what: 'toggleHostnameSwitch',
|
|
|
|
name: switchName,
|
|
|
|
hostname: popupData.pageHostname,
|
|
|
|
state: target.classList.contains('on'),
|
2018-09-03 20:06:49 +02:00
|
|
|
tabId: popupData.tabId,
|
|
|
|
persist: popupData.dfEnabled === false || ev.ctrlKey || ev.metaKey
|
|
|
|
},
|
|
|
|
response => {
|
|
|
|
cachePopupData(response);
|
|
|
|
updateAllFirewallCells();
|
|
|
|
hashFromPopupData();
|
2016-03-06 16:51:06 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-08 13:34:22 +01:00
|
|
|
renderTooltips('#' + switchName);
|
2015-03-27 18:00:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-01-10 17:23:28 +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,
|
2014-12-25 14:53:30 +01:00
|
|
|
// and maybe even many frames within these tabs, i.e. unacceptable overhead
|
2015-01-10 17:32:24 +01:00
|
|
|
// regardless of whether the popup is opened or not.
|
2015-01-10 17:23:28 +01:00
|
|
|
//
|
|
|
|
// - 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.
|
|
|
|
//
|
2014-12-25 14:53:30 +01:00
|
|
|
// A well done polling is a better anyways IMO, I prefer that data is pulled
|
2015-01-10 17:32:24 +01:00
|
|
|
// 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.
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const pollForContentChange = (function() {
|
|
|
|
let pollTimer;
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const pollCallback = function() {
|
|
|
|
pollTimer = undefined;
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
2015-01-10 17:23:28 +01:00
|
|
|
{
|
|
|
|
what: 'hasPopupContentChanged',
|
|
|
|
tabId: popupData.tabId,
|
|
|
|
contentLastModified: popupData.contentLastModified
|
|
|
|
},
|
|
|
|
queryCallback
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const queryCallback = function(response) {
|
2015-01-10 17:23:28 +01:00
|
|
|
if ( response ) {
|
2015-03-02 19:49:34 +01:00
|
|
|
getPopupData(popupData.tabId);
|
2015-01-10 17:23:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
poll();
|
|
|
|
};
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const poll = function() {
|
|
|
|
if ( pollTimer !== undefined ) { return; }
|
2015-05-17 19:02:56 +02:00
|
|
|
pollTimer = vAPI.setTimeout(pollCallback, 1500);
|
2015-01-10 17:23:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return poll;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const getPopupData = function(tabId) {
|
|
|
|
const onDataReceived = function(response) {
|
2015-01-10 17:23:28 +01:00
|
|
|
cachePopupData(response);
|
2016-12-29 05:39:15 +01:00
|
|
|
renderOnce();
|
2015-01-06 14:01:15 +01:00
|
|
|
renderPopup();
|
2015-04-05 18:03:14 +02:00
|
|
|
renderPopupLazy(); // low priority rendering
|
2015-01-10 17:23:28 +01:00
|
|
|
hashFromPopupData(true);
|
|
|
|
pollForContentChange();
|
|
|
|
};
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'popupPanel',
|
|
|
|
{ what: 'getPopupData', tabId: tabId },
|
|
|
|
onDataReceived
|
|
|
|
);
|
2015-01-10 17:23:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const onShowTooltip = function(ev) {
|
|
|
|
if ( popupData.tooltipsDisabled ) { return; }
|
2015-04-05 20:44:41 +02:00
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const target = ev.target;
|
2015-04-05 20:44:41 +02:00
|
|
|
|
2015-12-13 06:56:30 +01:00
|
|
|
// Tooltip container
|
2018-12-22 17:19:44 +01:00
|
|
|
const ttc = uDom(target).ancestors('.tooltipContainer').nodeAt(0) ||
|
|
|
|
document.body;
|
|
|
|
const ttcRect = ttc.getBoundingClientRect();
|
2015-12-13 06:56:30 +01:00
|
|
|
|
|
|
|
// Tooltip itself
|
2018-12-22 17:19:44 +01:00
|
|
|
const tip = uDom.nodeFromId('tooltip');
|
2015-04-05 20:44:41 +02:00
|
|
|
tip.textContent = target.getAttribute('data-tip');
|
|
|
|
tip.style.removeProperty('top');
|
|
|
|
tip.style.removeProperty('bottom');
|
2015-12-13 06:56:30 +01:00
|
|
|
ttc.appendChild(tip);
|
|
|
|
|
|
|
|
// Target rect
|
2018-12-22 17:19:44 +01:00
|
|
|
const targetRect = target.getBoundingClientRect();
|
2015-04-05 20:44:41 +02:00
|
|
|
|
|
|
|
// Default is "over"
|
2018-12-22 17:19:44 +01:00
|
|
|
let pos;
|
|
|
|
if ( target.getAttribute('data-tip-position') !== 'under' ) {
|
2015-12-13 06:56:30 +01:00
|
|
|
pos = ttcRect.height - targetRect.top + ttcRect.top;
|
2015-04-05 20:44:41 +02:00
|
|
|
tip.style.setProperty('bottom', pos + 'px');
|
|
|
|
} else {
|
2015-12-13 06:56:30 +01:00
|
|
|
pos = targetRect.bottom - ttcRect.top;
|
2015-04-05 20:44:41 +02:00
|
|
|
tip.style.setProperty('top', pos + 'px');
|
|
|
|
}
|
|
|
|
|
2015-12-13 06:56:30 +01:00
|
|
|
tip.classList.add('show');
|
2015-04-05 20:44:41 +02:00
|
|
|
};
|
|
|
|
|
2018-12-22 17:19:44 +01:00
|
|
|
const onHideTooltip = function() {
|
2015-06-10 15:23:48 +02:00
|
|
|
uDom.nodeFromId('tooltip').classList.remove('show');
|
2015-04-05 20:44:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-08-01 17:30:54 +02:00
|
|
|
// Popup DOM is assumed to be loaded at this point -- because this script
|
|
|
|
// is loaded after everything else..
|
2015-01-10 17:23:28 +01:00
|
|
|
|
2019-07-21 17:50:15 +02:00
|
|
|
(( ) => {
|
2015-08-01 17:34:31 +02:00
|
|
|
// If there's no tab id specified in the query string,
|
|
|
|
// it will default to current tab.
|
2018-05-04 14:44:54 +02:00
|
|
|
let tabId = null;
|
2015-08-01 17:34:31 +02:00
|
|
|
|
|
|
|
// Extract the tab id of the page this popup is for
|
2018-12-22 17:19:44 +01:00
|
|
|
const matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
|
2015-08-01 17:34:31 +02:00
|
|
|
if ( matches && matches.length === 2 ) {
|
2018-02-27 12:54:48 +01:00
|
|
|
tabId = parseInt(matches[1], 10) || 0;
|
2015-08-01 17:34:31 +02:00
|
|
|
}
|
|
|
|
getPopupData(tabId);
|
2018-05-04 14:44:54 +02:00
|
|
|
})();
|
2015-08-01 17:34:31 +02:00
|
|
|
|
2018-05-04 14:44:54 +02:00
|
|
|
uDom('#switch').on('click', toggleNetFilteringSwitch);
|
|
|
|
uDom('#gotoZap').on('click', gotoZap);
|
|
|
|
uDom('#gotoPick').on('click', gotoPick);
|
|
|
|
uDom('h2').on('click', toggleFirewallPane);
|
|
|
|
uDom('.hnSwitch').on('click', toggleHostnameSwitch);
|
|
|
|
uDom('#saveRules').on('click', saveFirewallRules);
|
|
|
|
uDom('#revertRules').on('click', revertFirewallRules);
|
|
|
|
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize);
|
2015-08-01 17:34:31 +02:00
|
|
|
|
2018-05-04 14:44:54 +02:00
|
|
|
uDom('body').on('mouseenter', '[data-tip]', onShowTooltip)
|
|
|
|
.on('mouseleave', '[data-tip]', onHideTooltip);
|
2017-07-03 15:51:34 +02:00
|
|
|
|
2018-05-04 14:44:54 +02:00
|
|
|
uDom('a[href]').on('click', gotoURL);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|