Major optimizations. Added a function for extension state. Tooltip is now being change also.

This commit is contained in:
Mario Basic
2015-06-13 22:07:39 +02:00
parent 3331d187b6
commit b8ca450969
21 changed files with 1211 additions and 1010 deletions

View File

@@ -1,8 +1,12 @@
var config = require('../config');
/**
* It changes the extension icon color.
* Supported values are: 'red', 'white', 'gray' and ''.
*
* @param color
*/
export default function changeExtensionIcon(color = '') {
function changeExtensionIcon(color = '') {
var path = null;
@@ -18,9 +22,9 @@ export default function changeExtensionIcon(color = '') {
if (color === '') {
chrome.storage.sync.get({
theme: 'light'
theme: config.theme
}, function (items) {
if (items.theme == 'light') {
if (items.theme == config.theme) {
path = './graphics/wakatime-logo-38.png';
chrome.browserAction.setIcon({
@@ -38,3 +42,5 @@ export default function changeExtensionIcon(color = '') {
}
}
export default changeExtensionIcon;

View File

@@ -0,0 +1,34 @@
var config = require('../config');
// Helpers
var changeExtensionIcon = require('./changeExtensionIcon');
var changeExtensionTooltip = require('./changeExtensionTooltip');
var in_array = require('./in_array');
/**
* Sets the current state of the extension.
*
* @param state
*/
function changeExtensionState(state){
if (! in_array(state, config.states)) {
throw new Error('Not a valid state!');
}
switch (state) {
case 'allGood':
changeExtensionIcon(config.colors.allGood);
changeExtensionTooltip(config.tooltips.allGood);
break;
case 'notLogging':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.notLogging);
break;
case 'notSignedIn':
changeExtensionIcon(config.colors.notSignedIn);
changeExtensionTooltip(config.tooltips.notSignedIn);
break;
}
}
export default changeExtensionState;

View File

@@ -0,0 +1,20 @@
var config = require('../config');
/**
* It changes the extension title
*
* @param text
*/
function changeExtensionTooltip(text) {
if (text === '') {
text = config.name;
}
else {
text = config.name + ' - ' + text;
}
chrome.browserAction.setTitle({title: text});
}
export default changeExtensionTooltip;

View File

@@ -1,6 +1,10 @@
/**
* Returns UNIX timestamp
*
* @returns {number}
*/
export default function(){
function currentTimestamp(){
return Math.round((new Date()).getTime() / 1000);
}
export default currentTimestamp;

View File

@@ -0,0 +1,13 @@
/**
* Returns domain from given URL.
*
* @param url
* @returns {string}
*/
function getDomainFromUrl(url) {
var parts = url.split('/');
return parts[0] + "//" + parts[2];
}
export default getDomainFromUrl;

View File

@@ -1,3 +1,10 @@
/**
* Returns boolean if needle is found in haystack or not.
*
* @param needle
* @param haystack
* @returns {boolean}
*/
function in_array(needle, haystack) {
for (var i = 0; i < haystack.length; i ++) {
if (needle == haystack[i]) {