Skip to content

Commit

Permalink
Track personal usage of OctoLinker (OctoLinker#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck authored Apr 30, 2020
1 parent 73f9abb commit 64ca52a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Plugins from './plugin-manager.js';
import debugMode from './debug-mode.js';
import loader from './loader.js';
import * as loadPlugins from './load-plugins';
import './stats.js';

const blobReader = new BlobReader();
const pluginManager = new Plugins(loadPlugins);
Expand Down
34 changes: 34 additions & 0 deletions packages/core/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as storage from '@octolinker/helper-settings';

const CLASS_NAME = 'octolinker-link';

let tid = null;

function updateCounter() {
const stats = storage.get('stats') || {
since: Date.now(),
counter: 0,
};

storage.set('stats', {
...stats,
counter: stats.counter + 1,
});
}

function init() {
function statsHandler(event) {
if (!event.target.classList.contains(CLASS_NAME)) {
return;
}

if (tid) clearTimeout(tid);

tid = setTimeout(updateCounter, 1000);
}

document.body.addEventListener('click', statsHandler);
document.body.addEventListener('mouseover', statsHandler);
}

init();

0 comments on commit 64ca52a

Please sign in to comment.