-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
203 lines (186 loc) · 4.99 KB
/
popup.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE>
<!--
* Copyright (c) 2011 Jordi Corbilla. All rights reserved.
-->
<html>
<head>
<script type="text/javascript" src="js/popup.js"></script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"
type="text/javascript"></script>
<script src="js/iphone-style-checkboxes.js" type="text/javascript"
charset="utf-8"></script>
<link rel="stylesheet" href="style.css" type="text/css" media="screen"
charset="utf-8" />
<style type="text/css">
body {
padding: 10px;
}
th {
text-align: left;
padding: 4px;
padding-right: 15px;
vertical-align: top;
font-family: Verdana;
font-size: 14px;
}
tr {
font-family: Verdana, Courier;
font-size: 11px;
}
.current_stuff { //
color: red;
font-style: oblique;
font-weight: bold;
}
.total_stuff {
//text-decoration: overline;
}
.toggle_checkbox .iPhoneCheckContainer {
width: 50px;
height: 30px;
}
#header-button {
background: url("images/close.png") top right no-repeat;
display: block;
float: right;
height: 16px;
margin-top: 2px;
width: 16px;
}
#header-button:hover {
background: url("images/close-hover.png") top right no-repeat;
cursor: pointer;
}
#header-button:active {
background: url("images/close-active.png") top right no-repeat;
}
</style>
<script type="text/javascript">
$(window).load(function() {
$('.current_stuff :checkbox').iphoneStyle();
$('.toggle_checkbox :checkbox').iphoneStyle({
resizeContainer : false,
resizeHandle : false
});
$('.listed_stuff :checkbox').iphoneStyle();
$('#header-button').on("click", function() {
self.close();
});
});
var oneHour = 60;//1 hour in minute
var site = null;
var time = 0;
function initialize() {
if (!localStorage.pause)
localStorage.pause = "false";//localStorage only stores string value
var sortedSites = new Array();
var totalTime = 0;
var top = 10;
for ( var i = 0; i < localStorage.length; i++) {
site = localStorage.key(i);
time = localStorage.getItem(site);
if (site == "pause")
continue;
sortedSites.push([ site, time ]);
totalTime += time * 1;
}
chrome.tabs.getSelected(null, function(tab) {
var currentURL = tab.url
var currentSite = getSiteFromURL(currentURL);
if (currentSite != null) {
var csTime = localStorage.getItem(currentSite);
var csHours = Math.floor(csTime / oneHour);
var csMinutes = Math.floor(csTime - csHours * oneHour);
$('#currentSite_time').text(csHours + "h:" + csMinutes + "'");
$('#currentSite_percent').text(
Math.round((csTime / totalTime) * 10000) / 100 + "%");
} else
currentSite = currentURL;
$('#currentSite').text(currentSite);
console.log(currentSite);
});
sortedSites.sort(function(a, b) {
return b[1] - a[1];
});
var table = document.getElementById("myTable");
console.log(top);
for ( var j = 0; (j < top) && (j < sortedSites.length); j++) {
site = sortedSites[j][0];
time = sortedSites[j][1];
var hours = Math.floor(time / oneHour);
var minutes = Math.floor(time - hours * oneHour);
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
row.setAttribute('class', 'listed_stuff');
cell1.innerHTML = site;
cell2.innerHTML = hours + "h:" + minutes + "'";
cell3.innerHTML = Math.round((time / totalTime) * 10000) / 100
+ "%";
var chkbox = document.createElement("input");
chkbox.type = "checkbox";
chkbox.checked = "checked";
cell4.appendChild(chkbox);
}
var totalHours = Math.floor(totalTime / oneHour);
var totalMinutes = Math.floor(totalTime - totalHours * oneHour);
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
row.setAttribute('class', 'total_stuff');
cell1.innerHTML = "Total";
cell2.innerHTML = totalHours + "h:" + totalMinutes + "'";
cell3.innerHTML = "100%";
var chkbox = document.createElement('input');
chkbox.type = 'checkbox';
cell4.appendChild(chkbox);
console.log(totalTime);
if (localStorage.pause == "true")
$('.total_stuff :checkbox').prop("checked", false);
else
$('.total_stuff :checkbox').prop("checked", true);
($('.total_stuff :checkbox')).iphoneStyle({
onChange : function() {
if (localStorage.pause == "false")
localStorage.pause = "true";
else
localStorage.pause = "false";
console.log("Pause changed, new value: " + localStorage.pause);
}
});
}
</script>
</head>
<body>
<div id="header-elements">
<div id="header-button"></div>
</div>
<table id="myTable" width=350>
<tr>
<th>Website</th>
<th>Time</th>
<th>Percent</th>
<th>Tracking</th>
</tr>
<tr>
<td colspan=4><hr size=1></td>
</tr>
<tr class="current_stuff">
<td id="currentSite"></td>
<td id="currentSite_time"></td>
<td id="currentSite_percent"></td>
<td><input type="checkbox"></td>
</tr>
<tr>
<td colspan=4><hr size=1></td>
</tr>
</table>
<script>
initialize();
</script>
</body>
</html>