-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopup.js
More file actions
84 lines (72 loc) · 2.75 KB
/
popup.js
File metadata and controls
84 lines (72 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
$('#settings').submit(function(e){
e.preventDefault();
console.log(duration)
var data = {};
var duration = $("#duration").val();
data["popupTimer"] = duration/1; //used to make duration an integer
chrome.storage.local.set(data,function(){console.log("stored")});
// Generates alarm
//var alarmParam = {}
//alarmParam["delayInMinutes"] = duration/1;
//console.log(alarmParam);
//chrome.alarms.create(alarmParam);
timeRemaining();
$('#editTime').toggle();
$('#timeRemain').toggle();
$('#editButton').toggle();
});
var blacklist = ["facebook","twitter","tumblr","youtube","messenger","reddit","twitch"];
function timeRemaining(){
chrome.storage.local.get(null, function (object) {
var blackListTime = 0;
var totalTime = 0;
var data = {};
for (var url in object) {
for (var i in blacklist){
if (url.includes(blacklist[i])){
// console.log(blacklist[i]);
// console.log(object);
// console.log(url);
// console.log(object[url]);
var data_for_url = JSON.parse(object[url]);
var visitTimeTotal = 0;
for (var visitTime in data_for_url) {
var visitLength = data_for_url[visitTime];
var date = new Date(parseInt(visitTime));
var currentDate = new Date();
if (date > new Date(currentDate.getTime() - 1440 * 60 * 1000)) {
visitTimeTotal = visitTimeTotal + visitLength;
}
}
blackListTime+=visitTimeTotal;
// console.log(blackListTime);
}
}
//copied of code above, may make it a function later
var data_for_url = JSON.parse(object[url]);
var visitTimeTotal = 0;
for (var visitTime in data_for_url) {
var visitLength = data_for_url[visitTime];
var date = new Date(parseInt(visitTime));
var currentDate = new Date();
if (date > new Date(currentDate.getTime() - 1440 * 60 * 1000)) {
visitTimeTotal = visitTimeTotal + visitLength;
}
}
totalTime+=visitTimeTotal;
}
chrome.storage.local.get("popupTimer",function(result){
var diff = (result["popupTimer"]*60)-blackListTime;
//$('#remaining').text("Time Left: "+Math.round(diff)+" seconds (~"+Math.round(diff/60)+" mins)");
$('#status').text("Total Time: ~"+Math.round(totalTime/60)+" mins Unproductive Time: ~"+Math.round(blackListTime/60)+" mins (Time Left: ~"+Math.round(diff/60)+" mins)");
});
});
}
$('#editButton').click(function(){
$('#editTime').toggle();
$('#timeRemain').toggle();
$('#editButton').toggle();
});
$(document).ready(function(){
timeRemaining();
});