2015-05-09 00:28:01 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2015-05-09 00:28:01 +02:00
|
|
|
Copyright (C) 2015 Raymond Hill
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
Home: https://github.com/gorhill/uBlock
|
2015-05-09 00:28:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* jshint boss: true */
|
|
|
|
/* global vAPI, uDom */
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
// Adjust top padding of content table, to match that of toolbar height.
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
uDom.nodeFromId('content').style.setProperty(
|
2015-05-16 16:15:02 +02:00
|
|
|
'margin-top',
|
2015-06-11 18:12:23 +02:00
|
|
|
uDom.nodeFromId('toolbar').offsetHeight + 'px'
|
2015-05-16 16:15:02 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var messager = vAPI.messaging.channel('logger-ui.js');
|
|
|
|
var tbody = document.querySelector('#content tbody');
|
|
|
|
var trJunkyard = [];
|
|
|
|
var tdJunkyard = [];
|
|
|
|
var firstVarDataCol = 2; // currently, column 2 (0-based index)
|
|
|
|
var lastVarDataIndex = 4; // currently, d0-d3
|
|
|
|
var maxEntries = 5000;
|
|
|
|
var noTabId = '';
|
|
|
|
var allTabIds = {};
|
2015-05-18 14:12:35 +02:00
|
|
|
var allTabIdsToken;
|
2015-05-16 16:15:02 +02:00
|
|
|
var hiddenTemplate = document.querySelector('#hiddenTemplate > span');
|
2015-05-21 20:15:17 +02:00
|
|
|
var reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
|
2015-06-11 18:12:23 +02:00
|
|
|
var netFilteringDialog = uDom.nodeFromId('netFilteringDialog');
|
|
|
|
var filterFinderDialog = uDom.nodeFromId('filterFinderDialog');
|
2015-05-16 16:15:02 +02:00
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var prettyRequestTypes = {
|
|
|
|
'main_frame': 'doc',
|
|
|
|
'stylesheet': 'css',
|
|
|
|
'sub_frame': 'frame',
|
|
|
|
'xmlhttprequest': 'xhr'
|
|
|
|
};
|
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
var uglyRequestTypes = {
|
|
|
|
'doc': 'main_frame',
|
|
|
|
'css': 'stylesheet',
|
|
|
|
'frame': 'sub_frame',
|
|
|
|
'xhr': 'xmlhttprequest'
|
|
|
|
};
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var timeOptions = {
|
|
|
|
hour: '2-digit',
|
|
|
|
minute: '2-digit',
|
|
|
|
second: '2-digit',
|
|
|
|
hour12: false
|
|
|
|
};
|
|
|
|
|
|
|
|
var dateOptions = {
|
|
|
|
month: 'short',
|
|
|
|
day: '2-digit'
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
var classNameFromTabId = function(tabId) {
|
|
|
|
if ( tabId === noTabId ) {
|
|
|
|
return 'tab_bts';
|
|
|
|
}
|
|
|
|
if ( tabId !== '' ) {
|
|
|
|
return 'tab_' + tabId;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-25 00:50:09 +02:00
|
|
|
var tabIdFromClassName = function(className) {
|
|
|
|
var matches = className.match(/(?:^| )tab_([^ ]+)(?: |$)/);
|
|
|
|
if ( matches === null ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return matches[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-06-09 16:27:08 +02:00
|
|
|
// Pretty much same logic as found in:
|
|
|
|
// µBlock.staticNetFilteringEngine.filterStringFromCompiled
|
|
|
|
// µBlock.staticNetFilteringEngine.filterRegexFromCompiled
|
|
|
|
|
|
|
|
var filterDecompiler = (function() {
|
|
|
|
var typeValToTypeName = {
|
|
|
|
1: 'stylesheet',
|
|
|
|
2: 'image',
|
|
|
|
3: 'object',
|
|
|
|
4: 'script',
|
|
|
|
5: 'xmlhttprequest',
|
|
|
|
6: 'sub_frame',
|
|
|
|
7: 'font',
|
|
|
|
8: 'other',
|
|
|
|
13: 'elemhide',
|
|
|
|
14: 'inline-script',
|
|
|
|
15: 'popup'
|
|
|
|
};
|
|
|
|
|
|
|
|
var toString = function(compiled) {
|
|
|
|
var opts = [];
|
|
|
|
var vfields = compiled.split('\v');
|
|
|
|
var filter = '';
|
2015-06-11 18:12:23 +02:00
|
|
|
var bits = parseInt(vfields[0], 16) | 0;
|
2015-06-09 16:27:08 +02:00
|
|
|
|
|
|
|
if ( bits & 0x01 ) {
|
|
|
|
filter += '@@';
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
var fid = vfields[1] === '.' ? '.' : vfields[2];
|
|
|
|
var tfields = fid !== '.' ? vfields[3].split('\t') : [];
|
2015-06-09 16:27:08 +02:00
|
|
|
var tfield0 = tfields[0];
|
|
|
|
|
|
|
|
switch ( fid ) {
|
|
|
|
case '.':
|
2015-06-11 18:12:23 +02:00
|
|
|
filter += '||' + vfields[2] + '^';
|
2015-06-09 16:27:08 +02:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
case 'ah':
|
|
|
|
case '0a':
|
|
|
|
case '0ah':
|
|
|
|
case '1a':
|
|
|
|
case '1ah':
|
|
|
|
case '_':
|
|
|
|
case '_h':
|
|
|
|
filter += tfield0;
|
|
|
|
// If the filter resemble a regex, add a trailing `*` as is
|
|
|
|
// customary to prevent ambiguity in logger.
|
|
|
|
if ( tfield0.charAt(0) === '/' && tfield0.slice(-1) === '/' ) {
|
|
|
|
filter += '*';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '|a':
|
|
|
|
case '|ah':
|
|
|
|
filter += '|' + tfield0;
|
|
|
|
break;
|
|
|
|
case 'a|':
|
|
|
|
case 'a|h':
|
|
|
|
filter += tfield0 + '|';
|
|
|
|
break;
|
|
|
|
case '||a':
|
|
|
|
case '||ah':
|
|
|
|
case '||_':
|
|
|
|
case '||_h':
|
|
|
|
filter += '||' + tfield0;
|
|
|
|
break;
|
|
|
|
case '//':
|
|
|
|
case '//h':
|
|
|
|
filter += '/' + tfield0 + '/';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Domain option?
|
|
|
|
switch ( fid ) {
|
|
|
|
case '0ah':
|
|
|
|
case '1ah':
|
|
|
|
case '|ah':
|
|
|
|
case 'a|h':
|
|
|
|
case '||ah':
|
|
|
|
case '||_h':
|
|
|
|
case '//h':
|
|
|
|
opts.push('domain=' + tfields[1]);
|
|
|
|
break;
|
|
|
|
case 'ah':
|
|
|
|
case '_h':
|
|
|
|
opts.push('domain=' + tfields[2]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter options
|
|
|
|
if ( bits & 0x02 ) {
|
|
|
|
opts.push('important');
|
|
|
|
}
|
|
|
|
if ( bits & 0x08 ) {
|
|
|
|
opts.push('third-party');
|
|
|
|
} else if ( bits & 0x04 ) {
|
|
|
|
opts.push('first-party');
|
|
|
|
}
|
|
|
|
var typeVal = bits >>> 4 & 0x0F;
|
|
|
|
if ( typeVal ) {
|
|
|
|
opts.push(typeValToTypeName[typeVal]);
|
|
|
|
// Because of the way `elemhide` is implemented
|
|
|
|
if ( typeVal === 13 ) {
|
|
|
|
filter = '@@' + filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( opts.length !== 0 ) {
|
|
|
|
filter += '$' + opts.join(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
return filter;
|
|
|
|
};
|
|
|
|
|
|
|
|
var reEscape = /[.+?^${}()|[\]\\]/g;
|
|
|
|
var reWildcards = /\*+/g;
|
|
|
|
|
|
|
|
var toRegex = function(compiled) {
|
|
|
|
var vfields = compiled.split('\v');
|
2015-06-11 18:12:23 +02:00
|
|
|
var fid = vfields[1] === '.' ? '.' : vfields[2];
|
|
|
|
var tfields = fid !== '.' ? vfields[3].split('\t') : [];
|
2015-06-09 16:27:08 +02:00
|
|
|
var reStr;
|
|
|
|
|
|
|
|
switch ( fid ) {
|
|
|
|
case '.':
|
2015-06-11 18:12:23 +02:00
|
|
|
reStr = vfields[2].replace(reEscape, '\\$&');
|
2015-06-09 16:27:08 +02:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
case 'ah':
|
|
|
|
case '0a':
|
|
|
|
case '0ah':
|
|
|
|
case '1a':
|
|
|
|
case '1ah':
|
|
|
|
case '_':
|
|
|
|
case '_h':
|
|
|
|
case '||a':
|
|
|
|
case '||ah':
|
|
|
|
case '||_':
|
|
|
|
case '||_h':
|
|
|
|
reStr = tfields[0]
|
|
|
|
.replace(reEscape, '\\$&')
|
|
|
|
.replace(reWildcards, '.*');
|
|
|
|
break;
|
|
|
|
case '|a':
|
|
|
|
case '|ah':
|
|
|
|
reStr = '^' + tfields[0].
|
|
|
|
replace(reEscape, '\\$&')
|
|
|
|
.replace(reWildcards, '.*');
|
|
|
|
break;
|
|
|
|
case 'a|':
|
|
|
|
case 'a|h':
|
|
|
|
reStr = tfields[0]
|
|
|
|
.replace(reEscape, '\\$&')
|
|
|
|
.replace(reWildcards, '.*') + '$';
|
|
|
|
break;
|
|
|
|
case '//':
|
|
|
|
case '//h':
|
|
|
|
reStr = tfields[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( reStr === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return new RegExp(reStr, 'gi');
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
toString: toString,
|
|
|
|
toRegex: toRegex
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var createCellAt = function(tr, index) {
|
|
|
|
var td = tr.cells[index];
|
|
|
|
var mustAppend = !td;
|
|
|
|
if ( mustAppend ) {
|
|
|
|
td = tdJunkyard.pop();
|
|
|
|
}
|
|
|
|
if ( td ) {
|
|
|
|
td.removeAttribute('colspan');
|
|
|
|
td.textContent = '';
|
|
|
|
} else {
|
|
|
|
td = document.createElement('td');
|
|
|
|
}
|
|
|
|
if ( mustAppend ) {
|
|
|
|
tr.appendChild(td);
|
|
|
|
}
|
|
|
|
return td;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var createRow = function(layout) {
|
|
|
|
var tr = trJunkyard.pop();
|
|
|
|
if ( tr ) {
|
|
|
|
tr.className = '';
|
2015-06-07 00:31:38 +02:00
|
|
|
tr.removeAttribute('data-hn-page');
|
|
|
|
tr.removeAttribute('data-hn-frame');
|
2015-06-11 18:12:23 +02:00
|
|
|
tr.removeAttribute('data-filter');
|
2015-05-09 00:28:01 +02:00
|
|
|
} else {
|
|
|
|
tr = document.createElement('tr');
|
|
|
|
}
|
|
|
|
for ( var index = 0; index < firstVarDataCol; index++ ) {
|
|
|
|
createCellAt(tr, index);
|
|
|
|
}
|
|
|
|
var i = 1, span = 1, td;
|
|
|
|
for (;;) {
|
|
|
|
td = createCellAt(tr, index);
|
|
|
|
if ( i === lastVarDataIndex ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
while ( td = tr.cells[index] ) {
|
|
|
|
tdJunkyard.push(tr.removeChild(td));
|
|
|
|
}
|
|
|
|
return tr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
var createHiddenTextNode = function(text) {
|
|
|
|
var node = hiddenTemplate.cloneNode(true);
|
|
|
|
node.textContent = text;
|
|
|
|
return node;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var createGap = function(tabId, url) {
|
|
|
|
var tr = createRow('1');
|
2015-06-13 17:21:55 +02:00
|
|
|
tr.classList.add('tab', 'canMtx', 'tab_' + tabId, 'maindoc');
|
2015-05-09 00:28:01 +02:00
|
|
|
tr.cells[firstVarDataCol].textContent = url;
|
|
|
|
tbody.insertBefore(tr, tbody.firstChild);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var renderNetLogEntry = function(tr, entry) {
|
2015-06-13 17:21:55 +02:00
|
|
|
var trcl = tr.classList;
|
2015-05-09 00:28:01 +02:00
|
|
|
var filter = entry.d0;
|
|
|
|
var type = entry.d1;
|
|
|
|
var url = entry.d2;
|
2015-05-21 20:15:17 +02:00
|
|
|
var td;
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add('canMtx');
|
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' ) {
|
|
|
|
createGap(entry.tab, url);
|
|
|
|
}
|
|
|
|
|
2015-06-05 05:33:40 +02:00
|
|
|
// Contexts
|
2015-05-21 20:15:17 +02:00
|
|
|
if ( entry.d3 ) {
|
2015-06-07 00:31:38 +02:00
|
|
|
tr.setAttribute('data-hn-page', entry.d3);
|
2015-05-21 20:15:17 +02:00
|
|
|
}
|
2015-06-05 05:33:40 +02:00
|
|
|
if ( entry.d4 ) {
|
2015-06-07 00:31:38 +02:00
|
|
|
tr.setAttribute('data-hn-frame', entry.d4);
|
2015-06-05 05:33:40 +02:00
|
|
|
}
|
2015-05-21 20:15:17 +02:00
|
|
|
|
|
|
|
var filterCat = filter.slice(0, 3);
|
|
|
|
if ( filterCat.charAt(2) === ':' ) {
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add(filterCat.slice(0, 2));
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
2015-06-09 16:27:08 +02:00
|
|
|
var filteringType = filterCat.charAt(0);
|
|
|
|
td = tr.cells[2];
|
|
|
|
if ( filter !== '' ) {
|
|
|
|
filter = filter.slice(3);
|
|
|
|
if ( filteringType === 's' ) {
|
|
|
|
td.textContent = filterDecompiler.toString(filter);
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add('canLookup');
|
2015-06-11 18:12:23 +02:00
|
|
|
tr.setAttribute('data-filter', filter);
|
2015-06-13 17:21:55 +02:00
|
|
|
} else if ( filteringType === 'c' ) {
|
|
|
|
td.textContent = filter;
|
|
|
|
trcl.add('canLookup');
|
2015-06-09 16:27:08 +02:00
|
|
|
} else {
|
|
|
|
td.textContent = filter;
|
|
|
|
}
|
2015-05-25 00:50:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
td = tr.cells[3];
|
2015-06-09 16:27:08 +02:00
|
|
|
var filteringOp = filterCat.charAt(1);
|
|
|
|
if ( filteringOp === 'b' ) {
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add('blocked');
|
2015-05-21 20:15:17 +02:00
|
|
|
td.textContent = '--';
|
2015-06-09 16:27:08 +02:00
|
|
|
} else if ( filteringOp === 'a' ) {
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add('allowed');
|
2015-05-21 20:15:17 +02:00
|
|
|
td.textContent = '++';
|
2015-06-09 16:27:08 +02:00
|
|
|
} else if ( filteringOp === 'n' ) {
|
2015-06-13 17:21:55 +02:00
|
|
|
trcl.add('nooped');
|
2015-05-25 00:50:09 +02:00
|
|
|
td.textContent = '**';
|
2015-05-09 00:28:01 +02:00
|
|
|
} else {
|
2015-05-21 20:15:17 +02:00
|
|
|
td.textContent = '';
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 20:15:17 +02:00
|
|
|
tr.cells[4].textContent = (prettyRequestTypes[type] || type);
|
2015-06-09 16:27:08 +02:00
|
|
|
|
|
|
|
var re = null;
|
|
|
|
if ( filteringType === 's' ) {
|
|
|
|
re = filterDecompiler.toRegex(filter);
|
|
|
|
} else if ( filteringType === 'l' ) {
|
|
|
|
re = regexFromURLFilteringResult(filter);
|
|
|
|
}
|
|
|
|
tr.cells[5].appendChild(nodeFromURL(url, re));
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var renderLogEntry = function(entry) {
|
|
|
|
var tr;
|
|
|
|
var fvdc = firstVarDataCol;
|
|
|
|
|
|
|
|
switch ( entry.cat ) {
|
|
|
|
case 'error':
|
|
|
|
case 'info':
|
|
|
|
tr = createRow('1');
|
|
|
|
tr.cells[fvdc].textContent = entry.d0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cosmetic':
|
|
|
|
case 'net':
|
|
|
|
tr = createRow('1111');
|
|
|
|
renderNetLogEntry(tr, entry);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
tr = createRow('1');
|
|
|
|
tr.cells[fvdc].textContent = entry.d0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fields common to all rows.
|
|
|
|
var time = new Date(entry.tstamp);
|
|
|
|
tr.cells[0].textContent = time.toLocaleTimeString('fullwide', timeOptions);
|
|
|
|
tr.cells[0].title = time.toLocaleDateString('fullwide', dateOptions);
|
|
|
|
|
|
|
|
if ( entry.tab ) {
|
2015-05-16 16:15:02 +02:00
|
|
|
tr.classList.add('tab', classNameFromTabId(entry.tab));
|
2015-05-09 00:28:01 +02:00
|
|
|
if ( entry.tab === noTabId ) {
|
2015-05-16 16:15:02 +02:00
|
|
|
tr.cells[1].appendChild(createHiddenTextNode('bts'));
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( entry.cat !== '' ) {
|
|
|
|
tr.classList.add('cat_' + entry.cat);
|
|
|
|
}
|
|
|
|
|
|
|
|
rowFilterer.filterOne(tr, true);
|
|
|
|
|
|
|
|
tbody.insertBefore(tr, tbody.firstChild);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var renderLogEntries = function(response) {
|
|
|
|
document.body.classList.toggle('colorBlind', response.colorBlind);
|
|
|
|
|
|
|
|
var entries = response.entries;
|
|
|
|
if ( entries.length === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preserve scroll position
|
|
|
|
var height = tbody.offsetHeight;
|
|
|
|
|
|
|
|
var tabIds = response.tabIds;
|
|
|
|
var n = entries.length;
|
|
|
|
var entry;
|
|
|
|
for ( var i = 0; i < n; i++ ) {
|
|
|
|
entry = entries[i];
|
|
|
|
// Unlikely, but it may happen
|
|
|
|
if ( entry.tab && tabIds.hasOwnProperty(entry.tab) === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
renderLogEntry(entries[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
var yDelta = tbody.offsetHeight - height;
|
|
|
|
if ( yDelta === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chromium:
|
|
|
|
// body.scrollTop = good value
|
|
|
|
// body.parentNode.scrollTop = 0
|
|
|
|
if ( document.body.scrollTop !== 0 ) {
|
|
|
|
document.body.scrollTop += yDelta;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Firefox:
|
|
|
|
// body.scrollTop = 0
|
|
|
|
// body.parentNode.scrollTop = good value
|
|
|
|
var parentNode = document.body.parentNode;
|
|
|
|
if ( parentNode && parentNode.scrollTop !== 0 ) {
|
|
|
|
parentNode.scrollTop += yDelta;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
var synchronizeTabIds = function(newTabIds) {
|
|
|
|
var oldTabIds = allTabIds;
|
|
|
|
var autoDeleteVoidRows = !!vAPI.localStorage.getItem('loggerAutoDeleteVoidRows');
|
|
|
|
var rowVoided = false;
|
|
|
|
var trs;
|
|
|
|
for ( var tabId in oldTabIds ) {
|
|
|
|
if ( oldTabIds.hasOwnProperty(tabId) === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( newTabIds.hasOwnProperty(tabId) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Mark or remove voided rows
|
|
|
|
trs = uDom('.tab_' + tabId);
|
|
|
|
if ( autoDeleteVoidRows ) {
|
|
|
|
toJunkyard(trs);
|
|
|
|
} else {
|
|
|
|
trs.removeClass('canMtx');
|
|
|
|
rowVoided = true;
|
|
|
|
}
|
|
|
|
// Remove popup if it is currently bound to a removed tab.
|
|
|
|
if ( tabId === popupManager.tabId ) {
|
|
|
|
popupManager.toggleOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
var select = uDom.nodeFromId('pageSelector');
|
2015-05-16 16:15:02 +02:00
|
|
|
var selectValue = select.value;
|
|
|
|
var tabIds = Object.keys(newTabIds).sort(function(a, b) {
|
|
|
|
return newTabIds[a].localeCompare(newTabIds[b]);
|
|
|
|
});
|
|
|
|
var option;
|
|
|
|
for ( var i = 0, j = 2; i < tabIds.length; i++ ) {
|
|
|
|
tabId = tabIds[i];
|
|
|
|
if ( tabId === noTabId ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
option = select.options[j];
|
|
|
|
j += 1;
|
|
|
|
if ( !option ) {
|
|
|
|
option = document.createElement('option');
|
|
|
|
select.appendChild(option);
|
|
|
|
}
|
|
|
|
option.textContent = newTabIds[tabId];
|
|
|
|
option.value = classNameFromTabId(tabId);
|
|
|
|
if ( option.value === selectValue ) {
|
|
|
|
option.setAttribute('selected', '');
|
|
|
|
} else {
|
|
|
|
option.removeAttribute('selected');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
return rowVoided;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var truncateLog = function(size) {
|
|
|
|
if ( size === 0 ) {
|
|
|
|
size = 5000;
|
|
|
|
}
|
|
|
|
var tbody = document.querySelector('#content tbody');
|
|
|
|
size = Math.min(size, 10000);
|
|
|
|
var tr;
|
|
|
|
while ( tbody.childElementCount > size ) {
|
|
|
|
tr = tbody.lastElementChild;
|
|
|
|
trJunkyard.push(tbody.removeChild(tr));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onLogBufferRead = function(response) {
|
|
|
|
// This tells us the behind-the-scene tab id
|
|
|
|
noTabId = response.noTabId;
|
|
|
|
|
|
|
|
// This may have changed meanwhile
|
|
|
|
if ( response.maxEntries !== maxEntries ) {
|
|
|
|
maxEntries = response.maxEntries;
|
|
|
|
uDom('#maxEntries').val(maxEntries || '');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Neuter rows for which a tab does not exist anymore
|
2015-05-18 14:12:35 +02:00
|
|
|
var rowVoided = false;
|
|
|
|
if ( response.tabIdsToken !== allTabIdsToken ) {
|
|
|
|
rowVoided = synchronizeTabIds(response.tabIds);
|
|
|
|
allTabIdsToken = response.tabIdsToken;
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
renderLogEntries(response);
|
|
|
|
|
2015-05-10 18:25:26 +02:00
|
|
|
if ( rowVoided ) {
|
|
|
|
uDom('#clean').toggleClass(
|
|
|
|
'disabled',
|
|
|
|
tbody.querySelector('tr.tab:not(.canMtx)') === null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
// Synchronize toolbar with content of log
|
|
|
|
uDom('#clear').toggleClass(
|
|
|
|
'disabled',
|
|
|
|
tbody.querySelector('tr') === null
|
|
|
|
);
|
|
|
|
|
2015-05-17 19:02:56 +02:00
|
|
|
vAPI.setTimeout(readLogBuffer, 1200);
|
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.
|
|
|
|
|
|
|
|
var readLogBuffer = function() {
|
|
|
|
messager.send({ what: 'readAll' }, onLogBufferRead);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
var pageSelectorChanged = function() {
|
2015-06-11 18:12:23 +02:00
|
|
|
var style = uDom.nodeFromId('tabFilterer');
|
|
|
|
var tabClass = uDom.nodeFromId('pageSelector').value;
|
2015-05-16 16:15:02 +02:00
|
|
|
var sheet = style.sheet;
|
|
|
|
while ( sheet.cssRules.length !== 0 ) {
|
|
|
|
sheet.deleteRule(0);
|
|
|
|
}
|
|
|
|
if ( tabClass !== '' ) {
|
|
|
|
sheet.insertRule(
|
|
|
|
'#content table tr:not(.' + tabClass + ') { display: none; }',
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
uDom('#refresh').toggleClass(
|
|
|
|
'disabled',
|
|
|
|
tabClass === '' || tabClass === 'tab_bts'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var reloadTab = function() {
|
2015-06-11 18:12:23 +02:00
|
|
|
var tabClass = uDom.nodeFromId('pageSelector').value;
|
2015-05-25 00:50:09 +02:00
|
|
|
var tabId = tabIdFromClassName(tabClass);
|
|
|
|
if ( tabId === 'bts' || tabId === '' ) {
|
2015-05-16 16:15:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-25 00:50:09 +02:00
|
|
|
messager.send({ what: 'reloadTab', tabId: tabId });
|
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);
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'userSettings',
|
|
|
|
name: 'requestLogMaxEntries',
|
|
|
|
value: maxEntries
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
var removeAllChildren = function(node) {
|
|
|
|
while ( node.firstChild ) {
|
|
|
|
node.removeChild(node.firstChild);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var uglyTypeFromSelector = function(pane) {
|
|
|
|
var prettyType = selectValue('select.type.' + pane);
|
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() {
|
|
|
|
messager.send({
|
|
|
|
what: 'getURLFilteringData',
|
2015-06-07 00:31:38 +02:00
|
|
|
context: selectValue('select.dynamic.origin'),
|
2015-05-26 15:52:09 +02:00
|
|
|
urls: targetURLs,
|
2015-06-07 00:31:38 +02:00
|
|
|
type: uglyTypeFromSelector('dynamic')
|
2015-05-21 20:15:17 +02:00
|
|
|
}, onColorsReady);
|
|
|
|
};
|
|
|
|
|
2015-06-07 00:31:38 +02:00
|
|
|
var parseStaticInputs = function() {
|
|
|
|
var filter = '';
|
2015-06-07 00:45:30 +02:00
|
|
|
var options = [];
|
|
|
|
var block = selectValue('select.static.action') === '';
|
|
|
|
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 !== '' ) {
|
|
|
|
filter += '||' + value;
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
messager.send({
|
|
|
|
what: 'createUserFilter',
|
|
|
|
filters: '! ' + d.toLocaleString() + ' ' + targetPageDomain + '\n' + value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
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' ) {
|
2015-05-21 20:15:17 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'saveURLFilteringRules',
|
2015-06-07 00:31:38 +02:00
|
|
|
context: selectValue('select.dynamic.origin'),
|
2015-05-26 15:52:09 +02:00
|
|
|
urls: targetURLs,
|
2015-06-07 00:31:38 +02:00
|
|
|
type: uglyTypeFromSelector('dynamic')
|
2015-05-21 20:15:17 +02:00
|
|
|
}, colorize);
|
|
|
|
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') ) {
|
2015-05-21 20:15:17 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'setURLFilteringRule',
|
2015-06-07 00:31:38 +02:00
|
|
|
context: selectValue('select.dynamic.origin'),
|
2015-05-21 20:15:17 +02:00
|
|
|
url: target.getAttribute('data-url'),
|
2015-06-07 00:31:38 +02:00
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
2015-05-22 14:05:55 +02:00
|
|
|
action: 0,
|
|
|
|
persist: persist
|
2015-05-21 20:15:17 +02:00
|
|
|
}, colorize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add "allow" url filtering rule
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('allow') ) {
|
2015-05-21 20:15:17 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'setURLFilteringRule',
|
2015-06-07 00:31:38 +02:00
|
|
|
context: selectValue('select.dynamic.origin'),
|
2015-05-21 20:15:17 +02:00
|
|
|
url: target.parentNode.getAttribute('data-url'),
|
2015-06-07 00:31:38 +02:00
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
2015-05-22 14:05:55 +02:00
|
|
|
action: 2,
|
|
|
|
persist: persist
|
2015-05-21 20:15:17 +02:00
|
|
|
}, colorize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add "block" url filtering rule
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('noop') ) {
|
2015-05-21 20:15:17 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'setURLFilteringRule',
|
2015-06-07 00:31:38 +02:00
|
|
|
context: selectValue('select.dynamic.origin'),
|
2015-05-21 20:15:17 +02:00
|
|
|
url: target.parentNode.getAttribute('data-url'),
|
2015-06-07 00:31:38 +02:00
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
2015-05-22 14:05:55 +02:00
|
|
|
action: 3,
|
|
|
|
persist: persist
|
2015-05-21 20:15:17 +02:00
|
|
|
}, colorize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add "block" url filtering rule
|
2015-05-26 15:52:09 +02:00
|
|
|
if ( tcl.contains('block') ) {
|
2015-05-21 20:15:17 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'setURLFilteringRule',
|
2015-06-07 00:31:38 +02:00
|
|
|
context: selectValue('select.dynamic.origin'),
|
2015-05-21 20:15:17 +02:00
|
|
|
url: target.parentNode.getAttribute('data-url'),
|
2015-06-07 00:31:38 +02:00
|
|
|
type: uglyTypeFromSelector('dynamic'),
|
2015-05-22 14:05:55 +02:00
|
|
|
action: 1,
|
|
|
|
persist: persist
|
2015-05-21 20:15:17 +02:00
|
|
|
}, colorize);
|
|
|
|
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') ) {
|
2015-05-25 00:50:09 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'reloadTab',
|
2015-06-07 00:31:38 +02:00
|
|
|
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') ) {
|
2015-05-25 00:50:09 +02:00
|
|
|
messager.send({
|
|
|
|
what: 'launchElementPicker',
|
2015-06-07 00:31:38 +02:00
|
|
|
tabId: targetTabId,
|
2015-05-26 15:52:09 +02:00
|
|
|
targetURL: 'img\t' + targetURLs[0],
|
2015-05-25 00:50:09 +02:00
|
|
|
select: true
|
|
|
|
});
|
|
|
|
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',
|
|
|
|
targetTabId === noTabId ||
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
urls.unshift(rootURL + path.slice(0, pos));
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
menuEntry.cells[1].textContent = url;
|
|
|
|
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;
|
|
|
|
var select, option, i, value;
|
|
|
|
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';
|
|
|
|
for ( i = 0; i < targetURLs.length; i++ ) {
|
|
|
|
value = targetURLs[i].replace(/^[a-z]+:\/\//, '');
|
|
|
|
option = document.createElement('option');
|
|
|
|
option.setAttribute('value', value);
|
|
|
|
option.textContent = value;
|
|
|
|
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);
|
|
|
|
targetType = targetRow.cells[4].textContent.trim() || '';
|
|
|
|
targetURLs = createTargetURLs(targetRow.cells[5].textContent);
|
|
|
|
targetPageHostname = targetRow.getAttribute('data-hn-page') || '';
|
|
|
|
targetFrameHostname = targetRow.getAttribute('data-hn-frame') || '';
|
|
|
|
|
|
|
|
// We need the root domain names for best user experience.
|
|
|
|
messager.send({
|
|
|
|
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
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var reverseLookupManager = (function() {
|
|
|
|
var reSentence1 = /\{\{filter\}\}/g;
|
|
|
|
var sentence1Template = vAPI.i18n('loggerStaticFilteringFinderSentence1');
|
|
|
|
|
|
|
|
var removeAllChildren = function(node) {
|
|
|
|
while ( node.firstChild ) {
|
|
|
|
node.removeChild(node.firstChild);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var onClick = function(ev) {
|
|
|
|
var target = ev.target;
|
|
|
|
|
|
|
|
// click outside the dialog proper
|
|
|
|
if ( target.classList.contains('modalDialog') ) {
|
|
|
|
toggleOff();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
};
|
|
|
|
|
2015-06-13 17:21:55 +02:00
|
|
|
var nodeFromFilter = function(filter, lists) {
|
|
|
|
if ( Array.isArray(lists) === false || lists.length === 0 ) {
|
|
|
|
return null;
|
2015-06-11 18:12:23 +02:00
|
|
|
}
|
|
|
|
var node;
|
2015-06-13 17:21:55 +02:00
|
|
|
var p = document.createElement('p');
|
2015-06-11 18:12:23 +02:00
|
|
|
|
|
|
|
reSentence1.lastIndex = 0;
|
|
|
|
var matches = reSentence1.exec(sentence1Template);
|
|
|
|
if ( matches === null ) {
|
|
|
|
node = document.createTextNode(sentence1Template);
|
|
|
|
} else {
|
|
|
|
node = uDom.nodeFromSelector('#filterFinderDialogSentence1 > span').cloneNode(true);
|
|
|
|
node.childNodes[0].textContent = sentence1Template.slice(0, matches.index);
|
2015-06-13 17:21:55 +02:00
|
|
|
node.childNodes[1].textContent = filter;
|
2015-06-11 18:12:23 +02:00
|
|
|
node.childNodes[2].textContent = sentence1Template.slice(reSentence1.lastIndex);
|
|
|
|
}
|
|
|
|
p.appendChild(node);
|
|
|
|
|
2015-06-13 17:21:55 +02:00
|
|
|
var ul = document.createElement('ul');
|
2015-06-11 18:12:23 +02:00
|
|
|
var list, li;
|
|
|
|
for ( var i = 0; i < lists.length; i++ ) {
|
|
|
|
list = lists[i];
|
|
|
|
li = document.createElement('li');
|
|
|
|
if ( list.supportURL ) {
|
|
|
|
node = document.createElement('a');
|
|
|
|
node.textContent = list.title;
|
|
|
|
node.setAttribute('href', list.supportURL);
|
|
|
|
node.setAttribute('target', '_blank');
|
|
|
|
} else {
|
|
|
|
node = document.createTextNode(list.title);
|
|
|
|
}
|
|
|
|
li.appendChild(node);
|
|
|
|
ul.appendChild(li);
|
|
|
|
}
|
2015-06-13 17:21:55 +02:00
|
|
|
p.appendChild(ul);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
};
|
|
|
|
|
|
|
|
var reverseLookupDone = function(response) {
|
|
|
|
if ( typeof response !== 'object' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dialog = filterFinderDialog.querySelector('.dialog');
|
|
|
|
removeAllChildren(dialog);
|
|
|
|
|
|
|
|
for ( var filter in response ) {
|
|
|
|
var p = nodeFromFilter(filter, response[filter]);
|
|
|
|
if ( p === null ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dialog.appendChild(p);
|
|
|
|
}
|
2015-06-11 18:12:23 +02:00
|
|
|
|
|
|
|
document.body.appendChild(filterFinderDialog);
|
|
|
|
filterFinderDialog.addEventListener('click', onClick, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
var toggleOn = function(ev) {
|
|
|
|
var row = ev.target.parentElement;
|
2015-06-13 17:21:55 +02:00
|
|
|
var rawFilter = row.cells[2].textContent;
|
|
|
|
if ( rawFilter === '' ) {
|
2015-06-11 18:12:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-06-13 17:21:55 +02:00
|
|
|
|
|
|
|
if ( row.classList.contains('cat_net') ) {
|
|
|
|
messager.send({
|
|
|
|
what: 'listsFromNetFilter',
|
|
|
|
compiledFilter: row.getAttribute('data-filter') || '',
|
|
|
|
rawFilter: rawFilter
|
|
|
|
}, reverseLookupDone);
|
|
|
|
} else if ( row.classList.contains('cat_cosmetic') ) {
|
|
|
|
messager.send({
|
|
|
|
what: 'listsFromCosmeticFilter',
|
|
|
|
hostname: row.getAttribute('data-hn-frame') || '',
|
|
|
|
rawFilter: rawFilter,
|
|
|
|
}, reverseLookupDone);
|
|
|
|
}
|
2015-06-11 18:12:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var toggleOff = function() {
|
|
|
|
filterFinderDialog.removeEventListener('click', onClick, true);
|
|
|
|
document.body.removeChild(filterFinderDialog);
|
2015-05-21 20:15:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
toggleOn: toggleOn
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2015-05-09 00:28:01 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var rowFilterer = (function() {
|
|
|
|
var filters = [];
|
|
|
|
|
|
|
|
var parseInput = function() {
|
|
|
|
filters = [];
|
|
|
|
|
2015-05-23 15:27:24 +02:00
|
|
|
var rawPart, hardBeg, hardEnd;
|
2015-05-09 00:28:01 +02:00
|
|
|
var raw = uDom('#filterInput').val().trim();
|
|
|
|
var rawParts = raw.split(/\s+/);
|
2015-05-23 15:27:24 +02:00
|
|
|
var reStr, reStrs = [], not = false;
|
2015-05-28 02:48:04 +02:00
|
|
|
var n = rawParts.length;
|
|
|
|
for ( var i = 0; i < n; i++ ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
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);
|
|
|
|
}
|
2015-05-09 00:28:01 +02:00
|
|
|
hardBeg = rawPart.charAt(0) === '|';
|
|
|
|
if ( hardBeg ) {
|
|
|
|
rawPart = rawPart.slice(1);
|
|
|
|
}
|
|
|
|
hardEnd = rawPart.slice(-1) === '|';
|
|
|
|
if ( hardEnd ) {
|
|
|
|
rawPart = rawPart.slice(0, -1);
|
|
|
|
}
|
|
|
|
if ( rawPart === '' ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
|
2015-05-25 00:50:09 +02:00
|
|
|
reStr = rawPart.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
2015-05-09 00:28:01 +02:00
|
|
|
if ( hardBeg ) {
|
|
|
|
reStr = '(?:^|\\s)' + reStr;
|
|
|
|
}
|
|
|
|
if ( hardEnd ) {
|
|
|
|
reStr += '(?:\\s|$)';
|
|
|
|
}
|
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('|');
|
2015-05-09 00:28:01 +02:00
|
|
|
filters.push({
|
|
|
|
re: new RegExp(reStr, 'i'),
|
|
|
|
r: !not
|
|
|
|
});
|
2015-05-23 15:27:24 +02:00
|
|
|
reStrs = [];
|
|
|
|
not = false;
|
2015-05-09 00:28:01 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var filterOne = function(tr, clean) {
|
|
|
|
var ff = filters;
|
|
|
|
var fcount = ff.length;
|
|
|
|
if ( fcount === 0 && clean === true ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// do not filter out doc boundaries, they help separate important
|
|
|
|
// section of log.
|
|
|
|
var cl = tr.classList;
|
|
|
|
if ( cl.contains('maindoc') ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( fcount === 0 ) {
|
|
|
|
cl.remove('f');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var cc = tr.cells;
|
|
|
|
var ccount = cc.length;
|
|
|
|
var hit, j, f;
|
|
|
|
// 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
|
|
|
|
for ( var i = 0; i < fcount; i++ ) {
|
|
|
|
f = ff[i];
|
|
|
|
hit = !f.r;
|
|
|
|
for ( j = 0; j < ccount; j++ ) {
|
|
|
|
if ( f.re.test(cc[j].textContent) ) {
|
|
|
|
hit = f.r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !hit ) {
|
|
|
|
cl.add('f');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cl.remove('f');
|
|
|
|
};
|
|
|
|
|
|
|
|
var filterAll = function() {
|
|
|
|
// Special case: no filter
|
|
|
|
if ( filters.length === 0 ) {
|
|
|
|
uDom('#content tr').removeClass('f');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var tbody = document.querySelector('#content tbody');
|
|
|
|
var rows = tbody.rows;
|
|
|
|
var i = rows.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
filterOne(rows[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var onFilterChangedAsync = (function() {
|
|
|
|
var timer = null;
|
|
|
|
var commit = function() {
|
|
|
|
timer = null;
|
|
|
|
parseInput();
|
|
|
|
filterAll();
|
|
|
|
};
|
|
|
|
return function() {
|
|
|
|
if ( timer !== null ) {
|
|
|
|
clearTimeout(timer);
|
|
|
|
}
|
2015-05-17 19:02:56 +02:00
|
|
|
timer = vAPI.setTimeout(commit, 750);
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
var onFilterButton = function() {
|
|
|
|
var cl = document.body.classList;
|
|
|
|
cl.toggle('f', cl.contains('f') === false);
|
|
|
|
};
|
|
|
|
|
|
|
|
uDom('#filterButton').on('click', onFilterButton);
|
|
|
|
uDom('#filterInput').on('input', onFilterChangedAsync);
|
|
|
|
|
|
|
|
return {
|
|
|
|
filterOne: filterOne,
|
|
|
|
filterAll: filterAll
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var toJunkyard = function(trs) {
|
|
|
|
trs.remove();
|
|
|
|
var i = trs.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
trJunkyard.push(trs.nodeAt(i));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var clearBuffer = function() {
|
|
|
|
var tbody = document.querySelector('#content tbody');
|
|
|
|
var tr;
|
|
|
|
while ( tbody.firstChild !== null ) {
|
|
|
|
tr = tbody.lastElementChild;
|
|
|
|
trJunkyard.push(tbody.removeChild(tr));
|
|
|
|
}
|
|
|
|
uDom('#clear').addClass('disabled');
|
2015-05-10 18:25:26 +02:00
|
|
|
uDom('#clean').addClass('disabled');
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var cleanBuffer = function() {
|
|
|
|
var rows = uDom('#content tr.tab:not(.canMtx)').remove();
|
|
|
|
var i = rows.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
trJunkyard.push(rows.nodeAt(i));
|
|
|
|
}
|
|
|
|
uDom('#clean').addClass('disabled');
|
2015-05-09 00:28:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var toggleCompactView = function() {
|
|
|
|
document.body.classList.toggle(
|
|
|
|
'compactView',
|
|
|
|
document.body.classList.contains('compactView') === false
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var popupManager = (function() {
|
|
|
|
var realTabId = null;
|
|
|
|
var localTabId = null;
|
|
|
|
var container = null;
|
|
|
|
var popup = null;
|
|
|
|
var popupObserver = null;
|
|
|
|
var style = null;
|
|
|
|
var styleTemplate = [
|
2015-05-25 00:50:09 +02:00
|
|
|
'#content tr:not(.tab_{{tabId}}) {',
|
2015-05-09 00:28:01 +02:00
|
|
|
'cursor: not-allowed;',
|
|
|
|
'opacity: 0.2;',
|
|
|
|
'}'
|
|
|
|
].join('\n');
|
|
|
|
|
2015-05-10 15:28:50 +02:00
|
|
|
var resizePopup = function() {
|
|
|
|
if ( popup === null ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var popupBody = popup.contentWindow.document.body;
|
|
|
|
if ( popupBody.clientWidth !== 0 && container.clientWidth !== popupBody.clientWidth ) {
|
2015-05-10 15:28:50 +02:00
|
|
|
container.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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-10 15:28:50 +02:00
|
|
|
var toggleSize = function() {
|
|
|
|
container.classList.toggle('hide');
|
|
|
|
};
|
|
|
|
|
2015-05-09 00:28:01 +02:00
|
|
|
var onLoad = function() {
|
|
|
|
resizePopup();
|
|
|
|
popupObserver.observe(popup.contentDocument.body, {
|
|
|
|
subtree: true,
|
|
|
|
attributes: true
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var toggleOn = function(td) {
|
|
|
|
var tr = td.parentNode;
|
2015-05-25 00:50:09 +02:00
|
|
|
realTabId = localTabId = tabIdFromClassName(tr.className);
|
|
|
|
if ( realTabId === '' ) {
|
2015-05-09 00:28:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( localTabId === 'bts' ) {
|
|
|
|
realTabId = noTabId;
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
container = uDom.nodeFromId('popupContainer');
|
2015-05-09 00:28:01 +02:00
|
|
|
|
2015-05-10 15:28:50 +02:00
|
|
|
container.querySelector('div > span:nth-of-type(1)').addEventListener('click', toggleSize);
|
|
|
|
container.querySelector('div > span:nth-of-type(2)').addEventListener('click', toggleOff);
|
2015-05-09 00:28:01 +02:00
|
|
|
|
|
|
|
popup = document.createElement('iframe');
|
|
|
|
popup.addEventListener('load', onLoad);
|
|
|
|
popup.setAttribute('src', 'popup.html?tabId=' + realTabId);
|
|
|
|
popupObserver = new MutationObserver(resizePopup);
|
|
|
|
container.appendChild(popup);
|
|
|
|
|
2015-06-11 18:12:23 +02:00
|
|
|
style = uDom.nodeFromId('popupFilterer');
|
2015-05-09 00:28:01 +02:00
|
|
|
style.textContent = styleTemplate.replace('{{tabId}}', localTabId);
|
|
|
|
|
|
|
|
document.body.classList.add('popupOn');
|
|
|
|
};
|
|
|
|
|
|
|
|
var toggleOff = function() {
|
|
|
|
document.body.classList.remove('popupOn');
|
|
|
|
|
2015-05-10 15:28:50 +02:00
|
|
|
container.querySelector('div > span:nth-of-type(1)').removeEventListener('click', toggleSize);
|
|
|
|
container.querySelector('div > span:nth-of-type(2)').removeEventListener('click', toggleOff);
|
|
|
|
container.classList.remove('hide');
|
2015-05-09 00:28:01 +02:00
|
|
|
|
|
|
|
popup.removeEventListener('load', onLoad);
|
|
|
|
popupObserver.disconnect();
|
|
|
|
popupObserver = null;
|
|
|
|
popup.setAttribute('src', '');
|
|
|
|
container.removeChild(popup);
|
|
|
|
popup = null;
|
|
|
|
|
|
|
|
style.textContent = '';
|
|
|
|
style = null;
|
|
|
|
|
|
|
|
container = null;
|
|
|
|
realTabId = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
var exports = {
|
|
|
|
toggleOn: function(ev) {
|
|
|
|
if ( realTabId === null ) {
|
|
|
|
toggleOn(ev.target);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleOff: function() {
|
|
|
|
if ( realTabId !== null ) {
|
|
|
|
toggleOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.defineProperty(exports, 'tabId', {
|
|
|
|
get: function() { return realTabId || 0; }
|
|
|
|
});
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
uDom.onLoad(function() {
|
|
|
|
readLogBuffer();
|
|
|
|
|
2015-05-16 16:15:02 +02:00
|
|
|
uDom('#pageSelector').on('change', pageSelectorChanged);
|
|
|
|
uDom('#refresh').on('click', reloadTab);
|
2015-05-09 00:28:01 +02:00
|
|
|
uDom('#compactViewToggler').on('click', toggleCompactView);
|
2015-05-10 18:25:26 +02:00
|
|
|
uDom('#clean').on('click', cleanBuffer);
|
2015-05-09 00:28:01 +02:00
|
|
|
uDom('#clear').on('click', clearBuffer);
|
|
|
|
uDom('#maxEntries').on('change', onMaxEntriesChanged);
|
|
|
|
uDom('#content table').on('click', 'tr.canMtx > td:nth-of-type(2)', popupManager.toggleOn);
|
2015-06-11 18:12:23 +02:00
|
|
|
uDom('#content').on('click', 'tr.cat_net > td:nth-of-type(4)', netFilteringManager.toggleOn);
|
2015-06-13 17:21:55 +02:00
|
|
|
uDom('#content').on('click', 'tr.canLookup > td:nth-of-type(3)', reverseLookupManager.toggleOn);
|
2015-05-09 00:28:01 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|