Skip to content

Commit 3417e29

Browse files
committed
Added URL uploading
URL data and time now gets uploaded on changing tabs
1 parent 5ff0c2d commit 3417e29

9 files changed

+79
-56
lines changed

background.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-app.js"></script>
5+
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-firestore.js"></script>
6+
<script src="./init-firebase.js"></script>
7+
<script src="./config.js"></script>
8+
<script src="./sites.js"></script>
9+
<script src="./tracker.js"></script>
10+
<script src="./background.js"></script>
11+
<script src="./videoRecord.js"></script>
12+
</head>
13+
<body></body>
14+
</html>

background.js

+1
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ chrome.alarms.onAlarm.addListener(function(alarm) {
7373
clearStats(config);
7474
}
7575
});
76+

manifest.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
"default_popup": "popup.html",
88
"default_title": "Monitoring Extension"
99
},
10-
"content_security_policy": "script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://ssl.google-analytics.com; object-src 'self'",
10+
"content_security_policy": "script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://ssl.google-analytics.com; object-src 'self';",
1111
"background": {
1212
"persistent": true,
13-
"scripts": ["config.js", "sites.js", "tracker.js", "background.js","videoRecord.js"]
13+
"page":"background.html"
1414
},
1515
"manifest_version": 2,
16-
"oauth2": {
17-
"client_id": "980342292470-ttlch1q7jn30l0atg06eeqb0r8u5qmvk.apps.googleusercontent.com",
18-
"scopes": [ "https://www.googleapis.com/auth/drive.file" ]
19-
},
2016
"options_page": "options.html",
2117
"icons": { "19": "images/icon19.png", "38": "images/icon38.png",
2218
"128": "images/icon.png" },

options.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
<body>
1111
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-app.js"></script>
12-
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-firestore.js"></script>
13-
<script src="./init-firebase.js"></script>
12+
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-firestore.js"></script>
13+
<script src="./init-firebase.js"></script>
1414
<b>Time Display</b>:
1515
<select id="time_display" class="pure-input-1-2">
1616
<option value="0">Pretty</option>

options.js

+1-35
Original file line numberDiff line numberDiff line change
@@ -91,52 +91,18 @@ function restoreOptions() {
9191
}
9292
}
9393

94-
function getTimestamp() {
95-
var e = new Date,
96-
t = e.getFullYear(),
97-
o = ("00" + (e.getMonth() + 1)).slice(-2),
98-
n = ("00" + e.getDate()).slice(-2),
99-
r = ("00" + e.getHours()).slice(-2),
100-
s = ("00" + e.getMinutes()).slice(-2),
101-
i = t + "-" + o + "-" + n + "_" + r + "-" + s;
102-
return i
103-
}
104-
105-
//Timer for peiodic uploads
106-
var time=0;
107-
10894
function download() {
10995
var csvContent = "data:text/csv;charset=utf-8,";
11096
var sitesDict = sites.sites;
11197
var pairs = [];
112-
var dict={}
98+
var dict={};
11399
for (var site in sitesDict) {
114100
if (sitesDict.hasOwnProperty(site)) {
115101
pairs.push(site + "," + sitesDict[site]);
116-
dict[site]=sitesDict[site];
117102
}
118103
}
119104
csvContent += pairs.join("\n");
120105
window.open(encodeURI(csvContent));
121-
122-
// for (index = 0; index < pairs.length; index++){
123-
db.collection("tracking_test").add({
124-
// url: pairs[index].split(",")[0],
125-
// time: parseFloat(pairs[index].split(",")[1])
126-
// url:pairs.split(",")[0],
127-
// time:parseFloat(pairs.split(",")[1])
128-
url:dict[0],
129-
time:dict[1],
130-
uploading_time:getTimestamp()
131-
})
132-
.then(function(docRef) {
133-
console.log("Document written with ID: ", docRef.id);
134-
})
135-
.catch(function(error) {
136-
console.error("Error adding document: ", error);
137-
});
138-
// }
139-
140106
}
141107

142108
document.addEventListener("DOMContentLoaded", function () {

popup.html

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<script src="popup.js"></script>
2222
</head>
2323
<body>
24+
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-app.js"></script>
25+
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-firestore.js"></script>
26+
<script src="./init-firebase.js"></script>
2427
<div id="button_row">
2528
<button id="options" class="pure-button">Options</button>&nbsp;
2629
<button id="clear" class="pure-button">Clear</button>&nbsp;

sites.js

+45-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
*
44
* The primary interface to this class is through setCurrentFocus.
55
*/
6+
var globt=0;
7+
var prev_url=null;
8+
var prev_domain=null;
9+
var start_time;
10+
611
function Sites(config) {
712
this._config = config;
813
if (!localStorage.sites) {
@@ -48,7 +53,7 @@ Sites.prototype._updateTime = function() {
4853
return;
4954
}
5055
var delta = new Date() - this._startTime;
51-
console.log("Site: " + this._currentSite + " Delta = " + delta/1000);
56+
// console.log("Site: " + this._currentSite + " Delta = " + delta/1000);
5257
if (delta/1000/60 > 2*this._config.updateTimePeriodMinutes) {
5358
console.log("Delta of " + delta/1000 + " seconds too long; ignored.");
5459
return;
@@ -58,6 +63,7 @@ Sites.prototype._updateTime = function() {
5863
sites[this._currentSite] = 0;
5964
}
6065
sites[this._currentSite] += delta/1000;
66+
globt=delta/1000;
6167
localStorage.sites = JSON.stringify(sites);
6268
};
6369

@@ -66,7 +72,7 @@ Sites.prototype._updateTime = function() {
6672
* Provide url=null if Chrome is out of focus.
6773
*/
6874
Sites.prototype.setCurrentFocus = function(url) {
69-
console.log("setCurrentFocus: " + url);
75+
// console.log("setCurrentFocus: " + url);
7076
this._updateTime();
7177
if (url == null) {
7278
this._currentSite = null;
@@ -75,8 +81,22 @@ Sites.prototype.setCurrentFocus = function(url) {
7581
{path: {19: 'images/icon_paused19.png',
7682
38: 'images/icon_paused38.png'}});
7783
} else {
84+
if(globt>1 && prev_url!=="" && prev_domain!==null){
85+
siteInfo={
86+
url:prev_url,
87+
site:prev_domain,
88+
time:globt,
89+
start_time: start_time,
90+
uploading_time:getTimestamp()
91+
}
92+
console.log(siteInfo);
93+
uploadInfo(siteInfo);
94+
}
95+
prev_url=url;
96+
prev_domain=this.getSiteFromUrl(prev_url);
7897
this._currentSite = this.getSiteFromUrl(url);
7998
this._startTime = new Date();
99+
start_time= getTimestamp();
80100
chrome.browserAction.setIcon(
81101
{path: {19: 'images/icon19.png',
82102
38: 'images/icon38.png'}});
@@ -90,3 +110,26 @@ Sites.prototype.clear = function() {
90110
localStorage.sites = JSON.stringify({});
91111
this._config.lastClearTime = new Date().getTime();
92112
};
113+
114+
115+
116+
uploadInfo = (siteInfo) =>{
117+
db.collection("tracking_test").add(siteInfo)
118+
.then(function(docRef) {
119+
console.log("Document written with ID: ", docRef.id);
120+
})
121+
.catch(function(error) {
122+
console.error("Error adding document: ", error);
123+
});
124+
};
125+
function getTimestamp() {
126+
var e = new Date,
127+
t = e.getFullYear(),
128+
o = ("00" + (e.getMonth() + 1)).slice(-2),
129+
n = ("00" + e.getDate()).slice(-2),
130+
r = ("00" + e.getHours()).slice(-2),
131+
s = ("00" + e.getMinutes()).slice(-2),
132+
i = t + "-" + o + "-" + n + "_" + r + "-" + s;
133+
return i;
134+
}
135+

tracker.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/**
22
* Responsible for detecting focus change from tabs and windows.
33
*/
4+
5+
var startDate=new Date();
46
function Tracker(config, sites) {
57
this._sites = sites;
68
var self = this;
79
chrome.tabs.onUpdated.addListener(
810
function(tabId, changeInfo, tab) {
11+
// console.log("Trying1");
12+
913
// This tab has updated, but it may not be on focus.
1014
// It is more reliable to request the current tab URL.
1115
self._updateTimeWithCurrentTab();
@@ -14,6 +18,9 @@ function Tracker(config, sites) {
1418
chrome.tabs.onActivated.addListener(
1519
function(activeInfo) {
1620
chrome.tabs.get(activeInfo.tabId, function(tab) {
21+
// console.log("Trying2");
22+
// console.log(self);
23+
// upload(tab.url,)
1724
self._sites.setCurrentFocus(tab.url);
1825
});
1926
}
@@ -24,15 +31,18 @@ function Tracker(config, sites) {
2431
self._sites.setCurrentFocus(null);
2532
return;
2633
}
34+
// console.log("Trying3"+document.title);
2735
self._updateTimeWithCurrentTab();
2836
}
2937
);
3038
chrome.idle.onStateChanged.addListener(function(idleState) {
3139
if (idleState == "active") {
3240
config.idle = false;
41+
// console.log("Trying4"+document.title);
3342
self._updateTimeWithCurrentTab();
3443
} else {
3544
config.idle = true;
45+
// console.log("Trying5");
3646
self._sites.setCurrentFocus(null);
3747
}
3848
});

videoRecord.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var autoUploading;
1212
var startTime;
1313
var finishTime;
1414
var uploadTimer;
15+
var flag=0;
1516
var gumVideo = document.querySelector('#video');
1617
var $timer = document.querySelector('#timer');
1718
var $stopBtn = document.querySelector('#stop');
@@ -53,22 +54,11 @@ function handleDataAvailable(event) {
5354
}
5455
}
5556

56-
//var downloadLink=document.getElementById("download");
57-
5857
function handleStop(event) {
5958
console.log('Recorder stopped: ', event);
6059
}
6160

6261

63-
function toggleRecording() {
64-
if (recordButton.textContent === 'Start Recording') {
65-
startRecording();
66-
} else {
67-
stopRecording();
68-
}
69-
}
70-
71-
7262
// The nested try blocks will be simplified when Chrome 47 moves to Stable
7363
function startRecording() {
7464
var options = {

0 commit comments

Comments
 (0)