Added config for extension, updated a lot of things to use config. Updated icons.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -164,22 +164,13 @@ var _helpersChangeExtensionIconJs = require('./helpers/changeExtensionIcon.js');
|
||||
var _helpersChangeExtensionIconJs2 = _interopRequireDefault(_helpersChangeExtensionIconJs);
|
||||
|
||||
var in_array = require('./helpers/in_array');
|
||||
var config = require('./config.js');
|
||||
|
||||
var WakaTime = (function () {
|
||||
function WakaTime(props) {
|
||||
_classCallCheck(this, WakaTime);
|
||||
|
||||
this.tabsWithDevtoolsOpen = [];
|
||||
|
||||
this.detectionIntervalInSeconds = 60; //default
|
||||
|
||||
this.loggingType = 'domain'; //default
|
||||
|
||||
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
|
||||
|
||||
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
||||
|
||||
this.tabsWithDevtoolsOpen = [];
|
||||
}
|
||||
|
||||
_createClass(WakaTime, [{
|
||||
@@ -196,12 +187,10 @@ var WakaTime = (function () {
|
||||
* @returns {*}
|
||||
*/
|
||||
value: function checkAuth() {
|
||||
var _this = this;
|
||||
|
||||
var deferredObject = _jquery2['default'].Deferred();
|
||||
|
||||
_jquery2['default'].ajax({
|
||||
url: this.currentUserApiUrl,
|
||||
url: config.currentUserApiUrl,
|
||||
dataType: 'json',
|
||||
success: function success(data) {
|
||||
|
||||
@@ -209,7 +198,7 @@ var WakaTime = (function () {
|
||||
},
|
||||
error: function error(xhr, status, err) {
|
||||
|
||||
console.error(_this.currentUserApiUrl, status, err.toString());
|
||||
console.error(config.currentUserApiUrl, status, err.toString());
|
||||
|
||||
deferredObject.resolve(false);
|
||||
}
|
||||
@@ -225,40 +214,40 @@ var WakaTime = (function () {
|
||||
* and sends it to WakaTime for logging.
|
||||
*/
|
||||
value: function recordHeartbeat() {
|
||||
var _this2 = this;
|
||||
var _this = this;
|
||||
|
||||
this.checkAuth().done(function (data) {
|
||||
|
||||
if (data !== false) {
|
||||
|
||||
chrome.storage.sync.get({
|
||||
loggingEnabled: true
|
||||
loggingEnabled: config.loggingEnabled
|
||||
}, function (items) {
|
||||
if (items.loggingEnabled === true) {
|
||||
(0, _helpersChangeExtensionIconJs2['default'])();
|
||||
(0, _helpersChangeExtensionIconJs2['default'])(config.colors.allGood);
|
||||
|
||||
chrome.idle.queryState(_this2.detectionIntervalInSeconds, function (newState) {
|
||||
chrome.idle.queryState(config.detectionIntervalInSeconds, function (newState) {
|
||||
|
||||
if (newState === 'active') {
|
||||
// Get current tab URL.
|
||||
chrome.tabs.query({ active: true }, function (tabs) {
|
||||
var debug = false;
|
||||
// If the current active tab has devtools open
|
||||
if (in_array(tabs[0].id, _this2.tabsWithDevtoolsOpen)) debug = true;
|
||||
if (in_array(tabs[0].id, _this.tabsWithDevtoolsOpen)) debug = true;
|
||||
|
||||
_this2.sendHeartbeat(tabs[0].url, debug);
|
||||
_this.sendHeartbeat(tabs[0].url, debug);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
(0, _helpersChangeExtensionIconJs2['default'])('red');
|
||||
(0, _helpersChangeExtensionIconJs2['default'])(config.colors.notLogging);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
// User is not logged in.
|
||||
// Change extension icon to red color.
|
||||
(0, _helpersChangeExtensionIconJs2['default'])('red');
|
||||
(0, _helpersChangeExtensionIconJs2['default'])(config.colors.notSignedIn);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -297,7 +286,7 @@ var WakaTime = (function () {
|
||||
var deferredObject = _jquery2['default'].Deferred();
|
||||
|
||||
chrome.storage.sync.get({
|
||||
loggingType: this.loggingType
|
||||
loggingType: config.loggingType
|
||||
}, function (items) {
|
||||
deferredObject.resolve(items.loggingType);
|
||||
});
|
||||
@@ -315,7 +304,7 @@ var WakaTime = (function () {
|
||||
* @param debug
|
||||
*/
|
||||
value: function sendHeartbeat(entity, debug) {
|
||||
var _this3 = this;
|
||||
var _this2 = this;
|
||||
|
||||
var payload = null;
|
||||
|
||||
@@ -327,19 +316,19 @@ var WakaTime = (function () {
|
||||
|
||||
var domain = _UrlHelperJs2['default'].getDomainFromUrl(entity);
|
||||
|
||||
payload = _this3._preparePayload(domain, 'domain', debug);
|
||||
payload = _this2._preparePayload(domain, 'domain', debug);
|
||||
|
||||
console.log(payload);
|
||||
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
_this2.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
// Send entity in heartbeat
|
||||
else if (loggingType == 'url') {
|
||||
payload = _this3._preparePayload(entity, 'url', debug);
|
||||
payload = _this2._preparePayload(entity, 'url', debug);
|
||||
|
||||
console.log(payload);
|
||||
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
_this2.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -354,27 +343,27 @@ var WakaTime = (function () {
|
||||
* @returns {*}
|
||||
*/
|
||||
value: function sendAjaxRequestToApi(payload) {
|
||||
var _this4 = this;
|
||||
var _this3 = this;
|
||||
|
||||
var method = arguments[1] === undefined ? 'POST' : arguments[1];
|
||||
|
||||
var deferredObject = _jquery2['default'].Deferred();
|
||||
|
||||
_jquery2['default'].ajax({
|
||||
url: this.heartbeatApiUrl,
|
||||
url: config.heartbeatApiUrl,
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
method: method,
|
||||
data: payload,
|
||||
success: function success(response) {
|
||||
|
||||
deferredObject.resolve(_this4);
|
||||
deferredObject.resolve(_this3);
|
||||
},
|
||||
error: function error(xhr, status, err) {
|
||||
|
||||
console.error(_this4.heartbeatApiUrl, status, err.toString());
|
||||
console.error(config.heartbeatApiUrl, status, err.toString());
|
||||
|
||||
deferredObject.resolve(_this4);
|
||||
deferredObject.resolve(_this3);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -388,10 +377,43 @@ var WakaTime = (function () {
|
||||
exports['default'] = WakaTime;
|
||||
module.exports = exports['default'];
|
||||
|
||||
},{"./UrlHelper.js":2,"./helpers/changeExtensionIcon.js":4,"./helpers/currentTimestamp.js":5,"./helpers/in_array":6,"jquery":7}],4:[function(require,module,exports){
|
||||
},{"./UrlHelper.js":2,"./config.js":4,"./helpers/changeExtensionIcon.js":5,"./helpers/currentTimestamp.js":6,"./helpers/in_array":7,"jquery":8}],4:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports['default'] = {
|
||||
// Time for idle state of the browser
|
||||
// The user is considered idle if there was
|
||||
// no activity in the browser for x seconds
|
||||
detectionIntervalInSeconds: 60,
|
||||
//default logging type
|
||||
loggingType: 'domain',
|
||||
// By default logging is enabled
|
||||
loggingEnabled: true,
|
||||
// Url to which to send the heartbeat
|
||||
heartbeatApiUrl: 'https://wakatime.com/api/v1/users/current/heartbeats',
|
||||
// Url from which to detect if the user is logged in
|
||||
currentUserApiUrl: 'https://wakatime.com/api/v1/users/current',
|
||||
// The url to logout the user from wakatime
|
||||
logoutUserUrl: 'https://wakatime.com/logout',
|
||||
// Different colors for different states of the extension
|
||||
colors: {
|
||||
allGood: '',
|
||||
notLogging: 'gray',
|
||||
notSignedIn: 'red',
|
||||
lightTheme: 'white'
|
||||
},
|
||||
// Default theme
|
||||
theme: 'light'
|
||||
};
|
||||
module.exports = exports['default'];
|
||||
|
||||
},{}],5:[function(require,module,exports){
|
||||
/**
|
||||
* It changes the extension icon color.
|
||||
* Supported values are: 'red', 'white' and ''.
|
||||
* Supported values are: 'red', 'white', 'gray' and ''.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
@@ -408,7 +430,7 @@ function changeExtensionIcon() {
|
||||
if (color !== '') {
|
||||
color = '-' + color;
|
||||
|
||||
path = './graphics/wakatime-logo-48' + color + '.png';
|
||||
path = './graphics/wakatime-logo-38' + color + '.png';
|
||||
|
||||
chrome.browserAction.setIcon({
|
||||
path: path
|
||||
@@ -420,13 +442,13 @@ function changeExtensionIcon() {
|
||||
theme: 'light'
|
||||
}, function (items) {
|
||||
if (items.theme == 'light') {
|
||||
path = './graphics/wakatime-logo-48.png';
|
||||
path = './graphics/wakatime-logo-38.png';
|
||||
|
||||
chrome.browserAction.setIcon({
|
||||
path: path
|
||||
});
|
||||
} else {
|
||||
path = './graphics/wakatime-logo-48-white.png';
|
||||
path = './graphics/wakatime-logo-38-white.png';
|
||||
|
||||
chrome.browserAction.setIcon({
|
||||
path: path
|
||||
@@ -438,7 +460,7 @@ function changeExtensionIcon() {
|
||||
|
||||
module.exports = exports['default'];
|
||||
|
||||
},{}],5:[function(require,module,exports){
|
||||
},{}],6:[function(require,module,exports){
|
||||
/**
|
||||
* Returns UNIX timestamp
|
||||
*/
|
||||
@@ -454,7 +476,7 @@ exports["default"] = function () {
|
||||
|
||||
module.exports = exports["default"];
|
||||
|
||||
},{}],6:[function(require,module,exports){
|
||||
},{}],7:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
@@ -474,7 +496,7 @@ function in_array(needle, haystack) {
|
||||
exports["default"] = in_array;
|
||||
module.exports = exports["default"];
|
||||
|
||||
},{}],7:[function(require,module,exports){
|
||||
},{}],8:[function(require,module,exports){
|
||||
/*!
|
||||
* jQuery JavaScript Library v2.1.4
|
||||
* http://jquery.com/
|
||||
|
||||
@@ -12,6 +12,8 @@ var _jquery2 = _interopRequireDefault(_jquery);
|
||||
global.jQuery = require('jquery');
|
||||
require('bootstrap');
|
||||
|
||||
var config = require('./config');
|
||||
|
||||
function detectCheckedRadio(name) {
|
||||
for (var i = 0; i < document.getElementsByName(name).length; i++) {
|
||||
var button = document.getElementsByName(name)[i];
|
||||
@@ -54,9 +56,9 @@ function save_options(e) {
|
||||
function restore_options() {
|
||||
// Use default value color = 'red' and likesColor = true.
|
||||
chrome.storage.sync.get({
|
||||
theme: 'light',
|
||||
theme: config.theme,
|
||||
blacklist: '',
|
||||
loggingType: 'domain'
|
||||
loggingType: config.loggingType
|
||||
}, function (items) {
|
||||
document.getElementById('theme').value = items.theme;
|
||||
document.getElementById('blacklist').value = items.blacklist;
|
||||
@@ -68,7 +70,40 @@ document.addEventListener('DOMContentLoaded', restore_options);
|
||||
document.getElementById('save').addEventListener('click', save_options);
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"bootstrap":2,"jquery":15}],2:[function(require,module,exports){
|
||||
},{"./config":2,"bootstrap":3,"jquery":16}],2:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports['default'] = {
|
||||
// Time for idle state of the browser
|
||||
// The user is considered idle if there was
|
||||
// no activity in the browser for x seconds
|
||||
detectionIntervalInSeconds: 60,
|
||||
//default logging type
|
||||
loggingType: 'domain',
|
||||
// By default logging is enabled
|
||||
loggingEnabled: true,
|
||||
// Url to which to send the heartbeat
|
||||
heartbeatApiUrl: 'https://wakatime.com/api/v1/users/current/heartbeats',
|
||||
// Url from which to detect if the user is logged in
|
||||
currentUserApiUrl: 'https://wakatime.com/api/v1/users/current',
|
||||
// The url to logout the user from wakatime
|
||||
logoutUserUrl: 'https://wakatime.com/logout',
|
||||
// Different colors for different states of the extension
|
||||
colors: {
|
||||
allGood: '',
|
||||
notLogging: 'gray',
|
||||
notSignedIn: 'red',
|
||||
lightTheme: 'white'
|
||||
},
|
||||
// Default theme
|
||||
theme: 'light'
|
||||
};
|
||||
module.exports = exports['default'];
|
||||
|
||||
},{}],3:[function(require,module,exports){
|
||||
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
|
||||
require('../../js/transition.js')
|
||||
require('../../js/alert.js')
|
||||
@@ -82,7 +117,7 @@ require('../../js/popover.js')
|
||||
require('../../js/scrollspy.js')
|
||||
require('../../js/tab.js')
|
||||
require('../../js/affix.js')
|
||||
},{"../../js/affix.js":3,"../../js/alert.js":4,"../../js/button.js":5,"../../js/carousel.js":6,"../../js/collapse.js":7,"../../js/dropdown.js":8,"../../js/modal.js":9,"../../js/popover.js":10,"../../js/scrollspy.js":11,"../../js/tab.js":12,"../../js/tooltip.js":13,"../../js/transition.js":14}],3:[function(require,module,exports){
|
||||
},{"../../js/affix.js":4,"../../js/alert.js":5,"../../js/button.js":6,"../../js/carousel.js":7,"../../js/collapse.js":8,"../../js/dropdown.js":9,"../../js/modal.js":10,"../../js/popover.js":11,"../../js/scrollspy.js":12,"../../js/tab.js":13,"../../js/tooltip.js":14,"../../js/transition.js":15}],4:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: affix.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#affix
|
||||
@@ -246,7 +281,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],4:[function(require,module,exports){
|
||||
},{}],5:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: alert.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#alerts
|
||||
@@ -342,7 +377,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],5:[function(require,module,exports){
|
||||
},{}],6:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: button.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#buttons
|
||||
@@ -460,7 +495,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],6:[function(require,module,exports){
|
||||
},{}],7:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: carousel.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#carousel
|
||||
@@ -699,7 +734,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],7:[function(require,module,exports){
|
||||
},{}],8:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: collapse.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#collapse
|
||||
@@ -912,7 +947,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],8:[function(require,module,exports){
|
||||
},{}],9:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: dropdown.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#dropdowns
|
||||
@@ -1075,7 +1110,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],9:[function(require,module,exports){
|
||||
},{}],10:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: modal.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#modals
|
||||
@@ -1416,7 +1451,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],10:[function(require,module,exports){
|
||||
},{}],11:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: popover.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#popovers
|
||||
@@ -1526,7 +1561,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],11:[function(require,module,exports){
|
||||
},{}],12:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: scrollspy.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#scrollspy
|
||||
@@ -1700,7 +1735,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],12:[function(require,module,exports){
|
||||
},{}],13:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: tab.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#tabs
|
||||
@@ -1855,7 +1890,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],13:[function(require,module,exports){
|
||||
},{}],14:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: tooltip.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#tooltip
|
||||
@@ -2333,7 +2368,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],14:[function(require,module,exports){
|
||||
},{}],15:[function(require,module,exports){
|
||||
/* ========================================================================
|
||||
* Bootstrap: transition.js v3.3.4
|
||||
* http://getbootstrap.com/javascript/#transitions
|
||||
@@ -2394,7 +2429,7 @@ require('../../js/affix.js')
|
||||
|
||||
}(jQuery);
|
||||
|
||||
},{}],15:[function(require,module,exports){
|
||||
},{}],16:[function(require,module,exports){
|
||||
/*!
|
||||
* jQuery JavaScript Library v2.1.4
|
||||
* http://jquery.com/
|
||||
|
||||
Reference in New Issue
Block a user