Skip to content

Commit

Permalink
Autoformatted JS files (using jsbeautify)
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgrossman committed Nov 16, 2016
1 parent fb28e47 commit 05915b5
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 143 deletions.
8 changes: 8 additions & 0 deletions .jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"brace_style": "collapse-preserve-inline",
"preserve_newlines": true,
"max_preserve_newlines": 10,
"indent_size": 4,
"indent_with_tabs": true,
"end_with_newline": false
}
41 changes: 32 additions & 9 deletions chrome-extension/html/options.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
<!-- Options screen - shown: (1) when clicking the extension icon in Chrome's toolbar; (2) on chrome://extensions/ when clicking "Options" -->
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Darkness</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,300' rel='stylesheet' type='text/css'>
</head>
<style>
body { width: 400px; background: #000; color: #ccc; font-size: 14px; padding: 7px 10px; line-height: 1.7em; font-family: 'Open Sans'; font-weight: 300; }

b { font-weight: 300; color: #fff; }

h3 { font-size: 17px; font-weight: 400; color: #fff; padding: 0 0 10px; margin: 0; }
body {
width: 400px;
background: #000;
color: #ccc;
font-size: 14px;
padding: 7px 10px;
line-height: 1.7em;
font-family: 'Open Sans';
font-weight: 300;
}

b {
font-weight: 300;
color: #fff;
}

h3 {
font-size: 17px;
font-weight: 400;
color: #fff;
padding: 0 0 10px;
margin: 0;
}
</style>

<body>
<h3>To configure Darkness:</h3>
1. Visit a supported website like <b>Facebook</b> or <b>Google</b>.<BR>
2. Click the <b>moon icon</b> in the <b>top-right corner</b> of the website.<BR><BR>
<img src="../images/explain-icon-location.png"/>
<h3>To configure Darkness:</h3>
1. Visit a supported website like <b>Facebook</b> or <b>Google</b>.
<BR> 2. Click the <b>moon icon</b> in the <b>top-right corner</b> of the website.
<BR>
<BR>
<img src="../images/explain-icon-location.png" />
</body>

</html>
80 changes: 38 additions & 42 deletions chrome-extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ var getSiteKeyForUrl = function(url) {
var returnedSiteKey = siteKey;
if (themeSupport == 'ask-developers') {
// In production mode ask developers to join us, in development mode there's no need
returnedSiteKey = (ENVIRONMENT == 'development') ? null: siteKey;
}
else if (themeSupport == 'in-development') {
returnedSiteKey = (ENVIRONMENT == 'development') ? null : siteKey;
} else if (themeSupport == 'in-development') {
// In production mode don't skin this website, in development mode do
returnedSiteKey = (ENVIRONMENT == 'development') ? siteKey : null;
}
Expand All @@ -64,8 +63,7 @@ var whichThemeForSite = function(debug, siteKey, canPreview) {
// Has user settings
if (debug) log('Which theme for ' + siteKey + '?' + ' User settings says ' + themeFromSettings);
themeKey = themeFromSettings;
}
else {
} else {
// No user settings, use default
var defaultTheme = CONFIG.sites[siteKey].p ? 'none' : settings.global.get('defaultTheme');
if (debug) log('Which theme for ' + siteKey + '?' + ' No user settings. Default says ' + defaultTheme);
Expand All @@ -83,8 +81,7 @@ var whichThemeForSite = function(debug, siteKey, canPreview) {
// Pro website? Set back to none
if (debug) log('Preview mode off. Resetting theme back to none');
themeKey = 'none';
}
else if (CONFIG.themes[themeKey].p) {
} else if (CONFIG.themes[themeKey].p) {
themeKey = CONFIG.defaultTheme;
// Pro theme? Set back to default theme
if (debug) log('Preview mode off. Resetting theme back to default: ' + themeKey);
Expand Down Expand Up @@ -168,7 +165,7 @@ var reloadUserUntilPro = function(success, callback) {
// Payment returned success
if (userType == 'p') {
// Pro user - return success
callback({type: userType});
callback({ type: userType });
} else {
if (reloadUserInterval < 20000) {
// Non-pro user - keep trying
Expand All @@ -180,14 +177,14 @@ var reloadUserUntilPro = function(success, callback) {
} else {
// Non-pro user - timeout
log('I give up');
callback({type: userType});
callback({ type: userType });
}
}
} else {
// Payment returned failure
// Return failure immediately
log('Reload called once due to failure');
callback({type: userType});
callback({ type: userType });
}
});
};
Expand All @@ -196,13 +193,13 @@ var reloadUserUntilPro = function(success, callback) {
// Check the specified promo code with Darkness' servers
var checkPromoCode = function(code, sendResponse) {
code = parseInt(code) || 0;
var params = {'machineId': stats.get('userId'), 'code': code, 'token': Math.floor(Math.random() * 99999) + 1};
var params = { 'machineId': stats.get('userId'), 'code': code, 'token': Math.floor(Math.random() * 99999) + 1 };
log('Checking promo for ' + JSON.stringify(params));
var onServerResponse = function(err, res) {
if (err) {
log('Promo server error: ' + code);
repEvent('user-action', 'prmo-server-error', code);
sendResponse({success: false});
sendResponse({ success: false });
}
if (res) {
console.log(res);
Expand All @@ -218,19 +215,18 @@ var checkPromoCode = function(code, sendResponse) {
repEvent('user-action', 'prmo-correct', code);
settings.global.set('override', 'prmo' + code);
reloadUser(function() {
sendResponse({success: true});
sendResponse({ success: true });
})
}
else {
} else {
log('Promo server invalid: ' + code);
repEvent('user-action', 'prmo-server-invalid', code);
sendResponse({success: false});
sendResponse({ success: false });
}

} else {
log('Promo incorrect: ' + code);
repEvent('user-action', 'prmo-incorrect', code);
sendResponse({success: false});
sendResponse({ success: false });
}
}
};
Expand All @@ -245,7 +241,7 @@ var checkPromoCode = function(code, sendResponse) {
// Callback returns: errorString, paidBoolean
var checkGooglePayments = function(callback) {
google.payments.inapp.getPurchases({
'parameters': {'env': 'prod'},
'parameters': { 'env': 'prod' },
'success': function(res) {
log('getPurchases success:', res);
if (!res.response || typeof(res.response.details) != 'object') return callback('getPurchases no response', false);
Expand Down Expand Up @@ -351,7 +347,7 @@ var queryPayPalStatusPeriodically = function() {
var queryPayPalStatusNow = function() {
var now = (new Date()).getTime();
stats.set('paypalCheckedTime', now);
var params = {'machineId': stats.get('userId'), 'transactionId': paypalTransacationId};
var params = { 'machineId': stats.get('userId'), 'transactionId': paypalTransacationId };
log('Checking IPN status for ' + JSON.stringify(params));
var onServerResponse = function(err, res) {
if (err) {
Expand Down Expand Up @@ -432,7 +428,7 @@ chrome.runtime.onMessage.addListener(
case 'loadTheme':
// Load the specified theme, then return the CSS that the client needs to inject to show that theme
replaceThemeAndGetCss(sender.tab, request.theme, function(cssContent) {
sendResponse({'cssContent': cssContent});
sendResponse({ 'cssContent': cssContent });
});
return true; // Don't call sendResponse automatically - tell Chrome we wish to call it later (async)

Expand Down Expand Up @@ -461,10 +457,10 @@ chrome.runtime.onMessage.addListener(
// Get the most recent settings from the background script to the client side
var siteKey = getSiteKeyForUrl(sender.tab.url);
var themeKey = siteKey ? whichThemeForSite(true, siteKey, false) : 'none';
sendResponse({newSettings: settings.getAllSettingsClone(), newTheme: themeKey});
sendResponse({ newSettings: settings.getAllSettingsClone(), newTheme: themeKey });
return false;

// ===== ANALYTICS =====
// ===== ANALYTICS =====

case 'repToFunnel':
// Report a step in the funnel of Darkness Pro
Expand All @@ -481,7 +477,7 @@ chrome.runtime.onMessage.addListener(
repEvent(request.cat, request.act, request.lab);
return false;

// ===== MISC =====
// ===== MISC =====

case 'openSettings':
// Load the settings dialog, by injecting settings.js into the active tab
Expand Down Expand Up @@ -545,7 +541,7 @@ var getAssetsForSettingsPanel = function(callback) {

// Return all the assets
// This should an exact match of "var ASSETS" in settings.js (client side)
var args = {'CSS': cssContent, 'CSSOFF': noThemeCssContent, 'HTML': htmlContent, 'TYPE': stats.get('type')};
var args = { 'CSS': cssContent, 'CSSOFF': noThemeCssContent, 'HTML': htmlContent, 'TYPE': stats.get('type') };
callback(args);
});
};
Expand Down Expand Up @@ -643,20 +639,19 @@ var injectPageJsToTab = function(tab, siteKey, themeKey) {
var noThemeCssContent = readFileFromCache("style-css/page.css");

// All the arguments required by page.js
var code = getCodeForInjection("js/page.js",
{
'HTML': htmlContent,
'CSS': cssContent,
'CSSOFF': noThemeCssContent,

'SETTINGS': JSON.stringify(settings.getAllSettingsClone()),
'TYPE': stats.get('type'),
'SITE': siteKey,
'SITE_SUPPORT': CONFIG.sites[siteKey].support,

'ENVIRONMENT': ENVIRONMENT,
'MACHINEID': stats.get('userId')
});
var code = getCodeForInjection("js/page.js", {
'HTML': htmlContent,
'CSS': cssContent,
'CSSOFF': noThemeCssContent,

'SETTINGS': JSON.stringify(settings.getAllSettingsClone()),
'TYPE': stats.get('type'),
'SITE': siteKey,
'SITE_SUPPORT': CONFIG.sites[siteKey].support,

'ENVIRONMENT': ENVIRONMENT,
'MACHINEID': stats.get('userId')
});

// Inject it to page
chrome.tabs.executeScript(tab.id, {
Expand Down Expand Up @@ -741,7 +736,8 @@ var retroactivelyInitExistingTabs = function() {
var loadAllAssetsToCache = function(debug, callback) {

// Get keys of all supported sites & themes
var themeKeys = [], siteKeys = [];
var themeKeys = [],
siteKeys = [];
for (var i in CONFIG.themes) themeKeys.push(CONFIG.themes[i].key);
for (i in CONFIG.sites) siteKeys.push(CONFIG.sites[i].key);
if (debug) {
Expand Down Expand Up @@ -774,10 +770,10 @@ var initializeConfiguration = function() {
// Chrome runtime configuration setup
chrome.runtime.setUninstallURL("http://improvver.com/darkness/extension/uninstalled");

chrome.runtime.onInstalled.addListener(function (details) {
chrome.runtime.onInstalled.addListener(function(details) {
log("Chrome invoked onInstalled: ", details);
if (details && details.reason == "install") {
chrome.tabs.create({url: "http://improvver.com/darkness/extension/thank-you"}, function(tab) {
chrome.tabs.create({ url: "http://improvver.com/darkness/extension/thank-you" }, function(tab) {
log("Thank you page opened");
});
}
Expand Down Expand Up @@ -843,4 +839,4 @@ var initializeBackgroundScript = function() {
});
};

initializeBackgroundScript();
initializeBackgroundScript();
14 changes: 7 additions & 7 deletions chrome-extension/js/background/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var initializeAnalyticsOnStart = function() {
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
Expand All @@ -41,10 +41,10 @@ var initializeAnalyticsOnStart = function() {
var initializeAnalyticsAfterLoad = function() {
// Anonymously report extension is alive every 24h
repUserActive();
setInterval(function() {repUserActive()}, 1000 * 60 * 5); // 5 minutes
setInterval(function() { repUserActive() }, 1000 * 60 * 5); // 5 minutes

// Anonymously report current domain randomally. No user identifying info is sent
setInterval(function() {repCurrentDomainAnonymously()}, 1000 * 60); // 1 minute
setInterval(function() { repCurrentDomainAnonymously() }, 1000 * 60); // 1 minute
};

//----------------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -59,7 +59,7 @@ var _reportPageview = function(path, title) {
var analyticsLoaded = typeof(ga) != 'undefined';
if (DEBUG_ANALYTICS) logWarn((analyticsLoaded ? 'Sending pageview:' : 'Not sending pageview:'), path);
if (analyticsLoaded) {
ga('send', {hitType: 'pageview', page: path, title: title});
ga('send', { hitType: 'pageview', page: path, title: title });
}
};

Expand Down Expand Up @@ -115,7 +115,7 @@ var repCurrentDomainAnonymously = function() {
var EVERY_N_CALLS = 1000; // Send a statistical sample
if (Math.random() * EVERY_N_CALLS <= 1) {
// Get the domain of the current tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
if (tabs[0]) {
var tab = tabs[0];
var host = _getHostByUrl(tab.url);
Expand Down Expand Up @@ -166,4 +166,4 @@ var repEventByUser = function(category, action) {
// Report a step in the funnel of Darkness Pro
var repToFunnel = function(step) {
_reportPageview('/pro-funnel/' + step, step);
};
};
Loading

0 comments on commit 05915b5

Please sign in to comment.