2015-05-09 00:28:01 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2018-07-22 14:14:02 +02:00
|
|
|
Copyright (C) 2015-present Raymond Hill
|
2015-05-09 00:28:01 +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/}.
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
Home: https://github.com/gorhill/uBlock
|
2015-05-09 00:28:01 +02:00
|
|
|
*/
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
/* global uDom */
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const messaging = vAPI.messaging;
|
2018-12-14 17:01:21 +01:00
|
|
|
const logger = self.logger = { ownerId: Date.now() };
|
|
|
|
let popupLoggerBox;
|
2018-12-17 19:54:17 +01:00
|
|
|
let popupLoggerTooltips;
|
2018-12-13 18:30:54 +01:00
|
|
|
let activeTabId;
|
2018-12-17 19:54:17 +01:00
|
|
|
let netInspectorPaused = false;
|
2015-06-28 23:42:08 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const removeAllChildren = logger.removeAllChildren = function(node) {
|
2015-06-28 23:42:08 +02:00
|
|
|
while ( node.firstChild ) {
|
|
|
|
node.removeChild(node.firstChild);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const tabIdFromClassName = function(className) {
|
|
|
|
const matches = className.match(/\btab_([^ ]+)\b/);
|
2018-02-26 22:52:16 +01:00
|
|
|
if ( matches === null ) { return 0; }
|
|
|
|
if ( matches[1] === 'bts' ) { return -1; }
|
|
|
|
return parseInt(matches[1], 10);
|
2018-01-09 14:08:17 +01:00
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const tabIdFromPageSelector = logger.tabIdFromPageSelector = function() {
|
|
|
|
const tabClass = uDom.nodeFromId('pageSelector').value;
|
2018-01-10 17:50:08 +01:00
|
|
|
if ( tabClass === 'tab_active' && activeTabId !== undefined ) {
|
|
|
|
return activeTabId;
|
|
|
|
}
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( tabClass === 'tab_bts' ) { return -1; }
|
2018-02-26 19:59:16 +01:00
|
|
|
return /^tab_\d+$/.test(tabClass) ? parseInt(tabClass.slice(4), 10) : 0;
|
2015-06-28 23:42:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
const tbody = document.querySelector('#netInspector tbody');
|
|
|
|
const trJunkyard = [];
|
|
|
|
const tdJunkyard = [];
|
|
|
|
const firstVarDataCol = 1;
|
|
|
|
const lastVarDataIndex = 6;
|
|
|
|
const reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
|
|
|
|
const netFilteringDialog = uDom.nodeFromId('netFilteringDialog');
|
2015-05-16 16:15:02 +02:00
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
const prettyRequestTypes = {
|
2015-05-09 00:28:01 +02:00
|
|
|
'main_frame': 'doc',
|
|
|
|
'stylesheet': 'css',
|
|
|
|
'sub_frame': 'frame',
|
|
|
|
'xmlhttprequest': 'xhr'
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
const uglyRequestTypes = {
|
2015-05-21 20:15:17 +02:00
|
|
|
'doc': 'main_frame',
|
|
|
|
'css': 'stylesheet',
|
|
|
|
'frame': 'sub_frame',
|
|
|
|
'xhr': 'xmlhttprequest'
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
const staticFilterTypes = {
|
2017-05-12 16:35:11 +02:00
|
|
|
'beacon': 'other',
|
2016-03-07 01:16:46 +01:00
|
|
|
'doc': 'document',
|
2015-06-18 23:23:52 +02:00
|
|
|
'css': 'stylesheet',
|
|
|
|
'frame': 'subdocument',
|
2017-05-12 16:35:11 +02:00
|
|
|
'ping': 'other',
|
2017-11-02 16:12:17 +01:00
|
|
|
'object_subrequest': 'object',
|
2015-06-18 23:23:52 +02:00
|
|
|
'xhr': 'xmlhttprequest'
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
let maxEntries = 5000;
|
|
|
|
let allTabIds = new Map();
|
|
|
|
let allTabIdsToken;
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
var classNameFromTabId = function(tabId) {
|
2018-02-26 19:59:16 +01:00
|
|
|
if ( tabId < 0 ) {
|
2015-05-16 16:15:02 +02:00
|
|
|
return 'tab_bts';
|
|
|
|
}
|
2018-02-27 12:54:48 +01:00
|
|
|
if ( tabId !== 0 ) {
|
2015-05-16 16:15:02 +02:00
|
|
|
return 'tab_' + tabId;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
2015-06-26 06:08:41 +02:00
|
|
|
/******************************************************************************/
|
2015-05-25 00:50:09 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-06-09 16:27:08 +02:00
|
|
|
var regexFromURLFilteringResult = function(result) {
|
2015-05-21 20:15:17 +02:00
|
|
|
var beg = result.indexOf(' ');
|
|
|
|
var end = result.indexOf(' ', beg + 1);
|
|
|
|
var url = result.slice(beg + 1, end);
|
|
|
|
if ( url === '*' ) {
|
2015-06-09 16:27:08 +02:00
|
|
|
return new RegExp('^.*$', 'gi');
|
2015-05-21 20:15:17 +02:00
|
|
|
}
|
2015-06-09 16:27:08 +02:00
|
|
|
return new RegExp('^' + url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
|
2015-05-21 20:15:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
// Emphasize hostname in URL, as this is what matters in uMatrix's rules.
|
|
|
|
|
2015-06-09 16:27:08 +02:00
|
|
|
var nodeFromURL = function(url, re) {
|
|
|
|
if ( re instanceof RegExp === false ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
return document.createTextNode(url);
|
|
|
|
}
|
|
|
|
var matches = re.exec(url);
|
|
|
|
if ( matches === null || matches[0].length === 0 ) {
|
|
|
|
return document.createTextNode(url);
|
|
|
|
}
|
|
|
|
var node = renderedURLTemplate.cloneNode(true);
|
|
|
|
node.childNodes[0].textContent = url.slice(0, matches.index);
|
|
|
|
node.childNodes[1].textContent = url.slice(matches.index, re.lastIndex);
|
|
|
|
node.childNodes[2].textContent = url.slice(re.lastIndex);
|
|
|
|
return node;
|
|
|
|
};
|
|
|
|
|
|
|
|
var renderedURLTemplate = document.querySelector('#renderedURLTemplate > span');
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const createCellAt = function(tr, index) {
|
|
|
|
let td = tr.cells[index];
|
|
|
|
const mustAppend = !td;
|
2015-05-09 00:28:01 +02:00
|
|
|
if ( mustAppend ) {
|
|
|
|
td = tdJunkyard.pop();
|
|
|
|
}
|
|
|
|
if ( td ) {
|
|
|
|
td.removeAttribute('colspan');
|
2018-12-15 18:23:13 +01:00
|
|
|
td.removeAttribute('data-parties');
|
2015-05-09 00:28:01 +02:00
|
|
|
td.textContent = '';
|
|
|
|
} else {
|
|
|
|
td = document.createElement('td');
|
|
|
|
}
|
|
|
|
if ( mustAppend ) {
|
|
|
|
tr.appendChild(td);
|
|
|
|
}
|
|
|
|
return td;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var createRow = function(layout) {
|
2018-12-13 18:30:54 +01:00
|
|
|
let tr = trJunkyard.pop();
|
2015-05-09 00:28:01 +02:00
|
|
|
if ( tr ) {
|
|
|
|
tr.className = '';
|
2018-12-13 18:30:54 +01:00
|
|
|
tr.removeAttribute('data-tabhn');
|
|
|
|
tr.removeAttribute('data-dochn');
|
2015-06-11 18:12:23 +02:00
|
|
|
tr.removeAttribute('data-filter');
|
2018-12-13 18:30:54 +01:00
|
|
|
tr.removeAttribute('data-tabid');
|
2015-05-09 00:28:01 +02:00
|
|
|
} else {
|
|
|
|
tr = document.createElement('tr');
|
|
|
|
}
|
2018-12-13 18:30:54 +01:00
|
|
|
let index = 0;
|
|
|
|
for ( ; index < firstVarDataCol; index++ ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
createCellAt(tr, index);
|
|
|
|
}
|
2018-12-13 18:30:54 +01:00
|
|
|
let i = 1, span = 1, td;
|
2015-05-09 00:28:01 +02:00
|
|
|
for (;;) {
|
|
|
|
td = createCellAt(tr, index);
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( i === lastVarDataIndex ) { break; }
|
2015-05-09 00:28:01 +02:00
|
|
|
if ( layout.charAt(i) !== '1' ) {
|
|
|
|
span += 1;
|
|
|
|
} else {
|
|
|
|
if ( span !== 1 ) {
|
|
|
|
td.setAttribute('colspan', span);
|
|
|
|
}
|
|
|
|
index += 1;
|
|
|
|
span = 1;
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
if ( span !== 1 ) {
|
|
|
|
td.setAttribute('colspan', span);
|
|
|
|
}
|
|
|
|
index += 1;
|
2015-08-18 17:44:24 +02:00
|
|
|
while ( (td = tr.cells[index]) ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
tdJunkyard.push(tr.removeChild(td));
|
|
|
|
}
|
|
|
|
return tr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2016-12-02 18:15:54 +01:00
|
|
|
var padTo2 = function(v) {
|
|
|
|
return v < 10 ? '0' + v : v;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const createGap = function(tabId, url) {
|
|
|
|
const tr = createRow('1');
|
|
|
|
tr.setAttribute('data-tabid', tabId);
|
2015-06-17 22:45:24 +02:00
|
|
|
tr.classList.add('tab_' + tabId);
|
|
|
|
tr.classList.add('maindoc');
|
2015-05-09 00:28:01 +02:00
|
|
|
tr.cells[firstVarDataCol].textContent = url;
|
|
|
|
tbody.insertBefore(tr, tbody.firstChild);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
var renderNetLogEntry = function(tr, details) {
|
|
|
|
const trcl = tr.classList;
|
|
|
|
const type = details.type;
|
|
|
|
const url = details.url;
|
|
|
|
let td;
|
2015-05-09 00:28:01 +02:00
|
|
|
|
|
|
|
// If the request is that of a root frame, insert a gap in the table
|
|
|
|
// in order to visually separate entries for different documents.
|
|
|
|
if ( type === 'main_frame' ) {
|
2018-12-13 18:30:54 +01:00
|
|
|
createGap(details.tabId, url);
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
tr.classList.add('cat_' + details.realm);
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
let filter = details.filter || undefined;
|
|
|
|
let filteringType;
|
|
|
|
if ( filter !== undefined ) {
|
|
|
|
if ( typeof filter.source === 'string' ) {
|
|
|
|
filteringType = filter.source;
|
|
|
|
trcl.add(filteringType);
|
|
|
|
}
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:35:11 +02:00
|
|
|
if ( filter !== undefined ) {
|
2018-12-16 21:26:38 +01:00
|
|
|
td = tr.cells[1];
|
2017-05-12 16:35:11 +02:00
|
|
|
if ( filteringType === 'static' ) {
|
|
|
|
td.textContent = filter.raw;
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add('canLookup');
|
2017-05-12 16:35:11 +02:00
|
|
|
tr.setAttribute('data-filter', filter.compiled);
|
|
|
|
} else if ( filteringType === 'cosmetic' ) {
|
|
|
|
td.textContent = filter.raw;
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add('canLookup');
|
2015-06-09 16:27:08 +02:00
|
|
|
} else {
|
2017-05-12 16:35:11 +02:00
|
|
|
td.textContent = filter.raw;
|
2015-06-09 16:27:08 +02:00
|
|
|
}
|
2015-05-25 00:50:09 +02:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:35:11 +02:00
|
|
|
if ( filter !== undefined ) {
|
2018-12-16 21:26:38 +01:00
|
|
|
td = tr.cells[2];
|
2017-05-12 16:35:11 +02:00
|
|
|
if ( filter.result === 1 ) {
|
|
|
|
trcl.add('blocked');
|
|
|
|
td.textContent = '--';
|
|
|
|
} else if ( filter.result === 2 ) {
|
|
|
|
trcl.add('allowed');
|
|
|
|
td.textContent = '++';
|
|
|
|
} else if ( filter.result === 3 ) {
|
|
|
|
trcl.add('nooped');
|
|
|
|
td.textContent = '**';
|
2018-12-13 18:30:54 +01:00
|
|
|
} else if ( filteringType === 'redirect' ) {
|
2017-05-12 16:35:11 +02:00
|
|
|
trcl.add('redirect');
|
|
|
|
td.textContent = '<<';
|
|
|
|
}
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( details.tabHostname ) {
|
|
|
|
tr.setAttribute('data-tabhn', details.tabHostname);
|
|
|
|
}
|
|
|
|
if ( details.docHostname ) {
|
|
|
|
tr.setAttribute('data-dochn', details.docHostname);
|
|
|
|
tr.cells[3].textContent = details.docHostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Partyness
|
|
|
|
if ( details.realm === 'net' && details.domain !== undefined ) {
|
|
|
|
td = tr.cells[4];
|
|
|
|
let text = '';
|
|
|
|
if ( details.tabDomain !== undefined ) {
|
|
|
|
text += details.domain === details.tabDomain ? '1' : '3';
|
|
|
|
} else {
|
|
|
|
text += '?';
|
|
|
|
}
|
|
|
|
if ( details.docDomain !== details.tabDomain ) {
|
|
|
|
text += ',';
|
|
|
|
if ( details.docDomain !== undefined ) {
|
|
|
|
text += details.domain === details.docDomain ? '1' : '3';
|
|
|
|
} else {
|
|
|
|
text += '?';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
td.textContent = text;
|
2018-12-15 18:23:13 +01:00
|
|
|
let indent = '\t';
|
|
|
|
text = details.tabDomain;
|
|
|
|
if ( details.docDomain !== details.tabDomain ) {
|
|
|
|
text += ` \u21d2\n\t${details.docDomain}`;
|
|
|
|
indent = '\t\t';
|
2018-12-13 18:30:54 +01:00
|
|
|
}
|
2018-12-15 18:23:13 +01:00
|
|
|
text += ` \u21d2\n${indent}${details.domain}`;
|
|
|
|
td.setAttribute('data-parties', text);
|
2018-12-13 18:30:54 +01:00
|
|
|
}
|
2015-06-09 16:27:08 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
tr.cells[5].textContent = (prettyRequestTypes[type] || type);
|
|
|
|
|
|
|
|
let re = null;
|
2017-05-12 16:35:11 +02:00
|
|
|
if ( filteringType === 'static' ) {
|
|
|
|
re = new RegExp(filter.regex, 'gi');
|
|
|
|
} else if ( filteringType === 'dynamicUrl' ) {
|
|
|
|
re = regexFromURLFilteringResult(filter.rule.join(' '));
|
2015-06-09 16:27:08 +02:00
|
|
|
}
|
2018-12-13 18:30:54 +01:00
|
|
|
tr.cells[6].appendChild(nodeFromURL(url, re));
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
var renderLogEntry = function(details) {
|
|
|
|
const fvdc = firstVarDataCol;
|
|
|
|
let tr;
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( details.error !== undefined ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
tr = createRow('1');
|
2018-12-13 18:30:54 +01:00
|
|
|
tr.cells[fvdc].textContent = details.error;
|
|
|
|
} else if ( details.url !== undefined ) {
|
|
|
|
tr = createRow('111111');
|
|
|
|
renderNetLogEntry(tr, details);
|
|
|
|
} else {
|
2015-05-09 00:28:01 +02:00
|
|
|
tr = createRow('1');
|
2018-12-13 18:30:54 +01:00
|
|
|
tr.cells[fvdc].textContent = '???';
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fields common to all rows.
|
2018-12-13 18:30:54 +01:00
|
|
|
const time = logDate;
|
|
|
|
time.setTime(details.tstamp - logDateTimezoneOffset);
|
2016-12-03 15:21:31 +01:00
|
|
|
tr.cells[0].textContent = padTo2(time.getUTCHours()) + ':' +
|
2017-01-12 14:45:46 +01:00
|
|
|
padTo2(time.getUTCMinutes()) + ':' +
|
2016-12-02 18:15:54 +01:00
|
|
|
padTo2(time.getSeconds());
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( details.tabId ) {
|
|
|
|
tr.setAttribute('data-tabid', details.tabId);
|
|
|
|
tr.classList.add(classNameFromTabId(details.tabId));
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rowFilterer.filterOne(tr, true);
|
|
|
|
tbody.insertBefore(tr, tbody.firstChild);
|
2016-05-07 17:45:26 +02:00
|
|
|
return tr;
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
2016-12-03 15:21:31 +01:00
|
|
|
// Reuse date objects.
|
2018-12-13 18:30:54 +01:00
|
|
|
const logDate = new Date();
|
|
|
|
const logDateTimezoneOffset = logDate.getTimezoneOffset() * 60000;
|
2016-12-03 15:21:31 +01:00
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const renderLogEntries = function(response) {
|
2015-05-09 00:28:01 +02:00
|
|
|
document.body.classList.toggle('colorBlind', response.colorBlind);
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const entries = response.entries;
|
2018-05-27 14:31:17 +02:00
|
|
|
if ( entries.length === 0 ) { return; }
|
2015-05-09 00:28:01 +02:00
|
|
|
|
|
|
|
// Preserve scroll position
|
2018-12-13 18:30:54 +01:00
|
|
|
const height = tbody.offsetHeight;
|
2018-05-27 14:31:17 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const tabIds = allTabIds;
|
|
|
|
for ( const entry of entries ) {
|
|
|
|
const details = JSON.parse(entry.details);
|
|
|
|
const tr = renderLogEntry(details);
|
2016-05-07 17:45:26 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/1613#issuecomment-217637122
|
|
|
|
// Unlikely, but it may happen: mark as void if associated tab no
|
|
|
|
// longer exist.
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( details.tabId && tabIds.has(details.tabId) === false ) {
|
|
|
|
tr.classList.add('void');
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent logger from growing infinitely and eating all memory. For
|
|
|
|
// instance someone could forget that it is left opened for some
|
|
|
|
// dynamically refreshed pages.
|
|
|
|
truncateLog(maxEntries);
|
|
|
|
|
2015-06-26 06:08:41 +02:00
|
|
|
// Follow waterfall if not observing top of waterfall.
|
2018-12-13 18:30:54 +01:00
|
|
|
const yDelta = tbody.offsetHeight - height;
|
2018-05-27 14:31:17 +02:00
|
|
|
if ( yDelta === 0 ) { return; }
|
2018-12-13 18:30:54 +01:00
|
|
|
const container = uDom.nodeFromSelector('#netInspector .vscrollable');
|
2015-06-26 06:08:41 +02:00
|
|
|
if ( container.scrollTop !== 0 ) {
|
|
|
|
container.scrollTop += yDelta;
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
let updateCurrentTabTitle = (function() {
|
|
|
|
let i18nCurrentTab = vAPI.i18n('loggerCurrentTab');
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
let select = uDom.nodeFromId('pageSelector');
|
|
|
|
if ( select.value !== 'tab_active' ) { return; }
|
|
|
|
let opt0 = select.querySelector('[value="tab_active"]');
|
|
|
|
let opt1 = select.querySelector('[value="tab_' + activeTabId + '"]');
|
|
|
|
let text = i18nCurrentTab;
|
|
|
|
if ( opt1 !== null ) {
|
|
|
|
text += ' / ' + opt1.textContent;
|
|
|
|
}
|
|
|
|
opt0.textContent = text;
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const synchronizeTabIds = function(newTabIds) {
|
|
|
|
const select = uDom.nodeFromId('pageSelector');
|
|
|
|
const selectValue = select.value;
|
|
|
|
const oldTabIds = allTabIds;
|
|
|
|
const autoDeleteVoidRows = selectValue === 'tab_active';
|
|
|
|
let rowVoided = false;
|
|
|
|
for ( const tabId of oldTabIds.keys() ) {
|
2018-02-26 19:59:16 +01:00
|
|
|
if ( newTabIds.has(tabId) ) { continue; }
|
2015-05-16 16:15:02 +02:00
|
|
|
// Mark or remove voided rows
|
2018-12-13 18:30:54 +01:00
|
|
|
const trs = uDom('.tab_' + tabId);
|
2015-05-16 16:15:02 +02:00
|
|
|
if ( autoDeleteVoidRows ) {
|
|
|
|
toJunkyard(trs);
|
|
|
|
} else {
|
2018-12-13 18:30:54 +01:00
|
|
|
trs.addClass('void');
|
2015-05-16 16:15:02 +02:00
|
|
|
rowVoided = true;
|
|
|
|
}
|
|
|
|
// Remove popup if it is currently bound to a removed tab.
|
|
|
|
if ( tabId === popupManager.tabId ) {
|
|
|
|
popupManager.toggleOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const tabIds = Array.from(newTabIds.keys()).sort(function(a, b) {
|
2018-02-26 19:59:16 +01:00
|
|
|
return newTabIds.get(a).localeCompare(newTabIds.get(b));
|
2015-05-16 16:15:02 +02:00
|
|
|
});
|
2018-12-13 18:30:54 +01:00
|
|
|
let j = 3;
|
|
|
|
for ( let i = 0; i < tabIds.length; i++ ) {
|
|
|
|
const tabId = tabIds[i];
|
2018-02-26 19:59:16 +01:00
|
|
|
if ( tabId < 0 ) { continue; }
|
2018-12-13 18:30:54 +01:00
|
|
|
let option = select.options[j];
|
2015-05-16 16:15:02 +02:00
|
|
|
if ( !option ) {
|
|
|
|
option = document.createElement('option');
|
|
|
|
select.appendChild(option);
|
|
|
|
}
|
2015-10-24 15:24:27 +02:00
|
|
|
// Truncate too long labels.
|
2018-02-26 19:59:16 +01:00
|
|
|
option.textContent = newTabIds.get(tabId).slice(0, 80);
|
2015-05-16 16:15:02 +02:00
|
|
|
option.value = classNameFromTabId(tabId);
|
|
|
|
if ( option.value === selectValue ) {
|
2015-07-02 01:50:43 +02:00
|
|
|
select.selectedIndex = j;
|
2015-05-16 16:15:02 +02:00
|
|
|
option.setAttribute('selected', '');
|
|
|
|
} else {
|
|
|
|
option.removeAttribute('selected');
|
|
|
|
}
|
2015-07-02 01:50:43 +02:00
|
|
|
j += 1;
|
2015-05-16 16:15:02 +02:00
|
|
|
}
|
|
|
|
while ( j < select.options.length ) {
|
|
|
|
select.removeChild(select.options[j]);
|
|
|
|
}
|
|
|
|
if ( select.value !== selectValue ) {
|
|
|
|
select.selectedIndex = 0;
|
|
|
|
select.value = '';
|
|
|
|
select.options[0].setAttribute('selected', '');
|
|
|
|
pageSelectorChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
allTabIds = newTabIds;
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
updateCurrentTabTitle();
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
return rowVoided;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var truncateLog = function(size) {
|
|
|
|
if ( size === 0 ) {
|
|
|
|
size = 5000;
|
|
|
|
}
|
2015-07-01 15:19:13 +02:00
|
|
|
var tbody = document.querySelector('#netInspector tbody');
|
2015-05-09 00:28:01 +02:00
|
|
|
size = Math.min(size, 10000);
|
|
|
|
var tr;
|
|
|
|
while ( tbody.childElementCount > size ) {
|
|
|
|
tr = tbody.lastElementChild;
|
|
|
|
trJunkyard.push(tbody.removeChild(tr));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const onLogBufferRead = function(response) {
|
2018-01-08 20:29:39 +01:00
|
|
|
if ( !response || response.unavailable ) {
|
|
|
|
readLogBufferAsync();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
// Disable tooltips?
|
|
|
|
if (
|
|
|
|
popupLoggerTooltips === undefined &&
|
|
|
|
response.tooltips !== undefined
|
|
|
|
) {
|
|
|
|
popupLoggerTooltips = response.tooltips;
|
|
|
|
if ( popupLoggerTooltips === false ) {
|
|
|
|
uDom('[data-i18n-title]').attr('title', '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 14:08:17 +01:00
|
|
|
// Tab id of currently active tab
|
2018-05-27 14:31:17 +02:00
|
|
|
let activeTabIdChanged = false;
|
2018-01-09 14:08:17 +01:00
|
|
|
if ( response.activeTabId ) {
|
2018-05-27 14:31:17 +02:00
|
|
|
activeTabIdChanged = response.activeTabId !== activeTabId;
|
2018-01-09 14:08:17 +01:00
|
|
|
activeTabId = response.activeTabId;
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
// This may have changed meanwhile
|
|
|
|
if ( response.maxEntries !== maxEntries ) {
|
|
|
|
maxEntries = response.maxEntries;
|
|
|
|
uDom('#maxEntries').val(maxEntries || '');
|
|
|
|
}
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
if ( Array.isArray(response.tabIds) ) {
|
|
|
|
response.tabIds = new Map(response.tabIds);
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
// Neuter rows for which a tab does not exist anymore
|
2018-05-27 14:31:17 +02:00
|
|
|
let rowVoided = false;
|
|
|
|
if ( response.tabIds !== undefined ) {
|
2015-05-18 14:12:35 +02:00
|
|
|
rowVoided = synchronizeTabIds(response.tabIds);
|
|
|
|
allTabIdsToken = response.tabIdsToken;
|
|
|
|
}
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
if ( activeTabIdChanged ) {
|
|
|
|
pageSelectorFromURLHash();
|
|
|
|
}
|
2015-08-01 17:30:54 +02:00
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
if ( netInspectorPaused === false ) {
|
|
|
|
renderLogEntries(response);
|
|
|
|
}
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2015-05-10 18:25:26 +02:00
|
|
|
if ( rowVoided ) {
|
|
|
|
uDom('#clean').toggleClass(
|
|
|
|
'disabled',
|
2018-12-13 18:30:54 +01:00
|
|
|
tbody.querySelector('#netInspector tr[data-tabid].void') === null
|
2015-05-10 18:25:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
// Synchronize toolbar with content of log
|
|
|
|
uDom('#clear').toggleClass(
|
|
|
|
'disabled',
|
|
|
|
tbody.querySelector('tr') === null
|
|
|
|
);
|
|
|
|
|
2018-01-08 20:29:39 +01:00
|
|
|
readLogBufferAsync();
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// This can be called only once, at init time. After that, this will be called
|
|
|
|
// automatically. If called after init time, this will be messy, and this would
|
|
|
|
// require a bit more code to ensure no multi time out events.
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const readLogBuffer = function() {
|
2018-01-09 14:08:17 +01:00
|
|
|
if ( logger.ownerId === undefined ) { return; }
|
2018-12-14 17:01:21 +01:00
|
|
|
const msg = {
|
|
|
|
what: 'readAll',
|
|
|
|
ownerId: logger.ownerId,
|
|
|
|
tabIdsToken: allTabIdsToken,
|
|
|
|
};
|
|
|
|
if (
|
|
|
|
popupLoggerBox instanceof Object &&
|
|
|
|
(
|
|
|
|
self.screenX !== popupLoggerBox.x ||
|
|
|
|
self.screenY !== popupLoggerBox.y ||
|
|
|
|
self.outerWidth !== popupLoggerBox.w ||
|
|
|
|
self.outerHeight !== popupLoggerBox.h
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
popupLoggerBox.x = self.screenX;
|
|
|
|
popupLoggerBox.y = self.screenY;
|
|
|
|
popupLoggerBox.w = self.outerWidth;
|
|
|
|
popupLoggerBox.h = self.outerHeight;
|
|
|
|
msg.popupLoggerBoxChanged = true;
|
|
|
|
}
|
|
|
|
vAPI.messaging.send('loggerUI', msg, onLogBufferRead);
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const readLogBufferAsync = function() {
|
2018-01-09 14:08:17 +01:00
|
|
|
if ( logger.ownerId === undefined ) { return; }
|
2018-01-08 20:29:39 +01:00
|
|
|
vAPI.setTimeout(readLogBuffer, 1200);
|
|
|
|
};
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
let pageSelectorChanged = function() {
|
|
|
|
let select = uDom.nodeFromId('pageSelector');
|
2018-01-09 14:08:17 +01:00
|
|
|
window.location.replace('#' + select.value);
|
2015-08-01 17:30:54 +02:00
|
|
|
pageSelectorFromURLHash();
|
2015-05-16 16:15:02 +02:00
|
|
|
};
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
let pageSelectorFromURLHash = (function() {
|
|
|
|
let lastTabClass = '';
|
|
|
|
let lastEffectiveTabClass = '';
|
|
|
|
let reActiveTabId = /^(tab_[^+]+)\+(.+)$/;
|
2015-08-01 17:30:54 +02:00
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
let selectRows = function(tabClass) {
|
|
|
|
let effectiveTabClass = tabClass;
|
2018-01-09 14:08:17 +01:00
|
|
|
if ( tabClass === 'tab_active' ) {
|
|
|
|
if ( activeTabId === undefined ) { return; }
|
2018-05-27 14:31:17 +02:00
|
|
|
effectiveTabClass = 'tab_' + activeTabId;
|
2018-01-09 14:08:17 +01:00
|
|
|
}
|
2018-05-27 14:31:17 +02:00
|
|
|
if ( effectiveTabClass === lastEffectiveTabClass ) { return; }
|
|
|
|
lastEffectiveTabClass = effectiveTabClass;
|
2018-01-09 14:08:17 +01:00
|
|
|
|
|
|
|
document.dispatchEvent(new Event('tabIdChanged'));
|
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
let style = uDom.nodeFromId('tabFilterer');
|
|
|
|
let sheet = style.sheet;
|
2018-01-09 14:08:17 +01:00
|
|
|
while ( sheet.cssRules.length !== 0 ) {
|
|
|
|
sheet.deleteRule(0);
|
2015-08-01 17:30:54 +02:00
|
|
|
}
|
2018-05-27 14:31:17 +02:00
|
|
|
if ( effectiveTabClass === '' ) { return; }
|
2018-01-09 14:08:17 +01:00
|
|
|
sheet.insertRule(
|
2018-05-27 14:31:17 +02:00
|
|
|
'#netInspector tr:not(.' + effectiveTabClass + '):not(.tab_bts) ' +
|
2018-03-17 18:35:36 +01:00
|
|
|
'{display:none;}',
|
|
|
|
0
|
2018-01-09 14:08:17 +01:00
|
|
|
);
|
2018-05-27 14:31:17 +02:00
|
|
|
|
|
|
|
updateCurrentTabTitle();
|
2018-01-09 14:08:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return function() {
|
2018-05-27 14:31:17 +02:00
|
|
|
let tabClass = window.location.hash.slice(1);
|
|
|
|
let match = reActiveTabId.exec(tabClass);
|
|
|
|
if ( match !== null ) {
|
|
|
|
tabClass = match[1];
|
|
|
|
activeTabId = parseInt(match[2], 10) || undefined;
|
|
|
|
window.location.hash = '#' + match[1];
|
|
|
|
}
|
2018-01-09 14:08:17 +01:00
|
|
|
selectRows(tabClass);
|
|
|
|
if ( tabClass === lastTabClass ) { return; }
|
|
|
|
lastTabClass = tabClass;
|
2015-08-01 17:30:54 +02:00
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
let select = uDom.nodeFromId('pageSelector');
|
|
|
|
let option = select.querySelector('option[value="' + tabClass + '"]');
|
2015-08-01 17:30:54 +02:00
|
|
|
if ( option === null ) {
|
2018-01-09 14:08:17 +01:00
|
|
|
window.location.hash = '';
|
2015-08-01 17:30:54 +02:00
|
|
|
tabClass = '';
|
|
|
|
option = select.options[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
select.selectedIndex = option.index;
|
|
|
|
select.value = option.value;
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
uDom('.needdom').toggleClass(
|
2015-08-01 17:30:54 +02:00
|
|
|
'disabled',
|
|
|
|
tabClass === '' || tabClass === 'tab_bts'
|
|
|
|
);
|
2018-12-13 18:30:54 +01:00
|
|
|
uDom('.needscope').toggleClass(
|
|
|
|
'disabled',
|
|
|
|
tabClass === ''
|
|
|
|
);
|
2015-08-01 17:30:54 +02:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-01-10 17:50:08 +01:00
|
|
|
var reloadTab = function(ev) {
|
2018-01-09 14:08:17 +01:00
|
|
|
var tabId = tabIdFromPageSelector();
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( tabId <= 0 ) { return; }
|
2018-01-10 17:50:08 +01:00
|
|
|
messaging.send('loggerUI', {
|
|
|
|
what: 'reloadTab',
|
|
|
|
tabId: tabId,
|
|
|
|
bypassCache: ev && (ev.ctrlKey || ev.metaKey || ev.shiftKey)
|
|
|
|
});
|
2015-05-16 16:15:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var onMaxEntriesChanged = function() {
|
2015-06-15 01:40:55 +02:00
|
|
|
var input = this;
|
2015-05-09 00:28:01 +02:00
|
|
|
try {
|
2015-06-15 01:40:55 +02:00
|
|
|
maxEntries = parseInt(input.value, 10);
|
|
|
|
if ( maxEntries === 0 || isNaN(maxEntries) ) {
|
|
|
|
maxEntries = 1000;
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2015-06-15 01:40:55 +02:00
|
|
|
maxEntries = 1000;
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
2015-06-15 01:40:55 +02:00
|
|
|
maxEntries = Math.min(maxEntries, 5000);
|
|
|
|
maxEntries = Math.max(maxEntries, 10);
|
|
|
|
|
|
|
|
input.value = maxEntries.toString(10);
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'userSettings',
|
|
|
|
name: 'requestLogMaxEntries',
|
|
|
|
value: maxEntries
|
|
|
|
}
|
|
|
|
);
|
2015-05-09 00:28:01 +02:00
|
|
|
|
|
|
|
truncateLog(maxEntries);
|
|
|
|
};
|
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
var netFilteringManager = (function() {
|
2015-06-07 00:31:38 +02:00
|
|
|
var targetRow = null;
|
2015-05-26 15:52:09 +02:00
|
|
|
var dialog = null;
|
2015-06-07 00:31:38 +02:00
|
|
|
var createdStaticFilters = {};
|
|
|
|
|
|
|
|
var targetType;
|
2015-05-26 15:52:09 +02:00
|
|
|
var targetURLs = [];
|
2015-06-07 00:31:38 +02:00
|
|
|
var targetFrameHostname;
|
|
|
|
var targetPageHostname;
|
|
|
|
var targetTabId;
|
|
|
|
var targetDomain;
|
|
|
|
var targetPageDomain;
|
|
|
|
var targetFrameDomain;
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var uglyTypeFromSelector = function(pane) {
|
|
|
|
var prettyType = selectValue('select.type.' + pane);
|
2015-06-18 23:23:52 +02:00
|
|
|
if ( pane === 'static' ) {
|
|
|
|
return staticFilterTypes[prettyType] || prettyType;
|
|
|
|
}
|
2015-05-21 20:15:17 +02:00
|
|
|
return uglyRequestTypes[prettyType] || prettyType;
|
|
|
|
};
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var selectNode = function(selector) {
|
|
|
|
return dialog.querySelector(selector);
|
|
|
|
};
|
|
|
|
|
|
|
|
var selectValue = function(selector) {
|
|
|
|
return selectNode(selector).value || '';
|
|
|
|
};
|
|
|
|
|
|
|
|
var staticFilterNode = function() {
|
|
|
|
return dialog.querySelector('div.containers > div.static textarea');
|
|
|
|
};
|
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
var onColorsReady = function(response) {
|
|
|
|
document.body.classList.toggle('dirty', response.dirty);
|
|
|
|
var colorEntries = response.colors;
|
|
|
|
var colorEntry, node;
|
|
|
|
for ( var url in colorEntries ) {
|
|
|
|
if ( colorEntries.hasOwnProperty(url) === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
colorEntry = colorEntries[url];
|
2015-06-07 00:31:38 +02:00
|
|
|
node = dialog.querySelector('.dynamic .entry .action[data-url="' + url + '"]');
|
2015-05-21 20:15:17 +02:00
|
|
|
if ( node === null ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
node.classList.toggle('allow', colorEntry.r === 2);
|
|
|
|
node.classList.toggle('noop', colorEntry.r === 3);
|
|
|
|
node.classList.toggle('block', colorEntry.r === 1);
|
|
|
|
node.classList.toggle('own', colorEntry.own);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var colorize = function() {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'getURLFilteringData',
|
|
|
|
context: selectValue('select.dynamic.origin'),
|
|
|
|
urls: targetURLs,
|
|
|
|
type: uglyTypeFromSelector('dynamic')
|
|
|
|
},
|
|
|
|
onColorsReady
|
|
|
|
);
|
2015-05-21 20:15:17 +02:00
|
|
|
};
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var parseStaticInputs = function() {
|
2017-07-03 16:20:47 +02:00
|
|
|
var filter = '',
|
|
|
|
options = [],
|
|
|
|
block = selectValue('select.static.action') === '';
|
2015-06-07 00:45:30 +02:00
|
|
|
if ( !block ) {
|
2015-06-07 00:31:38 +02:00
|
|
|
filter = '@@';
|
|
|
|
}
|
2015-06-07 00:45:30 +02:00
|
|
|
var value = selectValue('select.static.url');
|
2015-06-07 00:31:38 +02:00
|
|
|
if ( value !== '' ) {
|
2017-07-03 16:20:47 +02:00
|
|
|
if ( value.slice(-1) === '/' ) {
|
|
|
|
value += '*';
|
|
|
|
} else if ( /[/?]/.test(value) === false ) {
|
|
|
|
value += '^';
|
|
|
|
}
|
|
|
|
value = '||' + value;
|
2015-06-07 00:31:38 +02:00
|
|
|
}
|
2017-07-03 16:20:47 +02:00
|
|
|
filter += value;
|
2015-06-07 00:31:38 +02:00
|
|
|
value = selectValue('select.static.type');
|
|
|
|
if ( value !== '' ) {
|
|
|
|
options.push(uglyTypeFromSelector('static'));
|
|
|
|
}
|
|
|
|
value = selectValue('select.static.origin');
|
|
|
|
if ( value !== '' ) {
|
|
|
|
if ( value === targetDomain ) {
|
|
|
|
options.push('first-party');
|
|
|
|
} else {
|
|
|
|
options.push('domain=' + value);
|
|
|
|
}
|
|
|
|
}
|
2015-06-07 00:45:30 +02:00
|
|
|
if ( block && selectValue('select.static.importance') !== '' ) {
|
|
|
|
options.push('important');
|
|
|
|
}
|
2015-06-07 00:31:38 +02:00
|
|
|
if ( options.length ) {
|
|
|
|
filter += '$' + options.join(',');
|
|
|
|
}
|
|
|
|
staticFilterNode().value = filter;
|
|
|
|
updateWidgets();
|
|
|
|
};
|
|
|
|
|
|
|
|
var updateWidgets = function() {
|
|
|
|
var value = staticFilterNode().value;
|
|
|
|
dialog.querySelector('#createStaticFilter').classList.toggle(
|
|
|
|
'disabled',
|
|
|
|
createdStaticFilters.hasOwnProperty(value) || value === ''
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
var onClick = function(ev) {
|
|
|
|
var target = ev.target;
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
// click outside the dialog proper
|
|
|
|
if ( target.classList.contains('modalDialog') ) {
|
2015-05-21 20:15:17 +02:00
|
|
|
toggleOff();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2015-05-26 15:52:09 +02:00
|
|
|
var tcl = target.classList;
|
2015-06-07 00:31:38 +02:00
|
|
|
var value;
|
|
|
|
|
|
|
|
// Select a mode
|
|
|
|
if ( tcl.contains('header') ) {
|
|
|
|
if ( tcl.contains('selected') ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uDom('.header').removeClass('selected');
|
|
|
|
uDom('.container').removeClass('selected');
|
|
|
|
value = target.getAttribute('data-container');
|
|
|
|
uDom('.header.' + value).addClass('selected');
|
|
|
|
uDom('.container.' + value).addClass('selected');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create static filter
|
|
|
|
if ( target.id === 'createStaticFilter' ) {
|
|
|
|
value = staticFilterNode().value;
|
|
|
|
// Avoid duplicates
|
|
|
|
if ( createdStaticFilters.hasOwnProperty(value) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
createdStaticFilters[value] = true;
|
|
|
|
if ( value !== '' ) {
|
|
|
|
var d = new Date();
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'createUserFilter',
|
2016-07-07 22:42:01 +02:00
|
|
|
pageDomain: targetPageDomain,
|
2016-03-06 16:51:06 +01:00
|
|
|
filters: '! ' + d.toLocaleString() + ' ' + targetPageDomain + '\n' + value
|
|
|
|
}
|
|
|
|
);
|
2015-06-07 00:31:38 +02:00
|
|
|
}
|
|
|
|
updateWidgets();
|
|
|
|
return;
|
|
|
|
}
|
2015-05-26 15:52:09 +02:00
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
// Save url filtering rule(s)
|
2015-06-07 00:31:38 +02:00
|
|
|
if ( target.id === 'saveRules' ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'saveURLFilteringRules',
|
|
|
|
context: selectValue('select.dynamic.origin'),
|
|
|
|
urls: targetURLs,
|
|
|
|
type: uglyTypeFromSelector('dynamic')
|
|
|
|
},
|
|
|
|
colorize
|
|
|
|
);
|
2015-05-21 20:15:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-22 14:05:55 +02:00
|
|
|
var persist = !!ev.ctrlKey || !!ev.metaKey;
|
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
// Remove url filtering rule
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('action') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'setURLFilteringRule',
|
|
|
|
context: selectValue('select.dynamic.origin'),
|
|
|
|
url: target.getAttribute('data-url'),
|
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
|
|
|
action: 0,
|
|
|
|
persist: persist
|
|
|
|
},
|
|
|
|
colorize
|
|
|
|
);
|
2015-05-21 20:15:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add "allow" url filtering rule
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('allow') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'setURLFilteringRule',
|
|
|
|
context: selectValue('select.dynamic.origin'),
|
|
|
|
url: target.parentNode.getAttribute('data-url'),
|
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
|
|
|
action: 2,
|
|
|
|
persist: persist
|
|
|
|
},
|
|
|
|
colorize
|
|
|
|
);
|
2015-05-21 20:15:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add "block" url filtering rule
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('noop') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'setURLFilteringRule',
|
|
|
|
context: selectValue('select.dynamic.origin'),
|
|
|
|
url: target.parentNode.getAttribute('data-url'),
|
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
|
|
|
action: 3,
|
|
|
|
persist: persist
|
|
|
|
},
|
|
|
|
colorize
|
|
|
|
);
|
2015-05-21 20:15:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add "block" url filtering rule
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('block') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'setURLFilteringRule',
|
|
|
|
context: selectValue('select.dynamic.origin'),
|
|
|
|
url: target.parentNode.getAttribute('data-url'),
|
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
|
|
|
action: 1,
|
|
|
|
persist: persist
|
|
|
|
},
|
|
|
|
colorize
|
|
|
|
);
|
2015-05-21 20:15:17 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-25 00:50:09 +02:00
|
|
|
|
|
|
|
// Force a reload of the tab
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('reload') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'reloadTab',
|
|
|
|
tabId: targetTabId
|
|
|
|
}
|
|
|
|
);
|
2015-05-25 00:50:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hightlight corresponding element in target web page
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('picker') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'launchElementPicker',
|
|
|
|
tabId: targetTabId,
|
|
|
|
targetURL: 'img\t' + targetURLs[0],
|
|
|
|
select: true
|
|
|
|
}
|
|
|
|
);
|
2015-05-25 00:50:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var onSelectChange = function(ev) {
|
|
|
|
var target = ev.target;
|
|
|
|
var tcl = target.classList;
|
|
|
|
|
|
|
|
if ( tcl.contains('dynamic') ) {
|
|
|
|
colorize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tcl.contains('static') ) {
|
|
|
|
parseStaticInputs();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var onInputChange = function() {
|
|
|
|
updateWidgets();
|
|
|
|
};
|
|
|
|
|
2015-05-26 15:52:09 +02:00
|
|
|
var createPreview = function(type, url) {
|
2015-06-07 00:31:38 +02:00
|
|
|
// First, whether picker can be used
|
|
|
|
dialog.querySelector('.picker').classList.toggle(
|
|
|
|
'hide',
|
2018-02-26 19:59:16 +01:00
|
|
|
targetTabId < 0 ||
|
2015-06-07 00:31:38 +02:00
|
|
|
targetType !== 'image' ||
|
|
|
|
/(?:^| )[dlsu]b(?: |$)/.test(targetRow.className)
|
|
|
|
);
|
|
|
|
|
2015-05-25 00:50:09 +02:00
|
|
|
var preview = null;
|
|
|
|
|
|
|
|
if ( type === 'image' ) {
|
|
|
|
preview = document.createElement('img');
|
|
|
|
preview.setAttribute('src', url);
|
|
|
|
}
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var container = dialog.querySelector('div.preview');
|
2015-05-25 00:50:09 +02:00
|
|
|
container.classList.toggle('hide', preview === null);
|
|
|
|
if ( preview === null ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
container.appendChild(preview);
|
2015-05-21 20:15:17 +02:00
|
|
|
};
|
|
|
|
|
2016-03-28 15:31:53 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/1511
|
|
|
|
var shortenLongString = function(url, max) {
|
|
|
|
var urlLen = url.length;
|
|
|
|
if ( urlLen <= max ) {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
var n = urlLen - max - 1;
|
|
|
|
var i = (urlLen - n) / 2 | 0;
|
|
|
|
return url.slice(0, i) + '…' + url.slice(i + n);
|
|
|
|
};
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
// Build list of candidate URLs
|
|
|
|
var createTargetURLs = function(url) {
|
|
|
|
var urls = [];
|
|
|
|
var matches = reRFC3986.exec(url);
|
|
|
|
if ( matches === null || !matches[1] || !matches[2] ) {
|
|
|
|
return urls;
|
2015-05-26 15:52:09 +02:00
|
|
|
}
|
2015-06-07 00:31:38 +02:00
|
|
|
// Shortest URL for a valid URL filtering rule
|
|
|
|
var rootURL = matches[1] + matches[2];
|
|
|
|
urls.unshift(rootURL);
|
|
|
|
var path = matches[3] || '';
|
|
|
|
var pos = path.charAt(0) === '/' ? 1 : 0;
|
|
|
|
while ( pos < path.length ) {
|
|
|
|
pos = path.indexOf('/', pos + 1);
|
|
|
|
if ( pos === -1 ) {
|
|
|
|
pos = path.length;
|
|
|
|
}
|
2017-07-03 16:20:47 +02:00
|
|
|
urls.unshift(rootURL + path.slice(0, pos + 1));
|
2015-06-07 00:31:38 +02:00
|
|
|
}
|
|
|
|
var query = matches[4] || '';
|
|
|
|
if ( query !== '') {
|
|
|
|
urls.unshift(rootURL + path + query);
|
|
|
|
}
|
|
|
|
return urls;
|
|
|
|
};
|
2015-05-26 15:52:09 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
// Fill dynamic URL filtering pane
|
|
|
|
var fillDynamicPane = function() {
|
|
|
|
var select;
|
|
|
|
// Fill context selector
|
|
|
|
select = selectNode('select.dynamic.origin');
|
|
|
|
removeAllChildren(select);
|
|
|
|
fillOriginSelect(select, targetPageHostname, targetPageDomain);
|
|
|
|
var option = document.createElement('option');
|
|
|
|
option.textContent = '*';
|
|
|
|
option.setAttribute('value', '*');
|
|
|
|
select.appendChild(option);
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
// Fill type selector
|
|
|
|
select = selectNode('select.dynamic.type');
|
|
|
|
select.options[0].textContent = targetType;
|
|
|
|
select.options[0].setAttribute('value', targetType);
|
|
|
|
select.selectedIndex = 0;
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
// Fill entries
|
|
|
|
var menuEntryTemplate = dialog.querySelector('table.toolbar tr.entry');
|
|
|
|
var tbody = dialog.querySelector('div.dynamic table.entries tbody');
|
|
|
|
var url, menuEntry;
|
|
|
|
for ( var i = 0; i < targetURLs.length; i++ ) {
|
|
|
|
url = targetURLs[i];
|
|
|
|
menuEntry = menuEntryTemplate.cloneNode(true);
|
|
|
|
menuEntry.cells[0].children[0].setAttribute('data-url', url);
|
2016-03-28 15:31:53 +02:00
|
|
|
menuEntry.cells[1].textContent = shortenLongString(url, 128);
|
2015-06-07 00:31:38 +02:00
|
|
|
tbody.appendChild(menuEntry);
|
2015-05-21 20:15:17 +02:00
|
|
|
}
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
colorize();
|
|
|
|
};
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var fillOriginSelect = function(select, hostname, domain) {
|
|
|
|
var option, pos;
|
2015-06-07 15:50:38 +02:00
|
|
|
var template = vAPI.i18n('loggerStaticFilteringSentencePartOrigin');
|
2015-06-07 00:31:38 +02:00
|
|
|
var value = hostname;
|
2015-05-21 20:15:17 +02:00
|
|
|
for (;;) {
|
|
|
|
option = document.createElement('option');
|
2015-06-07 00:31:38 +02:00
|
|
|
option.setAttribute('value', value);
|
2015-06-07 15:50:38 +02:00
|
|
|
option.textContent = template.replace('{{origin}}', value);
|
2015-06-07 00:31:38 +02:00
|
|
|
select.appendChild(option);
|
|
|
|
if ( value === domain ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos = value.indexOf('.');
|
2015-05-21 20:15:17 +02:00
|
|
|
if ( pos === -1 ) {
|
|
|
|
break;
|
|
|
|
}
|
2015-06-07 00:31:38 +02:00
|
|
|
value = value.slice(pos + 1);
|
2015-05-21 20:15:17 +02:00
|
|
|
}
|
2015-06-07 00:31:38 +02:00
|
|
|
};
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
// Fill static filtering pane
|
|
|
|
var fillStaticPane = function() {
|
|
|
|
var template = vAPI.i18n('loggerStaticFilteringSentence');
|
|
|
|
var rePlaceholder = /\{\{[^}]+?\}\}/g;
|
|
|
|
var nodes = [];
|
|
|
|
var match, pos = 0;
|
2017-07-03 16:20:47 +02:00
|
|
|
var select, option, n, i, value;
|
2015-06-07 00:31:38 +02:00
|
|
|
for (;;) {
|
|
|
|
match = rePlaceholder.exec(template);
|
|
|
|
if ( match === null ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( pos !== match.index ) {
|
|
|
|
nodes.push(document.createTextNode(template.slice(pos, match.index)));
|
|
|
|
}
|
|
|
|
pos = rePlaceholder.lastIndex;
|
|
|
|
switch ( match[0] ) {
|
|
|
|
case '{{br}}':
|
|
|
|
nodes.push(document.createElement('br'));
|
|
|
|
break;
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
case '{{action}}':
|
|
|
|
select = document.createElement('select');
|
|
|
|
select.className = 'static action';
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', '');
|
|
|
|
option.textContent = vAPI.i18n('loggerStaticFilteringSentencePartBlock');
|
|
|
|
select.appendChild(option);
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', '@@');
|
|
|
|
option.textContent = vAPI.i18n('loggerStaticFilteringSentencePartAllow');
|
|
|
|
select.appendChild(option);
|
|
|
|
nodes.push(select);
|
|
|
|
break;
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
case '{{type}}':
|
|
|
|
select = document.createElement('select');
|
|
|
|
select.className = 'static type';
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', targetType);
|
|
|
|
option.textContent = vAPI.i18n('loggerStaticFilteringSentencePartType').replace('{{type}}', targetType);
|
|
|
|
select.appendChild(option);
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', '');
|
|
|
|
option.textContent = vAPI.i18n('loggerStaticFilteringSentencePartAnyType');
|
|
|
|
select.appendChild(option);
|
|
|
|
nodes.push(select);
|
|
|
|
break;
|
2015-05-25 00:50:09 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
case '{{url}}':
|
|
|
|
select = document.createElement('select');
|
|
|
|
select.className = 'static url';
|
2017-07-03 16:20:47 +02:00
|
|
|
for ( i = 0, n = targetURLs.length; i < n; i++ ) {
|
|
|
|
value = targetURLs[i].replace(/^[a-z-]+:\/\//, '');
|
2015-06-07 00:31:38 +02:00
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', value);
|
2016-03-28 15:31:53 +02:00
|
|
|
option.textContent = shortenLongString(value, 128);
|
2015-06-07 00:31:38 +02:00
|
|
|
select.appendChild(option);
|
|
|
|
}
|
|
|
|
nodes.push(select);
|
|
|
|
break;
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
case '{{origin}}':
|
|
|
|
select = document.createElement('select');
|
|
|
|
select.className = 'static origin';
|
|
|
|
fillOriginSelect(select, targetFrameHostname, targetFrameDomain);
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', '');
|
|
|
|
option.textContent = vAPI.i18n('loggerStaticFilteringSentencePartAnyOrigin');
|
|
|
|
select.appendChild(option);
|
|
|
|
nodes.push(select);
|
|
|
|
break;
|
2015-05-25 00:50:09 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
case '{{importance}}':
|
|
|
|
select = document.createElement('select');
|
|
|
|
select.className = 'static importance';
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', '');
|
|
|
|
option.textContent = vAPI.i18n('loggerStaticFilteringSentencePartNotImportant');
|
|
|
|
select.appendChild(option);
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', 'important');
|
|
|
|
option.textContent = vAPI.i18n('loggerStaticFilteringSentencePartImportant');
|
|
|
|
select.appendChild(option);
|
|
|
|
nodes.push(select);
|
|
|
|
break;
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( pos < template.length ) {
|
|
|
|
nodes.push(document.createTextNode(template.slice(pos)));
|
2015-05-21 20:15:17 +02:00
|
|
|
}
|
2015-06-07 00:31:38 +02:00
|
|
|
var parent = dialog.querySelector('div.containers > div.static > p:first-of-type');
|
|
|
|
removeAllChildren(parent);
|
|
|
|
for ( i = 0; i < nodes.length; i++ ) {
|
|
|
|
parent.appendChild(nodes[i]);
|
|
|
|
}
|
|
|
|
parseStaticInputs();
|
|
|
|
};
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var fillDialog = function(domains) {
|
|
|
|
targetDomain = domains[0];
|
|
|
|
targetPageDomain = domains[1];
|
|
|
|
targetFrameDomain = domains[2];
|
2015-05-21 20:15:17 +02:00
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
createPreview(targetType, targetURLs[0]);
|
|
|
|
fillDynamicPane();
|
|
|
|
fillStaticPane();
|
2015-06-11 18:12:23 +02:00
|
|
|
document.body.appendChild(netFilteringDialog);
|
|
|
|
netFilteringDialog.addEventListener('click', onClick, true);
|
|
|
|
netFilteringDialog.addEventListener('change', onSelectChange, true);
|
|
|
|
netFilteringDialog.addEventListener('input', onInputChange, true);
|
2015-06-07 00:31:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var toggleOn = function(ev) {
|
2015-06-11 18:12:23 +02:00
|
|
|
dialog = netFilteringDialog.querySelector('.dialog');
|
2015-06-07 00:31:38 +02:00
|
|
|
targetRow = ev.target.parentElement;
|
|
|
|
targetTabId = tabIdFromClassName(targetRow.className);
|
2018-12-13 18:30:54 +01:00
|
|
|
targetType = targetRow.cells[5].textContent.trim() || '';
|
|
|
|
targetURLs = createTargetURLs(targetRow.cells[6].textContent);
|
|
|
|
targetPageHostname = targetRow.getAttribute('data-tabhn') || '';
|
|
|
|
targetFrameHostname = targetRow.getAttribute('data-dochn') || '';
|
2015-06-07 00:31:38 +02:00
|
|
|
|
|
|
|
// We need the root domain names for best user experience.
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'getDomainNames',
|
|
|
|
targets: [targetURLs[0], targetPageHostname, targetFrameHostname]
|
|
|
|
},
|
|
|
|
fillDialog
|
|
|
|
);
|
2015-05-21 20:15:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var toggleOff = function() {
|
2015-06-07 00:31:38 +02:00
|
|
|
removeAllChildren(dialog.querySelector('div.preview'));
|
|
|
|
removeAllChildren(dialog.querySelector('div.dynamic table.entries tbody'));
|
|
|
|
dialog = null;
|
|
|
|
targetRow = null;
|
|
|
|
targetURLs = [];
|
2015-06-11 18:12:23 +02:00
|
|
|
netFilteringDialog.removeEventListener('click', onClick, true);
|
|
|
|
netFilteringDialog.removeEventListener('change', onSelectChange, true);
|
|
|
|
netFilteringDialog.removeEventListener('input', onInputChange, true);
|
|
|
|
document.body.removeChild(netFilteringDialog);
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
toggleOn: toggleOn
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2015-06-29 16:46:20 +02:00
|
|
|
// https://www.youtube.com/watch?v=XyNYrmmdUd4
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var reverseLookupManager = (function() {
|
2018-07-22 14:14:02 +02:00
|
|
|
let filterFinderDialog = uDom.nodeFromId('filterFinderDialog');
|
|
|
|
let rawFilter = '';
|
2015-06-11 18:12:23 +02:00
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
let removeAllChildren = function(node) {
|
2015-06-11 18:12:23 +02:00
|
|
|
while ( node.firstChild ) {
|
|
|
|
node.removeChild(node.firstChild);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
// Clicking outside the dialog will close the dialog
|
|
|
|
let onClick = function(ev) {
|
|
|
|
if ( ev.target.classList.contains('modalDialog') ) {
|
2015-06-11 18:12:23 +02:00
|
|
|
toggleOff();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
};
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
let nodeFromFilter = function(filter, lists) {
|
2015-06-13 17:21:55 +02:00
|
|
|
if ( Array.isArray(lists) === false || lists.length === 0 ) {
|
2018-07-22 14:14:02 +02:00
|
|
|
return;
|
2015-06-11 18:12:23 +02:00
|
|
|
}
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
let p = document.createElement('p');
|
2015-06-11 18:12:23 +02:00
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
vAPI.i18n.safeTemplateToDOM(
|
|
|
|
'loggerStaticFilteringFinderSentence1',
|
|
|
|
{ filter: filter },
|
|
|
|
p
|
|
|
|
);
|
|
|
|
|
|
|
|
let ul = document.createElement('ul');
|
|
|
|
for ( let list of lists ) {
|
|
|
|
let li = document.querySelector('#filterFinderListEntry > li')
|
|
|
|
.cloneNode(true);
|
|
|
|
let a = li.querySelector('a:nth-of-type(1)');
|
|
|
|
a.href += encodeURIComponent(list.assetKey);
|
|
|
|
a.textContent = list.title;
|
2015-06-11 18:12:23 +02:00
|
|
|
if ( list.supportURL ) {
|
2018-07-22 14:14:02 +02:00
|
|
|
a = li.querySelector('a:nth-of-type(2)');
|
|
|
|
a.setAttribute('href', list.supportURL);
|
2015-06-11 18:12:23 +02:00
|
|
|
}
|
|
|
|
ul.appendChild(li);
|
|
|
|
}
|
2015-06-13 17:21:55 +02:00
|
|
|
p.appendChild(ul);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
};
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
let reverseLookupDone = function(response) {
|
|
|
|
if ( response instanceof Object === false ) {
|
|
|
|
response = {};
|
2015-06-13 17:21:55 +02:00
|
|
|
}
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
let dialog = filterFinderDialog.querySelector('.dialog');
|
2015-06-13 17:21:55 +02:00
|
|
|
removeAllChildren(dialog);
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
for ( let filter in response ) {
|
|
|
|
let p = nodeFromFilter(filter, response[filter]);
|
|
|
|
if ( p === undefined ) { continue; }
|
2015-06-13 17:21:55 +02:00
|
|
|
dialog.appendChild(p);
|
|
|
|
}
|
2015-06-11 18:12:23 +02:00
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/2179
|
|
|
|
if ( dialog.childElementCount === 0 ) {
|
|
|
|
vAPI.i18n.safeTemplateToDOM(
|
|
|
|
'loggerStaticFilteringFinderSentence2',
|
|
|
|
{ filter: rawFilter },
|
|
|
|
dialog
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
document.body.appendChild(filterFinderDialog);
|
|
|
|
filterFinderDialog.addEventListener('click', onClick, true);
|
|
|
|
};
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
let toggleOn = function(ev) {
|
|
|
|
let row = ev.target.parentElement;
|
2018-12-13 18:30:54 +01:00
|
|
|
rawFilter = row.cells[1].textContent;
|
2018-07-22 14:14:02 +02:00
|
|
|
if ( rawFilter === '' ) { return; }
|
2015-06-13 17:21:55 +02:00
|
|
|
|
|
|
|
if ( row.classList.contains('cat_net') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'listsFromNetFilter',
|
|
|
|
compiledFilter: row.getAttribute('data-filter') || '',
|
|
|
|
rawFilter: rawFilter
|
|
|
|
},
|
|
|
|
reverseLookupDone
|
|
|
|
);
|
2015-06-13 17:21:55 +02:00
|
|
|
} else if ( row.classList.contains('cat_cosmetic') ) {
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'loggerUI',
|
|
|
|
{
|
|
|
|
what: 'listsFromCosmeticFilter',
|
2018-12-13 18:30:54 +01:00
|
|
|
url: row.cells[6].textContent,
|
2016-03-06 16:51:06 +01:00
|
|
|
rawFilter: rawFilter,
|
|
|
|
},
|
|
|
|
reverseLookupDone
|
|
|
|
);
|
2015-06-13 17:21:55 +02:00
|
|
|
}
|
2015-06-11 18:12:23 +02:00
|
|
|
};
|
|
|
|
|
2018-07-22 14:14:02 +02:00
|
|
|
let toggleOff = function() {
|
2015-06-11 18:12:23 +02:00
|
|
|
filterFinderDialog.removeEventListener('click', onClick, true);
|
|
|
|
document.body.removeChild(filterFinderDialog);
|
2018-07-22 14:14:02 +02:00
|
|
|
rawFilter = '';
|
2015-05-21 20:15:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
toggleOn: toggleOn
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2015-05-09 00:28:01 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const rowFilterer = (function() {
|
2018-12-16 21:26:38 +01:00
|
|
|
const userFilters = [];
|
|
|
|
const builtinFilters = [];
|
|
|
|
let filters = [];
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const parseInput = function() {
|
2018-12-16 21:26:38 +01:00
|
|
|
userFilters.length = 0;
|
2018-12-14 17:01:21 +01:00
|
|
|
|
|
|
|
const rawParts = uDom('#filterInput').val().trim().split(/\s+/);
|
|
|
|
const n = rawParts.length;
|
|
|
|
const reStrs = [];
|
|
|
|
let not = false;
|
|
|
|
for ( let i = 0; i < n; i++ ) {
|
|
|
|
let rawPart = rawParts[i];
|
2015-05-23 15:27:24 +02:00
|
|
|
if ( rawPart.charAt(0) === '!' ) {
|
|
|
|
if ( reStrs.length === 0 ) {
|
|
|
|
not = true;
|
|
|
|
}
|
|
|
|
rawPart = rawPart.slice(1);
|
|
|
|
}
|
2018-12-14 17:01:21 +01:00
|
|
|
let reStr = '';
|
|
|
|
if ( rawPart.startsWith('/') && rawPart.endsWith('/') ) {
|
|
|
|
reStr = rawPart.slice(1, -1);
|
|
|
|
try {
|
|
|
|
new RegExp(reStr);
|
|
|
|
} catch(ex) {
|
|
|
|
reStr = '';
|
|
|
|
}
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
2018-12-14 17:01:21 +01:00
|
|
|
if ( reStr === '' ) {
|
|
|
|
const hardBeg = rawPart.startsWith('|');
|
|
|
|
if ( hardBeg ) {
|
|
|
|
rawPart = rawPart.slice(1);
|
|
|
|
}
|
|
|
|
const hardEnd = rawPart.endsWith('|');
|
|
|
|
if ( hardEnd ) {
|
|
|
|
rawPart = rawPart.slice(0, -1);
|
|
|
|
}
|
|
|
|
if ( rawPart === '' ) { continue; }
|
|
|
|
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
|
|
reStr = rawPart.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
|
if ( hardBeg ) {
|
|
|
|
reStr = '(?:^|\\s)' + reStr;
|
|
|
|
}
|
|
|
|
if ( hardEnd ) {
|
|
|
|
reStr += '(?:\\s|$)';
|
|
|
|
}
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
2015-05-23 15:27:24 +02:00
|
|
|
reStrs.push(reStr);
|
2015-05-28 02:48:04 +02:00
|
|
|
if ( i < (n - 1) && rawParts[i + 1] === '||' ) {
|
|
|
|
i += 1;
|
2015-05-23 15:27:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
reStr = reStrs.length === 1 ? reStrs[0] : reStrs.join('|');
|
2018-12-16 21:26:38 +01:00
|
|
|
userFilters.push({
|
2015-05-09 00:28:01 +02:00
|
|
|
re: new RegExp(reStr, 'i'),
|
|
|
|
r: !not
|
|
|
|
});
|
2018-12-14 17:01:21 +01:00
|
|
|
reStrs.length = 0;
|
2015-05-23 15:27:24 +02:00
|
|
|
not = false;
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
2018-12-16 21:26:38 +01:00
|
|
|
filters = builtinFilters.concat(userFilters);
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const filterOne = function(tr, clean) {
|
2018-12-14 17:01:21 +01:00
|
|
|
if ( filters.length === 0 && clean === true ) { return; }
|
2015-05-09 00:28:01 +02:00
|
|
|
// do not filter out doc boundaries, they help separate important
|
|
|
|
// section of log.
|
2018-12-13 18:30:54 +01:00
|
|
|
const cl = tr.classList;
|
|
|
|
if ( cl.contains('maindoc') ) { return; }
|
2018-12-14 17:01:21 +01:00
|
|
|
if ( filters.length === 0 ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
cl.remove('f');
|
|
|
|
return;
|
|
|
|
}
|
2018-12-13 18:30:54 +01:00
|
|
|
const cc = tr.cells;
|
|
|
|
const ccount = cc.length;
|
2015-05-09 00:28:01 +02:00
|
|
|
// each filter expression must hit (implicit and-op)
|
|
|
|
// if...
|
|
|
|
// positive filter expression = there must one hit on any field
|
|
|
|
// negative filter expression = there must be no hit on all fields
|
2018-12-14 17:01:21 +01:00
|
|
|
for ( const f of filters ) {
|
2018-12-13 18:30:54 +01:00
|
|
|
let hit = !f.r;
|
|
|
|
for ( let j = 1; j < ccount; j++ ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
if ( f.re.test(cc[j].textContent) ) {
|
|
|
|
hit = f.r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !hit ) {
|
|
|
|
cl.add('f');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cl.remove('f');
|
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const filterAll = function() {
|
2015-05-09 00:28:01 +02:00
|
|
|
// Special case: no filter
|
|
|
|
if ( filters.length === 0 ) {
|
2015-07-01 15:19:13 +02:00
|
|
|
uDom('#netInspector tr').removeClass('f');
|
2015-05-09 00:28:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-12-14 17:01:21 +01:00
|
|
|
for ( const row of document.querySelector('#netInspector tbody').rows ) {
|
|
|
|
filterOne(row);
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const onFilterChangedAsync = (function() {
|
2018-12-14 17:01:21 +01:00
|
|
|
let timer;
|
|
|
|
const commit = ( ) => {
|
|
|
|
timer = undefined;
|
2015-05-09 00:28:01 +02:00
|
|
|
parseInput();
|
|
|
|
filterAll();
|
|
|
|
};
|
|
|
|
return function() {
|
2018-12-14 17:01:21 +01:00
|
|
|
if ( timer !== undefined ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
clearTimeout(timer);
|
|
|
|
}
|
2015-05-17 19:02:56 +02:00
|
|
|
timer = vAPI.setTimeout(commit, 750);
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const onFilterButton = function() {
|
2015-07-01 15:19:13 +02:00
|
|
|
uDom.nodeFromId('netInspector').classList.toggle('f');
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
2018-12-16 21:26:38 +01:00
|
|
|
const onToggleExtras = function(ev) {
|
|
|
|
ev.target.classList.toggle('expanded');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onToggleBuiltinExpression = function(ev) {
|
|
|
|
builtinFilters.length = 0;
|
|
|
|
|
|
|
|
ev.target.classList.toggle('on');
|
|
|
|
const filtexElems = ev.currentTarget.querySelectorAll('[data-filtex]');
|
|
|
|
const orExprs = [];
|
|
|
|
let not = false;
|
|
|
|
for ( const filtexElem of filtexElems ) {
|
|
|
|
let filtex = filtexElem.getAttribute('data-filtex');
|
|
|
|
let active = filtexElem.classList.contains('on');
|
|
|
|
if ( filtex === '!' ) {
|
|
|
|
if ( orExprs.length !== 0 ) {
|
|
|
|
builtinFilters.push({
|
|
|
|
re: new RegExp(orExprs.join('|')),
|
|
|
|
r: !not
|
|
|
|
});
|
|
|
|
orExprs.length = 0;
|
|
|
|
}
|
|
|
|
not = active;
|
|
|
|
} else if ( active ) {
|
|
|
|
orExprs.push(filtex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( orExprs.length !== 0 ) {
|
|
|
|
builtinFilters.push({
|
|
|
|
re: new RegExp(orExprs.join('|')),
|
|
|
|
r: !not
|
|
|
|
});
|
|
|
|
}
|
|
|
|
uDom.nodeFromId('filterExprButton').classList.toggle(
|
|
|
|
'on',
|
|
|
|
builtinFilters.length !== 0
|
|
|
|
);
|
|
|
|
filters = builtinFilters.concat(userFilters);
|
|
|
|
filterAll();
|
|
|
|
};
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
uDom('#filterButton').on('click', onFilterButton);
|
|
|
|
uDom('#filterInput').on('input', onFilterChangedAsync);
|
2018-12-16 21:26:38 +01:00
|
|
|
uDom('#filterExprButton').on('click', onToggleExtras);
|
|
|
|
uDom('#filterExprPicker').on('click', '[data-filtex]', onToggleBuiltinExpression);
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2015-06-26 01:09:47 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/404
|
2018-12-16 21:26:38 +01:00
|
|
|
// Ensure page state is in sync with the state of its various widgets.
|
2015-06-26 01:09:47 +02:00
|
|
|
parseInput();
|
|
|
|
filterAll();
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
return {
|
2018-12-16 21:26:38 +01:00
|
|
|
filterOne,
|
|
|
|
filterAll,
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-14 17:01:21 +01:00
|
|
|
const toJunkyard = function(trs) {
|
2015-05-09 00:28:01 +02:00
|
|
|
trs.remove();
|
|
|
|
var i = trs.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
trJunkyard.push(trs.nodeAt(i));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var clearBuffer = function() {
|
2018-01-10 17:50:08 +01:00
|
|
|
var tabClass = uDom.nodeFromId('pageSelector').value;
|
|
|
|
var btsAlso = tabClass === '' || tabClass === 'tab_bts';
|
2015-07-01 15:19:13 +02:00
|
|
|
var tbody = document.querySelector('#netInspector tbody');
|
2015-06-15 02:11:25 +02:00
|
|
|
var tr = tbody.lastElementChild;
|
|
|
|
var trPrevious;
|
|
|
|
while ( tr !== null ) {
|
|
|
|
trPrevious = tr.previousElementSibling;
|
2018-01-10 17:50:08 +01:00
|
|
|
if (
|
|
|
|
(tr.clientHeight > 0) &&
|
|
|
|
(tr.classList.contains('tab_bts') === false || btsAlso)
|
|
|
|
) {
|
2015-06-15 02:11:25 +02:00
|
|
|
trJunkyard.push(tbody.removeChild(tr));
|
|
|
|
}
|
|
|
|
tr = trPrevious;
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
2015-06-15 02:11:25 +02:00
|
|
|
uDom.nodeFromId('clear').classList.toggle(
|
|
|
|
'disabled',
|
|
|
|
tbody.childElementCount === 0
|
|
|
|
);
|
|
|
|
uDom.nodeFromId('clean').classList.toggle(
|
|
|
|
'disabled',
|
2018-12-13 18:30:54 +01:00
|
|
|
tbody.querySelector('#netInspector tr[data-tabid].void') === null
|
2015-06-15 02:11:25 +02:00
|
|
|
);
|
2015-05-10 18:25:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var cleanBuffer = function() {
|
2018-12-13 18:30:54 +01:00
|
|
|
var rows = uDom('#netInspector tr[data-tabid].void').remove();
|
2015-05-10 18:25:26 +02:00
|
|
|
var i = rows.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
trJunkyard.push(rows.nodeAt(i));
|
|
|
|
}
|
|
|
|
uDom('#clean').addClass('disabled');
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
const pauseNetInspector = function() {
|
|
|
|
netInspectorPaused = uDom.nodeFromId('netInspector')
|
|
|
|
.classList
|
|
|
|
.toggle('paused');
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const toggleVCompactView = function() {
|
2017-11-20 14:42:32 +01:00
|
|
|
uDom.nodeFromId('netInspector').classList.toggle('vCompact');
|
2018-01-08 20:29:39 +01:00
|
|
|
uDom('#netInspector .vExpanded').toggleClass('vExpanded');
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
const toggleVCompactRow = function(ev) {
|
2018-01-08 20:29:39 +01:00
|
|
|
ev.target.parentElement.classList.toggle('vExpanded');
|
2015-07-01 15:19:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
const popupManager = (function() {
|
2018-12-13 18:30:54 +01:00
|
|
|
let realTabId = 0;
|
|
|
|
let popup = null;
|
|
|
|
let popupObserver = null;
|
|
|
|
|
|
|
|
const resizePopup = function() {
|
|
|
|
if ( popup === null ) { return; }
|
|
|
|
const popupBody = popup.contentWindow.document.body;
|
|
|
|
if ( popupBody.clientWidth !== 0 && popup.clientWidth !== popupBody.clientWidth ) {
|
|
|
|
popup.style.setProperty('width', popupBody.clientWidth + 'px');
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
if ( popupBody.clientHeight !== 0 && popup.clientHeight !== popupBody.clientHeight ) {
|
2015-05-10 15:28:50 +02:00
|
|
|
popup.style.setProperty('height', popupBody.clientHeight + 'px');
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const onLoad = function() {
|
2015-05-09 00:28:01 +02:00
|
|
|
resizePopup();
|
|
|
|
popupObserver.observe(popup.contentDocument.body, {
|
|
|
|
subtree: true,
|
|
|
|
attributes: true
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const setTabId = function(tabId) {
|
|
|
|
if ( popup === null ) { return; }
|
|
|
|
popup.setAttribute('src', 'popup.html?tabId=' + tabId);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onTabIdChanged = function() {
|
|
|
|
const tabId = tabIdFromPageSelector();
|
|
|
|
if ( tabId === 0 ) { return toggleOff(); }
|
|
|
|
realTabId = tabId;
|
|
|
|
setTabId(realTabId);
|
|
|
|
};
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const toggleOn = function() {
|
|
|
|
const tabId = tabIdFromPageSelector();
|
|
|
|
if ( tabId === 0 ) { return; }
|
|
|
|
realTabId = tabId;
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
popup = uDom.nodeFromId('popupContainer');
|
2015-05-09 00:28:01 +02:00
|
|
|
|
|
|
|
popup.addEventListener('load', onLoad);
|
|
|
|
popupObserver = new MutationObserver(resizePopup);
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const parent = uDom.nodeFromId('inspectors');
|
|
|
|
const rect = parent.getBoundingClientRect();
|
|
|
|
popup.style.setProperty('right', (rect.right - parent.clientWidth) + 'px');
|
2015-06-26 06:08:41 +02:00
|
|
|
parent.classList.add('popupOn');
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
document.addEventListener('tabIdChanged', onTabIdChanged);
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
setTabId(realTabId);
|
|
|
|
};
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const toggleOff = function() {
|
|
|
|
document.removeEventListener('tabIdChanged', onTabIdChanged);
|
|
|
|
uDom.nodeFromId('inspectors').classList.remove('popupOn');
|
2015-05-09 00:28:01 +02:00
|
|
|
popup.removeEventListener('load', onLoad);
|
|
|
|
popupObserver.disconnect();
|
|
|
|
popupObserver = null;
|
|
|
|
popup.setAttribute('src', '');
|
2018-12-13 18:30:54 +01:00
|
|
|
|
|
|
|
realTabId = 0;
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const exports = {
|
|
|
|
toggleOn: function() {
|
|
|
|
void (realTabId === 0 ? toggleOn() : toggleOff());
|
2015-05-09 00:28:01 +02:00
|
|
|
},
|
|
|
|
toggleOff: function() {
|
2018-12-13 18:30:54 +01:00
|
|
|
if ( realTabId !== 0 ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
toggleOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.defineProperty(exports, 'tabId', {
|
|
|
|
get: function() { return realTabId || 0; }
|
|
|
|
});
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-17 19:54:17 +01:00
|
|
|
logger.resize = (function() {
|
|
|
|
let timer;
|
|
|
|
|
|
|
|
const resize = function() {
|
|
|
|
const vrect = document.body.getBoundingClientRect();
|
|
|
|
const elems = document.querySelectorAll('.vscrollable');
|
|
|
|
for ( const elem of elems ) {
|
|
|
|
const crect = elem.getBoundingClientRect();
|
|
|
|
const dh = crect.bottom - vrect.bottom;
|
|
|
|
if ( dh === 0 ) { continue; }
|
|
|
|
elem.style.height = (crect.height - dh) + 'px';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const resizeAsync = function() {
|
|
|
|
if ( timer !== undefined ) { return; }
|
|
|
|
timer = self.requestAnimationFrame(( ) => {
|
|
|
|
timer = undefined;
|
|
|
|
resize();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
resizeAsync();
|
|
|
|
|
|
|
|
window.addEventListener('resize', resizeAsync, { passive: true });
|
|
|
|
|
|
|
|
return resizeAsync;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const grabView = function() {
|
2018-01-09 14:08:17 +01:00
|
|
|
if ( logger.ownerId === undefined ) {
|
|
|
|
logger.ownerId = Date.now();
|
2018-01-08 20:29:39 +01:00
|
|
|
}
|
|
|
|
readLogBufferAsync();
|
|
|
|
};
|
|
|
|
|
2018-12-13 18:30:54 +01:00
|
|
|
const releaseView = function() {
|
2018-01-09 14:08:17 +01:00
|
|
|
if ( logger.ownerId === undefined ) { return; }
|
2018-01-08 20:29:39 +01:00
|
|
|
vAPI.messaging.send(
|
|
|
|
'loggerUI',
|
2018-01-09 14:08:17 +01:00
|
|
|
{ what: 'releaseView', ownerId: logger.ownerId }
|
2018-01-08 20:29:39 +01:00
|
|
|
);
|
2018-01-09 14:08:17 +01:00
|
|
|
logger.ownerId = undefined;
|
2018-01-08 20:29:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('pagehide', releaseView);
|
|
|
|
window.addEventListener('pageshow', grabView);
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1398625
|
|
|
|
window.addEventListener('beforeunload', releaseView);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-08-01 17:30:54 +02:00
|
|
|
readLogBuffer();
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2015-08-01 17:30:54 +02:00
|
|
|
uDom('#pageSelector').on('change', pageSelectorChanged);
|
|
|
|
uDom('#refresh').on('click', reloadTab);
|
2018-12-13 18:30:54 +01:00
|
|
|
uDom('#showpopup').on('click', popupManager.toggleOn);
|
2015-07-01 15:19:13 +02:00
|
|
|
|
2017-11-20 14:42:32 +01:00
|
|
|
uDom('#netInspector .vCompactToggler').on('click', toggleVCompactView);
|
2015-08-01 17:30:54 +02:00
|
|
|
uDom('#clean').on('click', cleanBuffer);
|
|
|
|
uDom('#clear').on('click', clearBuffer);
|
2018-12-17 19:54:17 +01:00
|
|
|
uDom('#pause').on('click', pauseNetInspector);
|
2015-08-01 17:30:54 +02:00
|
|
|
uDom('#maxEntries').on('change', onMaxEntriesChanged);
|
2018-01-08 20:29:39 +01:00
|
|
|
uDom('#netInspector table').on('click', 'tr > td:nth-of-type(1)', toggleVCompactRow);
|
2018-12-13 18:30:54 +01:00
|
|
|
uDom('#netInspector').on('click', 'tr.canLookup > td:nth-of-type(2)', reverseLookupManager.toggleOn);
|
|
|
|
uDom('#netInspector').on('click', 'tr.cat_net > td:nth-of-type(3)', netFilteringManager.toggleOn);
|
2015-06-26 01:09:47 +02:00
|
|
|
|
2018-05-27 14:31:17 +02:00
|
|
|
// https://github.com/gorhill/uBlock/issues/507
|
|
|
|
// Ensure tab selector is in sync with URL hash
|
|
|
|
pageSelectorFromURLHash();
|
2015-08-01 17:30:54 +02:00
|
|
|
window.addEventListener('hashchange', pageSelectorFromURLHash);
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2018-12-16 21:26:38 +01:00
|
|
|
// Start to watch the current window geometry 2 seconds after the document
|
|
|
|
// is loaded, to be sure no spurious geometry changes will be triggered due
|
|
|
|
// to the window geometry pontentially not settling fast enough.
|
2018-12-14 17:01:21 +01:00
|
|
|
if ( self.location.search.includes('popup=1') ) {
|
|
|
|
window.addEventListener('load', ( ) => {
|
2018-12-16 21:26:38 +01:00
|
|
|
setTimeout(( ) => {
|
|
|
|
popupLoggerBox = {
|
|
|
|
x: self.screenX,
|
|
|
|
y: self.screenY,
|
|
|
|
w: self.outerWidth,
|
|
|
|
h: self.outerHeight,
|
|
|
|
};
|
|
|
|
}, 2000);
|
2018-12-14 17:01:21 +01:00
|
|
|
}, { once: true });
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|