From fa5e4b7769c9759a588a4b842d79d3273c5756df Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 15 Dec 2022 10:04:59 -0500 Subject: [PATCH] Fine tune new exceptor code Related feedback: - https://github.com/gorhill/uBlock/commit/a91781a4959c0381c8ab3230545e4e0f579d4a2c#commitcomment-93128519 For instance, do not make exceptor widget available for exceptions from filter lists. --- src/js/logger-ui.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index 87f2e1167..f97d86745 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -1124,6 +1124,7 @@ const reloadTab = function(ev) { 'csp_report': 'other', }; const createdStaticFilters = {}; + const reIsExceptionFilter = /^@@|^[\w.-]*?#@#/; let dialog = null; let targetRow = null; @@ -1136,7 +1137,7 @@ const reloadTab = function(ev) { let targetPageDomain; let targetFrameDomain; - const uglyTypeFromSelector = function(pane) { + const uglyTypeFromSelector = pane => { const prettyType = selectValue('select.type.' + pane); if ( pane === 'static' ) { return staticFilterTypes[prettyType] || prettyType; @@ -1144,18 +1145,23 @@ const reloadTab = function(ev) { return uglyRequestTypes[prettyType] || prettyType; }; - const selectNode = function(selector) { + const selectNode = selector => { return qs$(dialog, selector); }; - const selectValue = function(selector) { + const selectValue = selector => { return selectNode(selector).value || ''; }; - const staticFilterNode = function() { + const staticFilterNode = ( ) => { return qs$(dialog, 'div.panes > div.static textarea'); }; + const toExceptionFilter = (filter, extended) => { + if ( reIsExceptionFilter.test(filter) ) { return filter; } + return extended ? filter.replace('##', '#@#') : `@@${filter}`; + }; + const onColorsReady = function(response) { dom.cl.toggle(dom.body, 'dirty', response.dirty); for ( const url in response.colors ) { @@ -1247,12 +1253,9 @@ const reloadTab = function(ev) { if ( tcl.contains('exceptor') ) { ev.stopPropagation(); const filter = filterFromTargetRow(); - const exceptedFilter = dom.cl.has(targetRow, 'extendedRealm') - ? `#@#${filter.replace(/^.*?#@?#/, '')}` - : `@@${filter.replace(/^@@/, '')}`; const status = await messaging.send('loggerUI', { what: 'toggleInMemoryFilter', - filter: exceptedFilter, + filter: toExceptionFilter(filter, dom.cl.has(targetRow, 'extendedRealm')), }); const row = target.closest('div'); dom.cl.toggle(row, 'exceptored', status); @@ -1480,16 +1483,17 @@ const reloadTab = function(ev) { const toSummaryPaneFilterNode = async function(receiver, filter) { receiver.children[1].textContent = filter; - if ( filterAuthorMode !== true ) { return; } if ( dom.cl.has(targetRow, 'canLookup') === false ) { return; } - const exceptedFilter = dom.cl.has(targetRow, 'extendedRealm') - ? `#@#${filter.replace(/^.*?#@?#/, '')}` - : `@@${filter.replace(/^@@/, '')}`; - const isTemporaryException = await messaging.send('loggerUI', { - what: 'hasInMemoryFilter', - filter: exceptedFilter, - }); - dom.cl.toggle(receiver, 'exceptored', isTemporaryException); + const isException = reIsExceptionFilter.test(filter); + let isExcepted = false; + if ( isException ) { + isExcepted = await messaging.send('loggerUI', { + what: 'hasInMemoryFilter', + filter: toExceptionFilter(filter, dom.cl.has(targetRow, 'extendedRealm')), + }); + } + if ( isException && isExcepted === false ) { return; } + dom.cl.toggle(receiver, 'exceptored', isExcepted); receiver.children[2].style.visibility = ''; };