Commented stuff.
This commit is contained in:
@@ -15,6 +15,11 @@ class WakaTime {
|
||||
|
||||
currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
||||
|
||||
/**
|
||||
* Checks if the user is logged in.
|
||||
*
|
||||
* @return $.promise()
|
||||
*/
|
||||
checkAuth()
|
||||
{
|
||||
var deferredObject = $.Deferred();
|
||||
@@ -38,29 +43,28 @@ class WakaTime {
|
||||
return deferredObject.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending on various factors detects the current active tab URL or domain,
|
||||
* and sends it to WakaTime for logging.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
recordHeartbeat()
|
||||
{
|
||||
this.checkAuth().done(data => {
|
||||
|
||||
if(data !== false){
|
||||
|
||||
console.log('user is logged id.');
|
||||
// User is logged in.
|
||||
// Change extension icon to default color.
|
||||
changeExtensionIcon();
|
||||
|
||||
console.log('recording heartbeat.');
|
||||
|
||||
chrome.idle.queryState(this.detectionIntervalInSeconds, (newState) => {
|
||||
|
||||
console.log(newState);
|
||||
|
||||
if(newState === 'active')
|
||||
{
|
||||
|
||||
// Get current tab URL.
|
||||
chrome.tabs.query({active: true}, (tabs) => {
|
||||
console.log(tabs[0].url);
|
||||
|
||||
this.sendHeartbeat(tabs[0].url);
|
||||
});
|
||||
}
|
||||
@@ -70,16 +74,20 @@ class WakaTime {
|
||||
else {
|
||||
|
||||
// User is not logged in.
|
||||
// Change extension icon to red color.
|
||||
changeExtensionIcon('red');
|
||||
|
||||
console.log('user is not logged id.');
|
||||
|
||||
//TODO: Redirect user to wakatime login page.
|
||||
//
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates payload for the heartbeat and returns it as JSON.
|
||||
*
|
||||
* @param string entity
|
||||
* @param string type 'domain' or 'url'
|
||||
* @param boolean debug = false
|
||||
* @return JSON
|
||||
*/
|
||||
_preparePayload(entity, type, debug = false)
|
||||
{
|
||||
return JSON.stringify({
|
||||
@@ -90,6 +98,11 @@ class WakaTime {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a promise with logging type variable.
|
||||
*
|
||||
* @return $.promise
|
||||
*/
|
||||
_getLoggingType()
|
||||
{
|
||||
var deferredObject = $.Deferred();
|
||||
@@ -103,16 +116,20 @@ class WakaTime {
|
||||
return deferredObject.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the entity and logging type it creates a payload and
|
||||
* sends an ajax post request to the API.
|
||||
*
|
||||
* @param string entity
|
||||
* @return null
|
||||
*/
|
||||
sendHeartbeat(entity)
|
||||
{
|
||||
this._getLoggingType().done((loggingType) => {
|
||||
|
||||
if(loggingType == 'domain') {
|
||||
console.log('sending entity with type domain');
|
||||
|
||||
// Get only the domain from the entity.
|
||||
// And send that in heartbeat
|
||||
console.log(UrlHelper.getDomainFromUrl(entity));
|
||||
if(loggingType == 'domain') {
|
||||
|
||||
var domain = UrlHelper.getDomainFromUrl(entity);
|
||||
|
||||
@@ -120,24 +137,28 @@ class WakaTime {
|
||||
|
||||
console.log(payload);
|
||||
|
||||
this.sendAjaxRequestToApi(payload);
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
|
||||
}
|
||||
else if (loggingType == 'url') {
|
||||
console.log('sending entity with type url');
|
||||
|
||||
// Send entity in heartbeat
|
||||
|
||||
else if (loggingType == 'url') {
|
||||
var payload = this._preparePayload(entity, 'url');
|
||||
|
||||
console.log(payload);
|
||||
|
||||
this.sendAjaxRequestToApi(payload);
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends AJAX request with payload to the heartbeat API as JSON.
|
||||
*
|
||||
* @param JSON payload
|
||||
* @param string method = 'POST'
|
||||
* @return $.promise
|
||||
*/
|
||||
sendAjaxRequestToApi(payload, method = 'POST') {
|
||||
|
||||
var deferredObject = $.Deferred();
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Returns UNIX timestamp
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
export default function(){
|
||||
return Math.round((new Date()).getTime() / 1000);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ elixir(function (mix) {
|
||||
mix.copy('vendor/bower_components/font-awesome/less', 'assets/less/font-awesome');
|
||||
mix.copy('vendor/bower_components/font-awesome/fonts', 'public/fonts');
|
||||
mix.less('app.less');
|
||||
mix.browserify('app.js', null, 'assets/js');
|
||||
//mix.browserify('events.js', 'public/js/events.js', 'assets/js');
|
||||
//mix.browserify('app.js', null, 'assets/js');
|
||||
mix.browserify('events.js', 'public/js/events.js', 'assets/js');
|
||||
//mix.browserify('options.js', 'public/js/options.js', 'assets/js');
|
||||
});
|
||||
|
||||
@@ -1500,6 +1500,58 @@ address {
|
||||
font-style: normal;
|
||||
line-height: 1.846;
|
||||
}
|
||||
code,
|
||||
kbd,
|
||||
pre,
|
||||
samp {
|
||||
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
|
||||
}
|
||||
code {
|
||||
padding: 2px 4px;
|
||||
font-size: 90%;
|
||||
color: #c7254e;
|
||||
background-color: #f9f2f4;
|
||||
border-radius: 3px;
|
||||
}
|
||||
kbd {
|
||||
padding: 2px 4px;
|
||||
font-size: 90%;
|
||||
color: #ffffff;
|
||||
background-color: #333333;
|
||||
border-radius: 3px;
|
||||
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
kbd kbd {
|
||||
padding: 0;
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
box-shadow: none;
|
||||
}
|
||||
pre {
|
||||
display: block;
|
||||
padding: 11px;
|
||||
margin: 0 0 11.5px;
|
||||
font-size: 12px;
|
||||
line-height: 1.846;
|
||||
word-break: break-all;
|
||||
word-wrap: break-word;
|
||||
color: #212121;
|
||||
background-color: #f5f5f5;
|
||||
border: 1px solid #cccccc;
|
||||
border-radius: 3px;
|
||||
}
|
||||
pre code {
|
||||
padding: 0;
|
||||
font-size: inherit;
|
||||
color: inherit;
|
||||
white-space: pre-wrap;
|
||||
background-color: transparent;
|
||||
border-radius: 0;
|
||||
}
|
||||
.pre-scrollable {
|
||||
max-height: 340px;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
.container {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -181,7 +181,7 @@ var WakaTime = (function () {
|
||||
|
||||
console.log(payload);
|
||||
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
} else if (loggingType == 'url') {
|
||||
console.log('sending entity with type url');
|
||||
|
||||
@@ -191,7 +191,7 @@ var WakaTime = (function () {
|
||||
|
||||
console.log(payload);
|
||||
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,6 +100,12 @@ var WakaTime = (function () {
|
||||
|
||||
_createClass(WakaTime, [{
|
||||
key: 'checkAuth',
|
||||
|
||||
/**
|
||||
* Checks if the user is logged in.
|
||||
*
|
||||
* @return $.promise()
|
||||
*/
|
||||
value: function checkAuth() {
|
||||
var _this = this;
|
||||
|
||||
@@ -124,6 +130,13 @@ var WakaTime = (function () {
|
||||
}
|
||||
}, {
|
||||
key: 'recordHeartbeat',
|
||||
|
||||
/**
|
||||
* Depending on various factors detects the current active tab URL or domain,
|
||||
* and sends it to WakaTime for logging.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
value: function recordHeartbeat() {
|
||||
var _this2 = this;
|
||||
|
||||
@@ -131,22 +144,15 @@ var WakaTime = (function () {
|
||||
|
||||
if (data !== false) {
|
||||
|
||||
console.log('user is logged id.');
|
||||
// User is logged in.
|
||||
// Change extension icon to default color.
|
||||
changeExtensionIcon();
|
||||
|
||||
console.log('recording heartbeat.');
|
||||
|
||||
chrome.idle.queryState(_this2.detectionIntervalInSeconds, function (newState) {
|
||||
|
||||
console.log(newState);
|
||||
|
||||
if (newState === 'active') {
|
||||
|
||||
// Get current tab URL.
|
||||
chrome.tabs.query({ active: true }, function (tabs) {
|
||||
console.log(tabs[0].url);
|
||||
|
||||
_this2.sendHeartbeat(tabs[0].url);
|
||||
});
|
||||
}
|
||||
@@ -154,17 +160,22 @@ var WakaTime = (function () {
|
||||
} else {
|
||||
|
||||
// User is not logged in.
|
||||
// Change extension icon to red color.
|
||||
changeExtensionIcon('red');
|
||||
|
||||
console.log('user is not logged id.');
|
||||
|
||||
//TODO: Redirect user to wakatime login page.
|
||||
//
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: '_preparePayload',
|
||||
|
||||
/**
|
||||
* Creates payload for the heartbeat and returns it as JSON.
|
||||
*
|
||||
* @param string entity
|
||||
* @param string type 'domain' or 'url'
|
||||
* @param boolean debug = false
|
||||
* @return JSON
|
||||
*/
|
||||
value: function _preparePayload(entity, type) {
|
||||
var debug = arguments[2] === undefined ? false : arguments[2];
|
||||
|
||||
@@ -177,6 +188,12 @@ var WakaTime = (function () {
|
||||
}
|
||||
}, {
|
||||
key: '_getLoggingType',
|
||||
|
||||
/**
|
||||
* Returns a promise with logging type variable.
|
||||
*
|
||||
* @return $.promise
|
||||
*/
|
||||
value: function _getLoggingType() {
|
||||
var deferredObject = $.Deferred();
|
||||
|
||||
@@ -190,17 +207,22 @@ var WakaTime = (function () {
|
||||
}
|
||||
}, {
|
||||
key: 'sendHeartbeat',
|
||||
|
||||
/**
|
||||
* Given the entity and logging type it creates a payload and
|
||||
* sends an ajax post request to the API.
|
||||
*
|
||||
* @param string entity
|
||||
* @return null
|
||||
*/
|
||||
value: function sendHeartbeat(entity) {
|
||||
var _this3 = this;
|
||||
|
||||
this._getLoggingType().done(function (loggingType) {
|
||||
|
||||
if (loggingType == 'domain') {
|
||||
console.log('sending entity with type domain');
|
||||
|
||||
// Get only the domain from the entity.
|
||||
// And send that in heartbeat
|
||||
console.log(UrlHelper.getDomainFromUrl(entity));
|
||||
if (loggingType == 'domain') {
|
||||
|
||||
var domain = UrlHelper.getDomainFromUrl(entity);
|
||||
|
||||
@@ -208,22 +230,28 @@ var WakaTime = (function () {
|
||||
|
||||
console.log(payload);
|
||||
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
} else if (loggingType == 'url') {
|
||||
console.log('sending entity with type url');
|
||||
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
// Send entity in heartbeat
|
||||
|
||||
else if (loggingType == 'url') {
|
||||
var payload = _this3._preparePayload(entity, 'url');
|
||||
|
||||
console.log(payload);
|
||||
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'sendAjaxRequestToApi',
|
||||
|
||||
/**
|
||||
* Sends AJAX request with payload to the heartbeat API as JSON.
|
||||
*
|
||||
* @param JSON payload
|
||||
* @param string method = 'POST'
|
||||
* @return $.promise
|
||||
*/
|
||||
value: function sendAjaxRequestToApi(payload) {
|
||||
var _this4 = this;
|
||||
|
||||
@@ -294,6 +322,11 @@ function changeExtensionIcon() {
|
||||
module.exports = exports['default'];
|
||||
|
||||
},{}],5:[function(require,module,exports){
|
||||
/**
|
||||
* Returns UNIX timestamp
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
|
||||
Reference in New Issue
Block a user