Added devtools detection.
This commit is contained in:
@@ -2,10 +2,12 @@ import UrlHelper from './UrlHelper.js';
|
|||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import currentTimestamp from './helpers/currentTimestamp.js';
|
import currentTimestamp from './helpers/currentTimestamp.js';
|
||||||
import changeExtensionIcon from './helpers/changeExtensionIcon.js';
|
import changeExtensionIcon from './helpers/changeExtensionIcon.js';
|
||||||
import devtools from './libs/devtools-detect.js';
|
var in_array = require('./helpers/in_array');
|
||||||
|
|
||||||
class WakaTime {
|
class WakaTime {
|
||||||
|
|
||||||
|
tabsWithDevtoolsOpen = [];
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
this.detectionIntervalInSeconds = 60; //default
|
this.detectionIntervalInSeconds = 60; //default
|
||||||
|
|
||||||
@@ -14,6 +16,12 @@ class WakaTime {
|
|||||||
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
|
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
|
||||||
|
|
||||||
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
||||||
|
|
||||||
|
this.tabsWithDevtoolsOpen = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
setTabsWithDevtoolsOpen(tabs) {
|
||||||
|
this.tabsWithDevtoolsOpen = tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +71,11 @@ class WakaTime {
|
|||||||
if (newState === 'active') {
|
if (newState === 'active') {
|
||||||
// Get current tab URL.
|
// Get current tab URL.
|
||||||
chrome.tabs.query({active: true}, (tabs) => {
|
chrome.tabs.query({active: true}, (tabs) => {
|
||||||
this.sendHeartbeat(tabs[0].url);
|
var debug = false;
|
||||||
|
// If the current active tab has devtools open
|
||||||
|
if(in_array(tabs[0].id, this.tabsWithDevtoolsOpen)) debug = true;
|
||||||
|
|
||||||
|
this.sendHeartbeat(tabs[0].url, debug);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -124,14 +136,12 @@ class WakaTime {
|
|||||||
* sends an ajax post request to the API.
|
* sends an ajax post request to the API.
|
||||||
*
|
*
|
||||||
* @param entity
|
* @param entity
|
||||||
|
* @param debug
|
||||||
*/
|
*/
|
||||||
sendHeartbeat(entity) {
|
sendHeartbeat(entity, debug) {
|
||||||
|
|
||||||
var payload = null;
|
var payload = null;
|
||||||
|
|
||||||
// TODO: Detect if devTools are open
|
|
||||||
console.log(devtools.open);
|
|
||||||
|
|
||||||
this._getLoggingType().done((loggingType) => {
|
this._getLoggingType().done((loggingType) => {
|
||||||
|
|
||||||
// Get only the domain from the entity.
|
// Get only the domain from the entity.
|
||||||
@@ -140,7 +150,7 @@ class WakaTime {
|
|||||||
|
|
||||||
var domain = UrlHelper.getDomainFromUrl(entity);
|
var domain = UrlHelper.getDomainFromUrl(entity);
|
||||||
|
|
||||||
payload = this._preparePayload(domain, 'domain');
|
payload = this._preparePayload(domain, 'domain', debug);
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
@@ -149,7 +159,7 @@ class WakaTime {
|
|||||||
}
|
}
|
||||||
// Send entity in heartbeat
|
// Send entity in heartbeat
|
||||||
else if (loggingType == 'url') {
|
else if (loggingType == 'url') {
|
||||||
payload = this._preparePayload(entity, 'url');
|
payload = this._preparePayload(entity, 'url', debug);
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
|
|||||||
9
assets/js/devtools.js
Normal file
9
assets/js/devtools.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Create a connection to the background page
|
||||||
|
var backgroundPageConnection = chrome.runtime.connect({
|
||||||
|
name: "devtools-page"
|
||||||
|
});
|
||||||
|
|
||||||
|
backgroundPageConnection.postMessage({
|
||||||
|
name: 'init',
|
||||||
|
tabId: chrome.devtools.inspectedWindow.tabId
|
||||||
|
});
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
import WakaTime from "./WakaTime.js";
|
import WakaTime from "./WakaTime.js";
|
||||||
|
|
||||||
|
var wakatime = new WakaTime;
|
||||||
|
|
||||||
|
// Holds currently open connections (ports) with devtools
|
||||||
|
// Uses tabId as index key.
|
||||||
|
var connections = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whenever an alarms sets off, this function
|
* Whenever an alarms sets off, this function
|
||||||
* gets called to detect the alarm name and
|
* gets called to detect the alarm name and
|
||||||
@@ -14,8 +20,6 @@ function resolveAlarm(alarm) {
|
|||||||
|
|
||||||
console.log('recording a heartbeat - alarm triggered');
|
console.log('recording a heartbeat - alarm triggered');
|
||||||
|
|
||||||
var wakatime = new WakaTime;
|
|
||||||
|
|
||||||
wakatime.recordHeartbeat();
|
wakatime.recordHeartbeat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,8 +39,6 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
|
|||||||
|
|
||||||
console.log('recording a heartbeat - active tab changed');
|
console.log('recording a heartbeat - active tab changed');
|
||||||
|
|
||||||
var wakatime = new WakaTime;
|
|
||||||
|
|
||||||
wakatime.recordHeartbeat();
|
wakatime.recordHeartbeat();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,11 +57,45 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|||||||
if (tabId == tabs[0].id) {
|
if (tabId == tabs[0].id) {
|
||||||
console.log('recording a heartbeat - tab updated');
|
console.log('recording a heartbeat - tab updated');
|
||||||
|
|
||||||
var wakatime = new WakaTime;
|
|
||||||
|
|
||||||
wakatime.recordHeartbeat();
|
wakatime.recordHeartbeat();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
chrome.runtime.onConnect.addListener(function (port) {
|
||||||
|
|
||||||
|
if (port.name == "devtools-page") {
|
||||||
|
|
||||||
|
// Listen to messages sent from the DevTools page
|
||||||
|
port.onMessage.addListener(function (message, sender, sendResponse) {
|
||||||
|
if (message.name == "init") {
|
||||||
|
|
||||||
|
connections[message.tabId] = port;
|
||||||
|
|
||||||
|
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||||
|
|
||||||
|
wakatime.recordHeartbeat();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
port.onDisconnect.addListener(function (port) {
|
||||||
|
|
||||||
|
var tabs = Object.keys(connections);
|
||||||
|
|
||||||
|
for (var i = 0, len = tabs.length; i < len; i ++) {
|
||||||
|
if (connections[tabs[i]] == port) {
|
||||||
|
delete connections[tabs[i]];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||||
|
|
||||||
|
wakatime.recordHeartbeat();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
12
assets/js/helpers/in_array.js
Normal file
12
assets/js/helpers/in_array.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
function in_array(needle, haystack) {
|
||||||
|
for (var i = 0; i < haystack.length; i ++) {
|
||||||
|
if (needle == haystack[i]) {
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default in_array;
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"font-awesome": "~4.3.0",
|
"font-awesome": "~4.3.0",
|
||||||
"bootstrap": "~3.3.4",
|
"bootstrap": "~3.3.4"
|
||||||
"devtools-detect": "~1.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
devtools.html
Normal file
2
devtools.html
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="public/js/devtools.js"></script>
|
||||||
@@ -18,9 +18,9 @@ elixir(function (mix) {
|
|||||||
mix.copy('vendor/bower_components/bootstrap/fonts', 'public/fonts');
|
mix.copy('vendor/bower_components/bootstrap/fonts', 'public/fonts');
|
||||||
mix.copy('vendor/bower_components/font-awesome/less', 'assets/less/font-awesome');
|
mix.copy('vendor/bower_components/font-awesome/less', 'assets/less/font-awesome');
|
||||||
mix.copy('vendor/bower_components/font-awesome/fonts', 'public/fonts');
|
mix.copy('vendor/bower_components/font-awesome/fonts', 'public/fonts');
|
||||||
mix.copy('vendor/bower_components/devtools-detect/devtools-detect.js', 'assets/js/libs/devtools-detect.js');
|
|
||||||
mix.less('app.less');
|
mix.less('app.less');
|
||||||
mix.browserify('app.js', null, 'assets/js');
|
mix.browserify('app.js', null, 'assets/js');
|
||||||
mix.browserify('events.js', 'public/js/events.js', 'assets/js');
|
mix.browserify('events.js', 'public/js/events.js', 'assets/js');
|
||||||
mix.browserify('options.js', 'public/js/options.js', 'assets/js');
|
mix.browserify('options.js', 'public/js/options.js', 'assets/js');
|
||||||
|
mix.browserify('devtools.js', 'public/js/devtools.js', 'assets/js');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"name": "WakaTime",
|
"name": "WakaTime",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Get stats about your website debugging, research, documentation, etc.",
|
"description": "Get stats about your website debugging, research, documentation, etc.",
|
||||||
|
"devtools_page": "devtools.html",
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "graphics/wakatime-logo-16.png",
|
"16": "graphics/wakatime-logo-16.png",
|
||||||
"48": "graphics/wakatime-logo-48.png",
|
"48": "graphics/wakatime-logo-48.png",
|
||||||
|
|||||||
@@ -79,14 +79,14 @@ var _helpersChangeExtensionIconJs = require('./helpers/changeExtensionIcon.js');
|
|||||||
|
|
||||||
var _helpersChangeExtensionIconJs2 = _interopRequireDefault(_helpersChangeExtensionIconJs);
|
var _helpersChangeExtensionIconJs2 = _interopRequireDefault(_helpersChangeExtensionIconJs);
|
||||||
|
|
||||||
var _libsDevtoolsDetectJs = require('./libs/devtools-detect.js');
|
var in_array = require('./helpers/in_array');
|
||||||
|
|
||||||
var _libsDevtoolsDetectJs2 = _interopRequireDefault(_libsDevtoolsDetectJs);
|
|
||||||
|
|
||||||
var WakaTime = (function () {
|
var WakaTime = (function () {
|
||||||
function WakaTime(props) {
|
function WakaTime(props) {
|
||||||
_classCallCheck(this, WakaTime);
|
_classCallCheck(this, WakaTime);
|
||||||
|
|
||||||
|
this.tabsWithDevtoolsOpen = [];
|
||||||
|
|
||||||
this.detectionIntervalInSeconds = 60; //default
|
this.detectionIntervalInSeconds = 60; //default
|
||||||
|
|
||||||
this.loggingType = 'domain'; //default
|
this.loggingType = 'domain'; //default
|
||||||
@@ -94,9 +94,16 @@ var WakaTime = (function () {
|
|||||||
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
|
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
|
||||||
|
|
||||||
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
||||||
|
|
||||||
|
this.tabsWithDevtoolsOpen = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(WakaTime, [{
|
_createClass(WakaTime, [{
|
||||||
|
key: 'setTabsWithDevtoolsOpen',
|
||||||
|
value: function setTabsWithDevtoolsOpen(tabs) {
|
||||||
|
this.tabsWithDevtoolsOpen = tabs;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
key: 'checkAuth',
|
key: 'checkAuth',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,7 +158,11 @@ var WakaTime = (function () {
|
|||||||
if (newState === 'active') {
|
if (newState === 'active') {
|
||||||
// Get current tab URL.
|
// Get current tab URL.
|
||||||
chrome.tabs.query({ active: true }, function (tabs) {
|
chrome.tabs.query({ active: true }, function (tabs) {
|
||||||
_this2.sendHeartbeat(tabs[0].url);
|
var debug = false;
|
||||||
|
// If the current active tab has devtools open
|
||||||
|
if (in_array(tabs[0].id, _this2.tabsWithDevtoolsOpen)) debug = true;
|
||||||
|
|
||||||
|
_this2.sendHeartbeat(tabs[0].url, debug);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -217,15 +228,13 @@ var WakaTime = (function () {
|
|||||||
* sends an ajax post request to the API.
|
* sends an ajax post request to the API.
|
||||||
*
|
*
|
||||||
* @param entity
|
* @param entity
|
||||||
|
* @param debug
|
||||||
*/
|
*/
|
||||||
value: function sendHeartbeat(entity) {
|
value: function sendHeartbeat(entity, debug) {
|
||||||
var _this3 = this;
|
var _this3 = this;
|
||||||
|
|
||||||
var payload = null;
|
var payload = null;
|
||||||
|
|
||||||
// TODO: Detect if devTools are open
|
|
||||||
console.log(_libsDevtoolsDetectJs2['default'].open);
|
|
||||||
|
|
||||||
this._getLoggingType().done(function (loggingType) {
|
this._getLoggingType().done(function (loggingType) {
|
||||||
|
|
||||||
// Get only the domain from the entity.
|
// Get only the domain from the entity.
|
||||||
@@ -234,7 +243,7 @@ var WakaTime = (function () {
|
|||||||
|
|
||||||
var domain = _UrlHelperJs2['default'].getDomainFromUrl(entity);
|
var domain = _UrlHelperJs2['default'].getDomainFromUrl(entity);
|
||||||
|
|
||||||
payload = _this3._preparePayload(domain, 'domain');
|
payload = _this3._preparePayload(domain, 'domain', debug);
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
@@ -242,7 +251,7 @@ var WakaTime = (function () {
|
|||||||
}
|
}
|
||||||
// Send entity in heartbeat
|
// Send entity in heartbeat
|
||||||
else if (loggingType == 'url') {
|
else if (loggingType == 'url') {
|
||||||
payload = _this3._preparePayload(entity, 'url');
|
payload = _this3._preparePayload(entity, 'url', debug);
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
@@ -295,7 +304,9 @@ var WakaTime = (function () {
|
|||||||
exports['default'] = WakaTime;
|
exports['default'] = WakaTime;
|
||||||
module.exports = exports['default'];
|
module.exports = exports['default'];
|
||||||
|
|
||||||
},{"./UrlHelper.js":2,"./helpers/changeExtensionIcon.js":7,"./helpers/currentTimestamp.js":8,"./libs/devtools-detect.js":9,"jquery":23}],4:[function(require,module,exports){
|
},{"./UrlHelper.js":2,"./helpers/changeExtensionIcon.js":7,"./helpers/currentTimestamp.js":8,"./helpers/in_array":9,"jquery":23}],4:[function(require,module,exports){
|
||||||
|
//jshint esnext:true
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', {
|
Object.defineProperty(exports, '__esModule', {
|
||||||
@@ -488,6 +499,8 @@ exports['default'] = MainList;
|
|||||||
module.exports = exports['default'];
|
module.exports = exports['default'];
|
||||||
|
|
||||||
},{"react":179}],5:[function(require,module,exports){
|
},{"react":179}],5:[function(require,module,exports){
|
||||||
|
//jshint esnext:true
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
@@ -601,6 +614,8 @@ exports["default"] = Navbar;
|
|||||||
module.exports = exports["default"];
|
module.exports = exports["default"];
|
||||||
|
|
||||||
},{"react":179}],6:[function(require,module,exports){
|
},{"react":179}],6:[function(require,module,exports){
|
||||||
|
//jshint esnext:true
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', {
|
Object.defineProperty(exports, '__esModule', {
|
||||||
@@ -868,47 +883,24 @@ exports["default"] = function () {
|
|||||||
module.exports = exports["default"];
|
module.exports = exports["default"];
|
||||||
|
|
||||||
},{}],9:[function(require,module,exports){
|
},{}],9:[function(require,module,exports){
|
||||||
/*!
|
"use strict";
|
||||||
devtools-detect
|
|
||||||
Detect if DevTools is open
|
|
||||||
https://github.com/sindresorhus/devtools-detect
|
|
||||||
by Sindre Sorhus
|
|
||||||
MIT License
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
(function () {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
'use strict';
|
value: true
|
||||||
var devtools = { open: false };
|
});
|
||||||
var threshold = 160;
|
function in_array(needle, haystack) {
|
||||||
var emitEvent = function emitEvent(state) {
|
for (var i = 0; i < haystack.length; i++) {
|
||||||
window.dispatchEvent(new CustomEvent('devtoolschange', {
|
if (needle == haystack[i]) {
|
||||||
detail: {
|
return true;
|
||||||
open: state
|
break;
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
};
|
|
||||||
|
|
||||||
setInterval(function () {
|
return false;
|
||||||
if (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized || window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold) {
|
}
|
||||||
if (!devtools.open) {
|
|
||||||
emitEvent(true);
|
|
||||||
}
|
|
||||||
devtools.open = true;
|
|
||||||
} else {
|
|
||||||
if (devtools.open) {
|
|
||||||
emitEvent(false);
|
|
||||||
}
|
|
||||||
devtools.open = false;
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
exports["default"] = in_array;
|
||||||
module.exports = devtools;
|
module.exports = exports["default"];
|
||||||
} else {
|
|
||||||
window.devtools = devtools;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
},{}],10:[function(require,module,exports){
|
},{}],10:[function(require,module,exports){
|
||||||
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
|
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
|
||||||
|
|||||||
14
public/js/devtools.js
Normal file
14
public/js/devtools.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||||
|
// Create a connection to the background page
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var backgroundPageConnection = chrome.runtime.connect({
|
||||||
|
name: "devtools-page"
|
||||||
|
});
|
||||||
|
|
||||||
|
backgroundPageConnection.postMessage({
|
||||||
|
name: "init",
|
||||||
|
tabId: chrome.devtools.inspectedWindow.tabId
|
||||||
|
});
|
||||||
|
|
||||||
|
},{}]},{},[1]);
|
||||||
@@ -7,6 +7,12 @@ var _WakaTimeJs = require('./WakaTime.js');
|
|||||||
|
|
||||||
var _WakaTimeJs2 = _interopRequireDefault(_WakaTimeJs);
|
var _WakaTimeJs2 = _interopRequireDefault(_WakaTimeJs);
|
||||||
|
|
||||||
|
var wakatime = new _WakaTimeJs2['default']();
|
||||||
|
|
||||||
|
// Holds currently open connections (ports) with devtools
|
||||||
|
// Uses tabId as index key.
|
||||||
|
var connections = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whenever an alarms sets off, this function
|
* Whenever an alarms sets off, this function
|
||||||
* gets called to detect the alarm name and
|
* gets called to detect the alarm name and
|
||||||
@@ -21,8 +27,6 @@ function resolveAlarm(alarm) {
|
|||||||
|
|
||||||
console.log('recording a heartbeat - alarm triggered');
|
console.log('recording a heartbeat - alarm triggered');
|
||||||
|
|
||||||
var wakatime = new _WakaTimeJs2['default']();
|
|
||||||
|
|
||||||
wakatime.recordHeartbeat();
|
wakatime.recordHeartbeat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,8 +46,6 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
|
|||||||
|
|
||||||
console.log('recording a heartbeat - active tab changed');
|
console.log('recording a heartbeat - active tab changed');
|
||||||
|
|
||||||
var wakatime = new _WakaTimeJs2['default']();
|
|
||||||
|
|
||||||
wakatime.recordHeartbeat();
|
wakatime.recordHeartbeat();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -61,11 +63,43 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|||||||
if (tabId == tabs[0].id) {
|
if (tabId == tabs[0].id) {
|
||||||
console.log('recording a heartbeat - tab updated');
|
console.log('recording a heartbeat - tab updated');
|
||||||
|
|
||||||
var wakatime = new _WakaTimeJs2['default']();
|
wakatime.recordHeartbeat();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chrome.runtime.onConnect.addListener(function (port) {
|
||||||
|
|
||||||
|
if (port.name == 'devtools-page') {
|
||||||
|
|
||||||
|
// Listen to messages sent from the DevTools page
|
||||||
|
port.onMessage.addListener(function (message, sender, sendResponse) {
|
||||||
|
if (message.name == 'init') {
|
||||||
|
|
||||||
|
connections[message.tabId] = port;
|
||||||
|
|
||||||
|
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||||
|
|
||||||
wakatime.recordHeartbeat();
|
wakatime.recordHeartbeat();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
port.onDisconnect.addListener(function (port) {
|
||||||
|
|
||||||
|
var tabs = Object.keys(connections);
|
||||||
|
|
||||||
|
for (var i = 0, len = tabs.length; i < len; i++) {
|
||||||
|
if (connections[tabs[i]] == port) {
|
||||||
|
delete connections[tabs[i]];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||||
|
|
||||||
|
wakatime.recordHeartbeat();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -129,14 +163,14 @@ var _helpersChangeExtensionIconJs = require('./helpers/changeExtensionIcon.js');
|
|||||||
|
|
||||||
var _helpersChangeExtensionIconJs2 = _interopRequireDefault(_helpersChangeExtensionIconJs);
|
var _helpersChangeExtensionIconJs2 = _interopRequireDefault(_helpersChangeExtensionIconJs);
|
||||||
|
|
||||||
var _libsDevtoolsDetectJs = require('./libs/devtools-detect.js');
|
var in_array = require('./helpers/in_array');
|
||||||
|
|
||||||
var _libsDevtoolsDetectJs2 = _interopRequireDefault(_libsDevtoolsDetectJs);
|
|
||||||
|
|
||||||
var WakaTime = (function () {
|
var WakaTime = (function () {
|
||||||
function WakaTime(props) {
|
function WakaTime(props) {
|
||||||
_classCallCheck(this, WakaTime);
|
_classCallCheck(this, WakaTime);
|
||||||
|
|
||||||
|
this.tabsWithDevtoolsOpen = [];
|
||||||
|
|
||||||
this.detectionIntervalInSeconds = 60; //default
|
this.detectionIntervalInSeconds = 60; //default
|
||||||
|
|
||||||
this.loggingType = 'domain'; //default
|
this.loggingType = 'domain'; //default
|
||||||
@@ -144,9 +178,16 @@ var WakaTime = (function () {
|
|||||||
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
|
this.heartbeatApiUrl = 'https://wakatime.com/api/v1/users/current/heartbeats';
|
||||||
|
|
||||||
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
this.currentUserApiUrl = 'https://wakatime.com/api/v1/users/current';
|
||||||
|
|
||||||
|
this.tabsWithDevtoolsOpen = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(WakaTime, [{
|
_createClass(WakaTime, [{
|
||||||
|
key: 'setTabsWithDevtoolsOpen',
|
||||||
|
value: function setTabsWithDevtoolsOpen(tabs) {
|
||||||
|
this.tabsWithDevtoolsOpen = tabs;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
key: 'checkAuth',
|
key: 'checkAuth',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,7 +242,11 @@ var WakaTime = (function () {
|
|||||||
if (newState === 'active') {
|
if (newState === 'active') {
|
||||||
// Get current tab URL.
|
// Get current tab URL.
|
||||||
chrome.tabs.query({ active: true }, function (tabs) {
|
chrome.tabs.query({ active: true }, function (tabs) {
|
||||||
_this2.sendHeartbeat(tabs[0].url);
|
var debug = false;
|
||||||
|
// If the current active tab has devtools open
|
||||||
|
if (in_array(tabs[0].id, _this2.tabsWithDevtoolsOpen)) debug = true;
|
||||||
|
|
||||||
|
_this2.sendHeartbeat(tabs[0].url, debug);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -267,15 +312,13 @@ var WakaTime = (function () {
|
|||||||
* sends an ajax post request to the API.
|
* sends an ajax post request to the API.
|
||||||
*
|
*
|
||||||
* @param entity
|
* @param entity
|
||||||
|
* @param debug
|
||||||
*/
|
*/
|
||||||
value: function sendHeartbeat(entity) {
|
value: function sendHeartbeat(entity, debug) {
|
||||||
var _this3 = this;
|
var _this3 = this;
|
||||||
|
|
||||||
var payload = null;
|
var payload = null;
|
||||||
|
|
||||||
// TODO: Detect if devTools are open
|
|
||||||
console.log(_libsDevtoolsDetectJs2['default'].open);
|
|
||||||
|
|
||||||
this._getLoggingType().done(function (loggingType) {
|
this._getLoggingType().done(function (loggingType) {
|
||||||
|
|
||||||
// Get only the domain from the entity.
|
// Get only the domain from the entity.
|
||||||
@@ -284,7 +327,7 @@ var WakaTime = (function () {
|
|||||||
|
|
||||||
var domain = _UrlHelperJs2['default'].getDomainFromUrl(entity);
|
var domain = _UrlHelperJs2['default'].getDomainFromUrl(entity);
|
||||||
|
|
||||||
payload = _this3._preparePayload(domain, 'domain');
|
payload = _this3._preparePayload(domain, 'domain', debug);
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
@@ -292,7 +335,7 @@ var WakaTime = (function () {
|
|||||||
}
|
}
|
||||||
// Send entity in heartbeat
|
// Send entity in heartbeat
|
||||||
else if (loggingType == 'url') {
|
else if (loggingType == 'url') {
|
||||||
payload = _this3._preparePayload(entity, 'url');
|
payload = _this3._preparePayload(entity, 'url', debug);
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
@@ -345,7 +388,7 @@ var WakaTime = (function () {
|
|||||||
exports['default'] = WakaTime;
|
exports['default'] = WakaTime;
|
||||||
module.exports = exports['default'];
|
module.exports = exports['default'];
|
||||||
|
|
||||||
},{"./UrlHelper.js":2,"./helpers/changeExtensionIcon.js":4,"./helpers/currentTimestamp.js":5,"./libs/devtools-detect.js":6,"jquery":7}],4:[function(require,module,exports){
|
},{"./UrlHelper.js":2,"./helpers/changeExtensionIcon.js":4,"./helpers/currentTimestamp.js":5,"./helpers/in_array":6,"jquery":7}],4:[function(require,module,exports){
|
||||||
/**
|
/**
|
||||||
* It changes the extension icon color.
|
* It changes the extension icon color.
|
||||||
* Supported values are: 'red', 'white' and ''.
|
* Supported values are: 'red', 'white' and ''.
|
||||||
@@ -412,47 +455,24 @@ exports["default"] = function () {
|
|||||||
module.exports = exports["default"];
|
module.exports = exports["default"];
|
||||||
|
|
||||||
},{}],6:[function(require,module,exports){
|
},{}],6:[function(require,module,exports){
|
||||||
/*!
|
"use strict";
|
||||||
devtools-detect
|
|
||||||
Detect if DevTools is open
|
|
||||||
https://github.com/sindresorhus/devtools-detect
|
|
||||||
by Sindre Sorhus
|
|
||||||
MIT License
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
(function () {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
'use strict';
|
value: true
|
||||||
var devtools = { open: false };
|
});
|
||||||
var threshold = 160;
|
function in_array(needle, haystack) {
|
||||||
var emitEvent = function emitEvent(state) {
|
for (var i = 0; i < haystack.length; i++) {
|
||||||
window.dispatchEvent(new CustomEvent('devtoolschange', {
|
if (needle == haystack[i]) {
|
||||||
detail: {
|
return true;
|
||||||
open: state
|
break;
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
};
|
|
||||||
|
|
||||||
setInterval(function () {
|
return false;
|
||||||
if (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized || window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold) {
|
}
|
||||||
if (!devtools.open) {
|
|
||||||
emitEvent(true);
|
|
||||||
}
|
|
||||||
devtools.open = true;
|
|
||||||
} else {
|
|
||||||
if (devtools.open) {
|
|
||||||
emitEvent(false);
|
|
||||||
}
|
|
||||||
devtools.open = false;
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
exports["default"] = in_array;
|
||||||
module.exports = devtools;
|
module.exports = exports["default"];
|
||||||
} else {
|
|
||||||
window.devtools = devtools;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
},{}],7:[function(require,module,exports){
|
},{}],7:[function(require,module,exports){
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Reference in New Issue
Block a user