Core features implemented.
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
assets/js/helpers/contains.js
Normal file
21
assets/js/helpers/contains.js
Normal 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;
|
||||
Reference in New Issue
Block a user