├── README.md
├── manifest.json
├── options.html
├── options.js
├── LICENSE.txt
├── server.php
└── opentabs.js
/README.md:
--------------------------------------------------------------------------------
1 | # Chrome Open Tabs
2 |
3 | Tracks your open Chrome tabs and posts stats to a server.
4 |
5 | ## Credits
6 |
7 | Based on the more thorough [chrome-tab-statistics](https://github.com/beaugunderson/chrome-tab-statistics) by [Beau Gunderson](https://beaugunderson.com/).
8 |
9 | Thanks to [maxmechanic](https://github.com/maxmechanic) for creating the configuration interface!
10 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Tab Statistics",
3 | "version": "0.2",
4 | "manifest_version": 2,
5 | "description": "Log your open tabs to a server",
6 |
7 | "icons": {
8 | },
9 |
10 | "permissions": [
11 | "alarms",
12 | "tabs",
13 | "storage"
14 | ],
15 |
16 | "background": {
17 | "persistent": false,
18 | "scripts": [
19 | "opentabs.js"
20 | ]
21 | },
22 |
23 | "options_ui": {
24 | "page": "options.html",
25 | "chrome_style": true
26 | }
27 | }
--------------------------------------------------------------------------------
/options.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/options.js:
--------------------------------------------------------------------------------
1 |
2 | function restoreOptions() {
3 |
4 | chrome.storage.sync.get({ token: null, endpoint: null, send_what: 'counts' }, function(config){
5 | document.getElementById('endpoint').value = config.endpoint;
6 | document.getElementById('token').value = config.token;
7 | document.getElementById('send_what').value = config.send_what;
8 | });
9 |
10 | }
11 |
12 | function saveOptions(e) {
13 |
14 | var config = {
15 | endpoint: document.getElementById('endpoint').value,
16 | token: document.getElementById('token').value,
17 | send_what: document.getElementById('send_what').value
18 | };
19 |
20 | chrome.storage.sync.set(config, function(){
21 | var status = document.getElementById('status');
22 | status.textContent = 'Options saved.';
23 | setTimeout(function() {
24 | status.innerHTML = ' ';
25 | }, 750);
26 | });
27 |
28 | }
29 |
30 | document.addEventListener('DOMContentLoaded', restoreOptions);
31 | document.getElementById('save').addEventListener('click', saveOptions);
32 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright 2017 Aaron Parecki and Beau Gunderson
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/server.php:
--------------------------------------------------------------------------------
1 | prepare('INSERT INTO tabs (date, tzoffset, num_windows, num_tabs, breakdown) VALUES(?,?,?,?,?)');
38 | $query->bindValue(1, date('Y-m-d H:i:s', strtotime($tabs['timestamp'])));
39 | $query->bindValue(2, $tabs['tzoffset']);
40 | $query->bindValue(3, $tabs['num_windows']);
41 | $query->bindValue(4, $tabs['num_tabs']);
42 | $query->bindValue(5, json_encode($tabs['breakdown']));
43 | $query->execute();
44 | */
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/opentabs.js:
--------------------------------------------------------------------------------
1 | /*global chrome:true */
2 |
3 | 'use strict';
4 |
5 | function parseURL(url) {
6 | var href = document.createElement('a');
7 | href.href = url;
8 | return href;
9 | }
10 |
11 | // consolidate async setup
12 | const getStorageAndWindows = (callback) =>
13 | chrome.storage.sync.get({ token: null, endpoint: null, send_what: 'counts' }, function(config) {
14 | chrome.windows.getAll({populate: true}, function(windows) {
15 | callback(config, windows)
16 | });
17 | });
18 |
19 | function storeTabCount() {
20 | getStorageAndWindows(function(config, windows) {
21 | if(!config.endpoint) {
22 | return;
23 | }
24 |
25 | var total = 0;
26 | var breakdown = {};
27 | var details = {};
28 | var windowKey;
29 |
30 | for (windowKey in windows) {
31 | if (!windows.hasOwnProperty(windowKey)) {
32 | return;
33 | }
34 |
35 | breakdown[windowKey] = windows[windowKey].tabs.length;
36 |
37 | if(config.send_what != 'counts') {
38 | details[windowKey] = [];
39 |
40 | for (var tabKey in windows[windowKey].tabs) {
41 | var tab = windows[windowKey].tabs[tabKey];
42 | var url = parseURL(tab.url);
43 | var info = {
44 | icon: tab.favIconUrl,
45 | domain: url.protocol+"//"+url.hostname
46 | };
47 | if(config.send_what == 'urls') {
48 | info.url = tab.url;
49 | }
50 |
51 | details[windowKey].push(info);
52 | }
53 | }
54 |
55 | total += windows[windowKey].tabs.length;
56 | }
57 |
58 | var d = new Date();
59 |
60 | var request = new XMLHttpRequest();
61 |
62 | request.open('POST', config.endpoint, true);
63 | request.setRequestHeader('Content-Type', 'application/json');
64 | request.setRequestHeader('Authorization', `Bearer ${config.token}`);
65 | request.send(JSON.stringify({
66 | timestamp: d.toISOString(),
67 | tzoffset: (d.getTimezoneOffset()/60)*(-3600),
68 | num_windows: windows.length,
69 | num_tabs: total,
70 | breakdown: breakdown,
71 | details: details
72 | }));
73 | });
74 | }
75 |
76 | chrome.alarms.create('store-tab-count', {periodInMinutes: 5});
77 |
78 | chrome.alarms.onAlarm.addListener(function (alarm) {
79 | if (alarm.name === 'store-tab-count') {
80 | storeTabCount();
81 | }
82 | });
83 |
84 | chrome.tabs.onCreated.addListener(storeTabCount);
85 | chrome.tabs.onRemoved.addListener(storeTabCount);
86 |
87 | chrome.windows.onCreated.addListener(storeTabCount);
88 | chrome.windows.onRemoved.addListener(storeTabCount);
89 |
90 |
--------------------------------------------------------------------------------