Core features implemented.

This commit is contained in:
Mario Basic
2015-06-18 17:28:46 +02:00
parent f98e2d09d9
commit fb6e8bee75
8 changed files with 384 additions and 199 deletions

View File

@@ -32,7 +32,9 @@ var config = {
tooltips: {
allGood: '',
notLogging: 'Not logging',
notSignedIn: 'Not signed In'
notSignedIn: 'Not signed In',
blacklisted: 'This URL is blacklisted',
whitelisted: 'This URL is not on your whitelist'
},
// Default theme
theme: 'light',

View File

@@ -11,6 +11,7 @@ var getDomainFromUrl = require('./../helpers/getDomainFromUrl');
var currentTimestamp = require('./../helpers/currentTimestamp');
var changeExtensionState = require('../helpers/changeExtensionState');
var in_array = require('./../helpers/in_array');
var contains = require('./../helpers/contains');
class WakaTime {
@@ -88,7 +89,10 @@ class WakaTime {
if (data !== false) {
chrome.storage.sync.get({
loggingEnabled: config.loggingEnabled
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
blacklist: '',
whitelist: ''
}, (items) => {
if (items.loggingEnabled === true) {
@@ -99,11 +103,33 @@ class WakaTime {
if (newState === 'active') {
// Get current tab URL.
chrome.tabs.query({active: true}, (tabs) => {
var currentActiveTab = tabs[0];
var debug = false;
// If the current active tab has devtools open
if (in_array(tabs[0].id, this.tabsWithDevtoolsOpen)) debug = true;
if (in_array(currentActiveTab.id, this.tabsWithDevtoolsOpen)) debug = true;
if (items.loggingStyle == 'blacklist') {
if (! contains(currentActiveTab.url, items.blacklist)) {
this.sendHeartbeat(currentActiveTab.url, debug);
}
else {
changeExtensionState('blacklisted');
console.log(currentActiveTab.url + ' is on a blacklist.');
}
}
if (items.loggingStyle == 'whitelist') {
if (contains(currentActiveTab.url, items.whitelist)) {
this.sendHeartbeat(currentActiveTab.url, debug);
}
else {
changeExtensionState('whitelisted');
console.log(currentActiveTab.url + ' is not on a whitelist.');
}
}
this.sendHeartbeat(tabs[0].url, debug);
});
}
});

View File

@@ -28,6 +28,14 @@ function changeExtensionState(state) {
changeExtensionIcon(config.colors.notSignedIn);
changeExtensionTooltip(config.tooltips.notSignedIn);
break;
case 'blacklisted':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.blacklisted);
break;
case 'whitelisted':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.whitelisted);
break;
}
}

View File

@@ -0,0 +1,21 @@
/**
* Creates an array from list using \n as delimiter
* and checks if the line is located in the list.
*
* @param line
* @param list
* @returns {boolean}
*/
function contains(line, list) {
var lines = list.split('\n');
for (var i = 0; i < lines.length; i ++) {
if (line.indexOf(lines[i]) > - 1) {
return true;
}
}
return false;
}
module.exports = contains;