this fixes #87

This commit is contained in:
gorhill 2015-04-24 08:36:19 -04:00
parent 1cec79195e
commit 51e0ce6ad1
4 changed files with 103 additions and 67 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta name="viewport" content="width=470"> <!-- When showing as a tab in fennec, scale to full size (150px + 320px)-->
<meta name="viewport" content="width=470"><!-- When showing as a tab in fennec, scale to full size (150px + 320px) -->
<meta charset="utf-8">
<link rel="stylesheet" href="css/common.css" type="text/css">
<link rel="stylesheet" href="css/popup.css" type="text/css">
@ -41,7 +41,7 @@
<div><span data-i18n="popup1pScriptRulePrompt"></span><span data-src="/" data-des="*" data-type="1p-script"> </span><span data-src="." data-des="*" data-type="1p-script"> </span></div>
<div><span data-i18n="popup3pScriptRulePrompt"></span><span data-src="/" data-des="*" data-type="3p-script"> </span><span data-src="." data-des="*" data-type="3p-script"> </span></div>
<div><span data-i18n="popup3pFrameRulePrompt"></span><span data-src="/" data-des="*" data-type="3p-frame"> </span><span data-src="." data-des="*" data-type="3p-frame"> </span></div>
</div><div id="saveRules" class="fa">&#xf13e;</div>
</div><div id="rulesetTools"><span id="saveRules" class="fa">&#xf023;</span><span id="revertRules" class="fa">&#xf12d;</span></div>
</div>
</div>