From 51e0ce6ad1efeedb98e4d90126f80a8c7d3ed6f6 Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 24 Apr 2015 08:36:19 -0400 Subject: [PATCH] this fixes #87 --- src/css/popup.css | 37 +++++++++------ src/js/messaging.js | 107 ++++++++++++++++++++++++-------------------- src/js/popup.js | 22 ++++++++- src/popup.html | 4 +- 4 files changed, 103 insertions(+), 67 deletions(-) diff --git a/src/css/popup.css b/src/css/popup.css index 4293faf33..32c2b5267 100644 --- a/src/css/popup.css +++ b/src/css/popup.css @@ -186,15 +186,15 @@ body.advancedUser #panes.dfEnabled h2:before { #refresh { background-color: #ffe; - border: 1px solid #eec; + border: 1px solid #ddc; border-radius: 4px; bottom: 0.7em; color: #888; cursor: pointer; display: none; - font-size: 40px; + font-size: 42px; left: 4px; - line-height: 40px; + line-height: 1; padding: 4px 8px; position: absolute; right: 4px; @@ -431,22 +431,31 @@ body.dirty #refresh:hover { visibility: hidden; } -#saveRules { - background-color: #ffe; - border: 1px solid #eec; - border-radius: 4px; +#rulesetTools { + background-color: transparent; + border: 0; color: #888; - cursor: pointer; display: none; - font-size: 30px; - line-height: 40px; - padding: 0.1em 0.4em; + padding: 0; position: fixed; - text-align: center; } -#firewallContainer.dirty ~ #saveRules { +#rulesetTools > span { + background-color: #ffe; + border: 1px solid #ddc; + border-radius: 4px; + cursor: pointer; + display: inline-block; + font-size: 1.7em; + line-height: 1.0; + margin: 0; + margin-right: 0.1em; + padding: 0.2em 0.4em; + text-align: center; + width: 1em; + } +#firewallContainer.dirty ~ #rulesetTools { display: block; } -#firewallContainer.dirty ~ #saveRules:hover { +#firewallContainer.dirty ~ #rulesetTools > span:hover { color: black; } diff --git a/src/js/messaging.js b/src/js/messaging.js index d3f89f3df..e880789ec 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -307,23 +307,23 @@ var getPopupDataLazy = function(tabId, callback) { var onMessage = function(request, sender, callback) { // Async switch ( request.what ) { - case 'getPopupDataLazy': - getPopupDataLazy(request.tabId, callback); - return; + case 'getPopupDataLazy': + getPopupDataLazy(request.tabId, callback); + return; - case 'getPopupData': - if ( request.tabId === vAPI.noTabId ) { - callback(getStats(vAPI.noTabId, '')); - return; - } - vAPI.tabs.get(request.tabId, function(tab) { - // https://github.com/chrisaljoudi/uBlock/issues/1012 - callback(getStats(getTargetTabId(tab), tab ? tab.title : '')); - }); + case 'getPopupData': + if ( request.tabId === vAPI.noTabId ) { + callback(getStats(vAPI.noTabId, '')); return; + } + vAPI.tabs.get(request.tabId, function(tab) { + // https://github.com/chrisaljoudi/uBlock/issues/1012 + callback(getStats(getTargetTabId(tab), tab ? tab.title : '')); + }); + return; - default: - break; + default: + break; } // Sync @@ -331,46 +331,55 @@ var onMessage = function(request, sender, callback) { var response; switch ( request.what ) { - case 'gotoPick': - // Picker launched from popup: clear context menu args - µb.contextMenuClientX = -1; - µb.contextMenuClientY = -1; - µb.elementPickerExec(request.tabId); - if ( request.select && vAPI.tabs.select ) { - vAPI.tabs.select(request.tabId); - } - break; + case 'gotoPick': + // Picker launched from popup: clear context menu args + µb.contextMenuClientX = -1; + µb.contextMenuClientY = -1; + µb.elementPickerExec(request.tabId); + if ( request.select && vAPI.tabs.select ) { + vAPI.tabs.select(request.tabId); + } + break; - case 'hasPopupContentChanged': - pageStore = µb.pageStoreFromTabId(request.tabId); - var lastModified = pageStore ? pageStore.contentLastModified : 0; - response = lastModified !== request.contentLastModified; - break; + case 'hasPopupContentChanged': + pageStore = µb.pageStoreFromTabId(request.tabId); + var lastModified = pageStore ? pageStore.contentLastModified : 0; + response = lastModified !== request.contentLastModified; + break; - case 'saveFirewallRules': - µb.permanentFirewall.copyRules( - µb.sessionFirewall, - request.srcHostname, - request.desHostnames - ); - µb.savePermanentFirewallRules(); - break; + case 'revertFirewallRules': + µb.sessionFirewall.copyRules( + µb.permanentFirewall, + request.srcHostname, + request.desHostnames + ); + response = getStats(request.tabId); + break; - case 'toggleFirewallRule': - µb.toggleFirewallRule(request); - response = getStats(request.tabId); - break; + case 'saveFirewallRules': + µb.permanentFirewall.copyRules( + µb.sessionFirewall, + request.srcHostname, + request.desHostnames + ); + µb.savePermanentFirewallRules(); + break; - case 'toggleNetFiltering': - pageStore = µb.pageStoreFromTabId(request.tabId); - if ( pageStore ) { - pageStore.toggleNetFilteringSwitch(request.url, request.scope, request.state); - µb.updateBadgeAsync(request.tabId); - } - break; + case 'toggleFirewallRule': + µb.toggleFirewallRule(request); + response = getStats(request.tabId); + break; - default: - return vAPI.messaging.UNHANDLED; + case 'toggleNetFiltering': + pageStore = µb.pageStoreFromTabId(request.tabId); + if ( pageStore ) { + pageStore.toggleNetFilteringSwitch(request.url, request.scope, request.state); + µb.updateBadgeAsync(request.tabId); + } + break; + + default: + return vAPI.messaging.UNHANDLED; } callback(response); diff --git a/src/js/popup.js b/src/js/popup.js index b5a65062c..ba281d022 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -47,7 +47,7 @@ document.querySelector('#panes > div:nth-of-type(2)').style.setProperty( // The padlock must be manually positioned: // - It's vertical position depends on the height on the title bar. -document.getElementById('saveRules').style.setProperty( +document.getElementById('rulesetTools').style.setProperty( 'top', (document.getElementById('gotoPrefs').getBoundingClientRect().bottom + 4) + 'px' ); @@ -329,7 +329,7 @@ var buildAllFirewallRows = function() { // - Its horizontal position depends on whether there is a vertical // scrollbar. var rect = document.getElementById('firewallContainer').getBoundingClientRect(); - document.getElementById('saveRules').style.setProperty('left', (rect.left + 4) + 'px'); + document.getElementById('rulesetTools').style.setProperty('left', (rect.left + 4) + 'px'); updateAllFirewallCells(); }; @@ -678,6 +678,23 @@ var saveFirewallRules = function() { /******************************************************************************/ +var revertFirewallRules = function() { + var onFirewallRuleChanged = function(response) { + cachePopupData(response); + updateAllFirewallCells(); + hashFromPopupData(); + }; + messager.send({ + what: 'revertFirewallRules', + srcHostname: popupData.pageHostname, + desHostnames: popupData.hostnameDict, + tabId: popupData.tabId + }, onFirewallRuleChanged); + uDom('#firewallContainer').removeClass('dirty'); +}; + +/******************************************************************************/ + var toggleHostnameSwitch = function() { var elem = uDom(this); var switchName = elem.attr('id'); @@ -815,6 +832,7 @@ uDom.onLoad(function () { uDom('#refresh').on('click', reloadTab); uDom('.hnSwitch').on('click', toggleHostnameSwitch); uDom('#saveRules').on('click', saveFirewallRules); + uDom('#revertRules').on('click', revertFirewallRules); uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize); uDom('body').on('mouseenter', '[data-tip]', onShowTooltip) diff --git a/src/popup.html b/src/popup.html index 2d362d0b4..c54bd6e1a 100644 --- a/src/popup.html +++ b/src/popup.html @@ -2,7 +2,7 @@ - + @@ -41,7 +41,7 @@
-
+