From 74981341e817bce117af2695aaa55da907200daa Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 18 Mar 2015 13:00:07 -0400 Subject: [PATCH] attempt at addressing #514, #518 --- src/css/devtool-log.css | 4 +-- src/css/devtools.css | 19 +++++++++++++ src/devtools.html | 2 ++ src/js/devtools.js | 61 +++++++++++++++++++++++++++++++++++++++++ src/js/messaging.js | 4 +++ 5 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src/css/devtool-log.css b/src/css/devtool-log.css index d3ea119ab..69d392a98 100644 --- a/src/css/devtool-log.css +++ b/src/css/devtool-log.css @@ -14,12 +14,12 @@ body { border: 0; box-sizing: border-box; height: 36px; + left: 1em; margin: 0; padding: 0; position: fixed; text-align: center; top: 0; - width: 100%; } #toolbar .button { background-color: white; @@ -105,4 +105,4 @@ body:not(.filterOff) #content table tr.hidden { } #content table tr.allowed td:nth-of-type(4) b { background-color: rgba(0, 160, 0, 0.2); - } \ No newline at end of file + } diff --git a/src/css/devtools.css b/src/css/devtools.css index 44a5892fc..a33ae379b 100644 --- a/src/css/devtools.css +++ b/src/css/devtools.css @@ -17,6 +17,7 @@ body { } #toolbar > * { display: inline-block; + position: relative; vertical-align: middle; } #toolbar button { @@ -42,6 +43,14 @@ select { select option { max-width: 40em; } +#popupToggler { + opacity: 0.25; + position: absolute; + right: 0; + } +body.popupEnabled #popupToggler { + opacity: 1; + } #content { border: 0; box-sizing: border-box; @@ -52,3 +61,13 @@ select option { padding: 0; width: 100%; } +#popup { + border: 1px solid gray; + display: none; + position: fixed; + right: 2px; + top: calc(4em + 2px); + } +body.popupEnabled #popup[src^="popup.html"] { + display: initial; + } diff --git a/src/devtools.html b/src/devtools.html index f2daaec25..9f4832c0c 100644 --- a/src/devtools.html +++ b/src/devtools.html @@ -14,8 +14,10 @@
+
+ diff --git a/src/js/devtools.js b/src/js/devtools.js index da8ed5570..17a783a55 100644 --- a/src/js/devtools.js +++ b/src/js/devtools.js @@ -78,6 +78,7 @@ var selectPage = function() { return; } inspector.attr('src', targetSrc); + uDom('#popup').attr('src', tabId ? 'popup.html?tabId=' + tabId : ''); // This is useful for when the user force-refresh the page: this will // prevent a reset to the original request log. @@ -93,6 +94,63 @@ var selectPage = function() { /******************************************************************************/ +var togglePopup = function() { + var tabId = uDom('#pageSelector').val() || ''; + var body = uDom('body'); + body.toggleClass('popupEnabled'); + if ( body.hasClass('popupEnabled') === false ) { + tabId = ''; + } + uDom('#popup').attr('src', tabId ? 'popup.html?tabId=' + tabId : ''); +}; + +/******************************************************************************/ + +var resizePopup = function() { + var popup = document.getElementById('popup'); + popup.style.width = popup.contentWindow.document.body.clientWidth + 'px'; + popup.style.height = popup.contentWindow.document.body.clientHeight + 'px'; +}; + +/******************************************************************************/ + +var onPopupLoaded = function() { + resizePopup(); + + if ( popupObserver !== null ) { + popupObserver.disconnect(); + } + + var popup = document.getElementById('popup'); + if ( popup.contentDocument === null ) { + return; + } + var popupBody = popup.contentDocument.body; + if ( popupBody === null ) { + return; + } + var popupPanes = popup.contentDocument.getElementById('panes'); + if ( popupPanes === null ) { + return; + } + + if ( popupObserver === null ) { + popupObserver = new MutationObserver(resizePopup); + } + + var details = { + childList: false, + attributes: true, + attributeFilter: ['class'] + }; + popupObserver.observe(popupBody, details); + popupObserver.observe(popupPanes, details); +}; + +var popupObserver = null; + +/******************************************************************************/ + uDom.onLoad(function() { var tabId; @@ -102,6 +160,9 @@ uDom.onLoad(function() { tabId = matches[1]; } + uDom('#popupToggler').on('click', togglePopup); + uDom('#popup').on('load', onPopupLoaded); + renderPageSelector(tabId); uDom('#pageSelector').on('change', pageSelectorChanged); diff --git a/src/js/messaging.js b/src/js/messaging.js index eea5110a2..f11de5ef3 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -281,6 +281,10 @@ var onMessage = function(request, sender, callback) { // Async switch ( request.what ) { case 'getPopupData': + if ( request.tabId === vAPI.noTabId ) { + callback(getStats(vAPI.noTabId, '')); + return; + } vAPI.tabs.get(request.tabId, function(tab) { // https://github.com/gorhill/uBlock/issues/1012 callback(getStats(getTargetTabId(tab), tab ? tab.title : ''));