Skip to content

Commit

Permalink
code review re advanced settings + added popupFontSize
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 6, 2016
1 parent bc379a1 commit ee4fc2a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ return {
hiddenSettingsDefault: {
ignoreRedirectFilters: false,
ignoreScriptInjectFilters: false,
popupFontSize: 'unset',
suspendTabsUntilReady: false
},
// This will be filled ASAP:
Expand Down
5 changes: 3 additions & 2 deletions src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ var getFirewallRules = function(srcHostname, desHostnames) {
/******************************************************************************/

var popupDataFromTabId = function(tabId, tabTitle) {
var tabContext = µb.tabContextManager.mustLookup(tabId);
var rootHostname = tabContext.rootHostname;
var tabContext = µb.tabContextManager.mustLookup(tabId),
rootHostname = tabContext.rootHostname;
var r = {
advancedUserEnabled: µb.userSettings.advancedUserEnabled,
appName: vAPI.app.name,
Expand All @@ -294,6 +294,7 @@ var popupDataFromTabId = function(tabId, tabTitle) {
firewallPaneMinimized: µb.userSettings.firewallPaneMinimized,
globalAllowedRequestCount: µb.localSettings.allowedRequestCount,
globalBlockedRequestCount: µb.localSettings.blockedRequestCount,
fontSize: µb.hiddenSettings.popupFontSize,
netFilteringSwitch: false,
rawURL: tabContext.rawURL,
pageURL: tabContext.normalURL,
Expand Down
17 changes: 16 additions & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

/******************************************************************************/

var popupFontSize = vAPI.localStorage.getItem('popupFontSize');
if ( typeof popupFontSize === 'string' && popupFontSize !== 'unset' ) {
document.body.style.setProperty('font-size', popupFontSize);
}

// Ensure the popup is properly sized as soon as possible. It is assume the DOM
// content is ready at this point, which should be the case given where this
// script file is included in the HTML file.
Expand Down Expand Up @@ -100,7 +105,6 @@ var rowsToRecycle = uDom();
var cachedPopupHash = '';
var statsStr = vAPI.i18n('popupBlockedStats');
var domainsHitStr = vAPI.i18n('popupHitDomainCount');
var reNetworkRelatedURL = /^(?:ftps?|https?|wss?):\/\//;

/******************************************************************************/

Expand Down Expand Up @@ -386,6 +390,17 @@ var renderPrivacyExposure = function() {
// Assume everything has to be done incrementally.

var renderPopup = function() {
if ( popupData.fontSize !== popupFontSize ) {
popupFontSize = popupData.fontSize;
if ( popupFontSize !== 'unset' ) {
document.body.style.setProperty('font-size', popupFontSize);
vAPI.localStorage.setItem('popupFontSize', popupFontSize);
} else {
document.body.style.removeProperty('font-size');
vAPI.localStorage.removeItem('popupFontSize');
}
}

if ( popupData.tabTitle ) {
document.title = popupData.appName + ' - ' + popupData.tabTitle;
}
Expand Down
15 changes: 10 additions & 5 deletions src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,23 @@ var onAdminSettingsRestored = function() {
/******************************************************************************/

µb.hiddenSettings = (function() {
var json = vAPI.localStorage.getItem('hiddenSettings');
var out = objectAssign({}, µb.hiddenSettingsDefault),
json = vAPI.localStorage.getItem('hiddenSettings');
if ( typeof json === 'string' ) {
try {
var out = JSON.parse(json);
if ( out instanceof Object ) {
return out;
var o = JSON.parse(json);
if ( o instanceof Object ) {
for ( var k in o ) {
if ( out.hasOwnProperty(k) ) {
out[k] = o[k];
}
}
}
}
catch(ex) {
}
}
return objectAssign({}, µb.hiddenSettingsDefault);
return out;
})();

/******************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
out[name] = false;
}
break;
case 'string':
out[name] = value;
break;
default:
break;
}
Expand Down

0 comments on commit ee4fc2a

Please sign in to comment.