This commit is contained in:
Raymond Hill 2018-12-14 11:01:21 -05:00
parent 2f1d319072
commit 5b7a3c9983
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 179 additions and 91 deletions

View File

@ -482,10 +482,35 @@ vAPI.tabs.open = function(details) {
}; };
// Open in a standalone window // Open in a standalone window
//
// https://github.com/uBlockOrigin/uBlock-issues/issues/168#issuecomment-413038191 // https://github.com/uBlockOrigin/uBlock-issues/issues/168#issuecomment-413038191
// Not all platforms support browser.windows API. // Not all platforms support browser.windows API.
if ( details.popup === true && chrome.windows instanceof Object ) { //
chrome.windows.create({ url: details.url, type: 'popup' }); // For some reasons, some platforms do not honor the left,top
// position when specified. I found that further calling
// windows.update again with the same position _may_ help.
if ( details.popup === true && browser.windows instanceof Object ) {
const options = {
url: details.url,
type: 'popup',
};
if ( details.box instanceof Object ) {
Object.assign(options, details.box);
}
browser.windows.create(options, win => {
if ( win instanceof Object === false ) { return; }
if ( details.box instanceof Object === false ) { return; }
if (
win.left === details.box.left &&
win.top === details.box.top
) {
return;
}
browser.windows.update(win.id, {
left: details.box.left,
top: details.box.top
});
});
return; return;
} }

View File

@ -30,11 +30,8 @@
/******************************************************************************/ /******************************************************************************/
const messaging = vAPI.messaging; const messaging = vAPI.messaging;
const logger = self.logger = { ownerId: Date.now() };
const logger = self.logger = { let popupLoggerBox;
ownerId: Date.now()
};
let activeTabId; let activeTabId;
/******************************************************************************/ /******************************************************************************/
@ -576,15 +573,27 @@ const onLogBufferRead = function(response) {
const readLogBuffer = function() { const readLogBuffer = function() {
if ( logger.ownerId === undefined ) { return; } if ( logger.ownerId === undefined ) { return; }
vAPI.messaging.send( const msg = {
'loggerUI', what: 'readAll',
{ ownerId: logger.ownerId,
what: 'readAll', tabIdsToken: allTabIdsToken,
ownerId: logger.ownerId, };
tabIdsToken: allTabIdsToken, if (
}, popupLoggerBox instanceof Object &&
onLogBufferRead (
); 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);
}; };
const readLogBufferAsync = function() { const readLogBufferAsync = function() {
@ -1398,42 +1407,50 @@ var reverseLookupManager = (function() {
/******************************************************************************/ /******************************************************************************/
const rowFilterer = (function() { const rowFilterer = (function() {
let filters = []; const filters = [];
const parseInput = function() { const parseInput = function() {
filters = []; filters.length = 0;
var rawPart, hardBeg, hardEnd; const rawParts = uDom('#filterInput').val().trim().split(/\s+/);
var raw = uDom('#filterInput').val().trim(); const n = rawParts.length;
var rawParts = raw.split(/\s+/); const reStrs = [];
var reStr, reStrs = [], not = false; let not = false;
var n = rawParts.length; for ( let i = 0; i < n; i++ ) {
for ( var i = 0; i < n; i++ ) { let rawPart = rawParts[i];
rawPart = rawParts[i];
if ( rawPart.charAt(0) === '!' ) { if ( rawPart.charAt(0) === '!' ) {
if ( reStrs.length === 0 ) { if ( reStrs.length === 0 ) {
not = true; not = true;
} }
rawPart = rawPart.slice(1); rawPart = rawPart.slice(1);
} }
hardBeg = rawPart.charAt(0) === '|'; let reStr = '';
if ( hardBeg ) { if ( rawPart.startsWith('/') && rawPart.endsWith('/') ) {
rawPart = rawPart.slice(1); reStr = rawPart.slice(1, -1);
try {
new RegExp(reStr);
} catch(ex) {
reStr = '';
}
} }
hardEnd = rawPart.slice(-1) === '|'; if ( reStr === '' ) {
if ( hardEnd ) { const hardBeg = rawPart.startsWith('|');
rawPart = rawPart.slice(0, -1); if ( hardBeg ) {
} rawPart = rawPart.slice(1);
if ( rawPart === '' ) { }
continue; const hardEnd = rawPart.endsWith('|');
} if ( hardEnd ) {
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions rawPart = rawPart.slice(0, -1);
reStr = rawPart.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
if ( hardBeg ) { if ( rawPart === '' ) { continue; }
reStr = '(?:^|\\s)' + reStr; // https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
} reStr = rawPart.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
if ( hardEnd ) { if ( hardBeg ) {
reStr += '(?:\\s|$)'; reStr = '(?:^|\\s)' + reStr;
}
if ( hardEnd ) {
reStr += '(?:\\s|$)';
}
} }
reStrs.push(reStr); reStrs.push(reStr);
if ( i < (n - 1) && rawParts[i + 1] === '||' ) { if ( i < (n - 1) && rawParts[i + 1] === '||' ) {
@ -1445,22 +1462,18 @@ const rowFilterer = (function() {
re: new RegExp(reStr, 'i'), re: new RegExp(reStr, 'i'),
r: !not r: !not
}); });
reStrs = []; reStrs.length = 0;
not = false; not = false;
} }
}; };
const filterOne = function(tr, clean) { const filterOne = function(tr, clean) {
const ff = filters; if ( filters.length === 0 && clean === true ) { return; }
const fcount = ff.length;
if ( fcount === 0 && clean === true ) {
return;
}
// do not filter out doc boundaries, they help separate important // do not filter out doc boundaries, they help separate important
// section of log. // section of log.
const cl = tr.classList; const cl = tr.classList;
if ( cl.contains('maindoc') ) { return; } if ( cl.contains('maindoc') ) { return; }
if ( fcount === 0 ) { if ( filters.length === 0 ) {
cl.remove('f'); cl.remove('f');
return; return;
} }
@ -1470,8 +1483,7 @@ const rowFilterer = (function() {
// if... // if...
// positive filter expression = there must one hit on any field // positive filter expression = there must one hit on any field
// negative filter expression = there must be no hit on all fields // negative filter expression = there must be no hit on all fields
for ( let i = 0; i < fcount; i++ ) { for ( const f of filters ) {
let f = ff[i];
let hit = !f.r; let hit = !f.r;
for ( let j = 1; j < ccount; j++ ) { for ( let j = 1; j < ccount; j++ ) {
if ( f.re.test(cc[j].textContent) ) { if ( f.re.test(cc[j].textContent) ) {
@ -1493,23 +1505,20 @@ const rowFilterer = (function() {
uDom('#netInspector tr').removeClass('f'); uDom('#netInspector tr').removeClass('f');
return; return;
} }
var tbody = document.querySelector('#netInspector tbody'); for ( const row of document.querySelector('#netInspector tbody').rows ) {
var rows = tbody.rows; filterOne(row);
var i = rows.length;
while ( i-- ) {
filterOne(rows[i]);
} }
}; };
const onFilterChangedAsync = (function() { const onFilterChangedAsync = (function() {
var timer = null; let timer;
var commit = function() { const commit = ( ) => {
timer = null; timer = undefined;
parseInput(); parseInput();
filterAll(); filterAll();
}; };
return function() { return function() {
if ( timer !== null ) { if ( timer !== undefined ) {
clearTimeout(timer); clearTimeout(timer);
} }
timer = vAPI.setTimeout(commit, 750); timer = vAPI.setTimeout(commit, 750);
@ -1536,7 +1545,7 @@ const rowFilterer = (function() {
/******************************************************************************/ /******************************************************************************/
var toJunkyard = function(trs) { const toJunkyard = function(trs) {
trs.remove(); trs.remove();
var i = trs.length; var i = trs.length;
while ( i-- ) { while ( i-- ) {
@ -1725,6 +1734,17 @@ uDom('#netInspector').on('click', 'tr.cat_net > td:nth-of-type(3)', netFiltering
pageSelectorFromURLHash(); pageSelectorFromURLHash();
window.addEventListener('hashchange', pageSelectorFromURLHash); window.addEventListener('hashchange', pageSelectorFromURLHash);
if ( self.location.search.includes('popup=1') ) {
window.addEventListener('load', ( ) => {
popupLoggerBox = {
x: self.screenX,
y: self.screenY,
w: self.outerWidth,
h: self.outerHeight,
};
}, { once: true });
}
/******************************************************************************/ /******************************************************************************/
})(); })();

View File

@ -1124,13 +1124,13 @@ vAPI.messaging.listen('dashboard', onMessage);
/******************************************************************************/ /******************************************************************************/
var µb = µBlock, const µb = µBlock;
extensionOriginURL = vAPI.getURL(''); const extensionOriginURL = vAPI.getURL('');
/******************************************************************************/ /******************************************************************************/
var getLoggerData = function(details, activeTabId, callback) { const getLoggerData = function(details, activeTabId, callback) {
let response = { const response = {
colorBlind: µb.userSettings.colorBlindFriendly, colorBlind: µb.userSettings.colorBlindFriendly,
entries: µb.logger.readAll(details.ownerId), entries: µb.logger.readAll(details.ownerId),
maxEntries: µb.userSettings.requestLogMaxEntries, maxEntries: µb.userSettings.requestLogMaxEntries,
@ -1138,16 +1138,16 @@ var getLoggerData = function(details, activeTabId, callback) {
tabIdsToken: µb.pageStoresToken tabIdsToken: µb.pageStoresToken
}; };
if ( µb.pageStoresToken !== details.tabIdsToken ) { if ( µb.pageStoresToken !== details.tabIdsToken ) {
let tabIds = new Map(); const tabIds = new Map();
for ( let entry of µb.pageStores ) { for ( const entry of µb.pageStores ) {
let pageStore = entry[1]; const pageStore = entry[1];
if ( pageStore.rawURL.startsWith(extensionOriginURL) ) { continue; } if ( pageStore.rawURL.startsWith(extensionOriginURL) ) { continue; }
tabIds.set(entry[0], pageStore.title); tabIds.set(entry[0], pageStore.title);
} }
response.tabIds = Array.from(tabIds); response.tabIds = Array.from(tabIds);
} }
if ( activeTabId ) { if ( activeTabId ) {
let pageStore = µb.pageStoreFromTabId(activeTabId); const pageStore = µb.pageStoreFromTabId(activeTabId);
if ( if (
pageStore === null || pageStore === null ||
pageStore.rawURL.startsWith(extensionOriginURL) pageStore.rawURL.startsWith(extensionOriginURL)
@ -1155,43 +1155,71 @@ var getLoggerData = function(details, activeTabId, callback) {
response.activeTabId = undefined; response.activeTabId = undefined;
} }
} }
if ( details.popupLoggerBoxChanged && browser.windows instanceof Object ) {
browser.tabs.query(
{ url: vAPI.getURL('/logger-ui.html?popup=1') },
tabs => {
if ( Array.isArray(tabs) === false ) { return; }
if ( tabs.length === 0 ) { return; }
browser.windows.get(
tabs[0].windowId,
{ windowTypes: [ 'popup' ] },
win => {
if ( win instanceof Object === false ) { return; }
vAPI.localStorage.setItem(
'popupLoggerBox',
JSON.stringify({
left: win.left,
top: win.top,
width: win.width,
height: win.height,
})
);
}
);
}
);
}
callback(response); callback(response);
}; };
/******************************************************************************/ /******************************************************************************/
var getURLFilteringData = function(details) { const getURLFilteringData = function(details) {
var colors = {}; const colors = {};
var response = { const response = {
dirty: false, dirty: false,
colors: colors colors: colors
}; };
var suf = µb.sessionURLFiltering; const suf = µb.sessionURLFiltering;
var puf = µb.permanentURLFiltering; const puf = µb.permanentURLFiltering;
var urls = details.urls, const urls = details.urls;
context = details.context, const context = details.context;
type = details.type; const type = details.type;
var url, colorEntry; for ( const url of urls ) {
var i = urls.length; const colorEntry = colors[url] = { r: 0, own: false };
while ( i-- ) {
url = urls[i];
colorEntry = colors[url] = { r: 0, own: false };
if ( suf.evaluateZ(context, url, type).r !== 0 ) { if ( suf.evaluateZ(context, url, type).r !== 0 ) {
colorEntry.r = suf.r; colorEntry.r = suf.r;
colorEntry.own = suf.r !== 0 && suf.context === context && suf.url === url && suf.type === type; colorEntry.own = suf.r !== 0 &&
} suf.context === context &&
if ( response.dirty ) { suf.url === url &&
continue; suf.type === type;
} }
if ( response.dirty ) { continue; }
puf.evaluateZ(context, url, type); puf.evaluateZ(context, url, type);
response.dirty = colorEntry.own !== (puf.r !== 0 && puf.context === context && puf.url === url && puf.type === type); response.dirty = colorEntry.own !== (
puf.r !== 0 &&
puf.context === context &&
puf.url === url &&
puf.type === type
);
} }
return response; return response;
}; };
/******************************************************************************/ /******************************************************************************/
var onMessage = function(request, sender, callback) { const onMessage = function(request, sender, callback) {
// Async // Async
switch ( request.what ) { switch ( request.what ) {
case 'readAll': case 'readAll':
@ -1212,7 +1240,7 @@ var onMessage = function(request, sender, callback) {
} }
// Sync // Sync
var response; let response;
switch ( request.what ) { switch ( request.what ) {
case 'releaseView': case 'releaseView':

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock Origin - a browser extension to block requests. uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2018 Raymond Hill Copyright (C) 2014-present Raymond Hill
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -365,6 +365,21 @@
); );
} }
details.popup = this.userSettings.alwaysDetachLogger; details.popup = this.userSettings.alwaysDetachLogger;
if ( details.popup ) {
const url = new URL(vAPI.getURL(details.url));
url.searchParams.set('popup', '1');
details.url = url.href;
let popupLoggerBox;
try {
popupLoggerBox = JSON.parse(
vAPI.localStorage.getItem('popupLoggerBox')
);
} catch(ex) {
}
if ( popupLoggerBox !== undefined ) {
details.box = popupLoggerBox;
}
}
} }
vAPI.tabs.open(details); vAPI.tabs.open(details);
}; };