Skip to content

Commit 4e9f820

Browse files
committed
Merge branch 'dev-without-permissions' of https://bitbucket.org/Stigmat/chrome_extension into dev
2 parents 75174d0 + 9288e99 commit 4e9f820

File tree

5 files changed

+92
-19
lines changed

5 files changed

+92
-19
lines changed

manifest.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"name": "Web Activity Time Tracker",
55
"short_name": "Web Activity",
6-
"version": "0.8.0",
6+
"version": "0.8.1",
77
"minimum_chrome_version": "26",
88

99
"description": "Track your activity in the browser.",
@@ -23,9 +23,12 @@
2323
"idle",
2424
"chrome://favicon/*",
2525
"webNavigation",
26-
"unlimitedStorage",
27-
"<all_urls>"
26+
"unlimitedStorage"
2827
],
28+
"optional_permissions": [
29+
"http://*/*",
30+
"https://*/*"
31+
],
2932
"offline_enabled": true,
3033
"background": {
3134
"scripts": ["scripts/common.js",

options.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@
8181
<div class="margin-top-10">
8282
<input type="button" value="Export to CSV" id='exportToCsv'>
8383
</div>
84+
<div class="margin-top-10">
85+
<label class="block">Web Activity Time Tracker tracks your activity, if you active in browser (mouse
86+
or keyboard).
87+
In order for the extension to also track when you watch a video, you must grant permissions to
88+
access the sites.
89+
It is necessary that extension will get access to DOM (Document Object Model).</label>
90+
<input class="margin-top-10" type="button" value="Grant permission" id='grantPermission'>
91+
<div class="inline-block">
92+
<div id='permissionSuccessedBlock' hidden>
93+
<img src="/icons/success.png" height="18" />
94+
<label>Permissions have been granted</label>
95+
</div>
96+
</div>
97+
</div>
8498
<div class="margin-top-10">
8599
<label>Data in memory use </label><label id='memoryUse'></label>
86100
</div>
@@ -132,9 +146,11 @@
132146
<input type="hidden" name="business" value="JBQEMTYGHGJVS" />
133147
<input type="hidden" name="item_name" value="Web Activity Time Tracker" />
134148
<input type="hidden" name="currency_code" value="USD" />
135-
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" />
149+
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0"
150+
name="submit" title="PayPal - The safer, easier way to pay online!"
151+
alt="Donate with PayPal button" />
136152
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
137-
</form>
153+
</form>
138154
</div>
139155
</div>
140156
</div>

scripts/background.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,24 @@ function isVideoPlayedOnPage() {
104104

105105
function checkDOM(state, activeUrl, tab, activeTab) {
106106
if (state === 'idle') {
107-
chrome.tabs.executeScript({ code: "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" }, (results) => {
108-
if (results !== undefined && results[0] !== undefined && results[0] === true)
109-
mainTRacker(activeUrl, tab, activeTab);
110-
});
107+
checkPermissions(mainTRacker, activeUrl, tab, activeTab);
111108
}
112109
}
113110

111+
function checkPermissions(callback, activeUrl, tab, activeTab){
112+
chrome.permissions.contains({
113+
permissions: ['tabs'],
114+
origins: ["http://*/*", "https://*/*"]
115+
}, function(result) {
116+
if (result) {
117+
chrome.tabs.executeScript({ code: "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" }, (results) => {
118+
if (results !== undefined && results[0] !== undefined && results[0] === true)
119+
callback(activeUrl, tab, activeTab);
120+
});
121+
}
122+
});
123+
}
124+
114125
function backgroundUpdateStorage() {
115126
if (tabs != undefined && tabs.length > 0)
116127
storage.saveTabs(tabs);

scripts/settings.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ document.addEventListener('DOMContentLoaded', function () {
3636
document.getElementById('rangeToDays').addEventListener('change', function () {
3737
storage.saveSettings(SETTINGS_INTERVAL_RANGE, this.value);
3838
});
39+
document.getElementById('grantPermission').addEventListener('click', function () {
40+
grantPermission();
41+
});
3942
$('.clockpicker').clockpicker();
4043

4144
loadSettings();
@@ -81,6 +84,18 @@ function loadSettings() {
8184
restrictionList = [];
8285
viewRestrictionList(items);
8386
});
87+
checkPermissions();
88+
}
89+
90+
function checkPermissions() {
91+
chrome.permissions.contains({
92+
permissions: ['tabs'],
93+
origins: ["http://*/*", "https://*/*"]
94+
}, function (result) {
95+
if (result) {
96+
setUIForAnyPermission();
97+
}
98+
});
8499
}
85100

86101
function loadVersion() {
@@ -96,6 +111,23 @@ function viewBlackList(items) {
96111
}
97112
}
98113

114+
function grantPermission() {
115+
chrome.permissions.request({
116+
permissions: ['tabs'],
117+
origins: ["http://*/*", "https://*/*"]
118+
}, function (granted) {
119+
// The callback argument will be true if the user granted the permissions.
120+
if (granted) {
121+
setUIForAnyPermission();
122+
}
123+
});
124+
}
125+
126+
function setUIForAnyPermission() {
127+
document.getElementById('permissionSuccessedBlock').hidden = false;
128+
document.getElementById('grantPermission').setAttribute('disabled', 'true');
129+
}
130+
99131
function viewRestrictionList(items) {
100132
if (items !== undefined) {
101133
for (var i = 0; i < items.length; i++) {
@@ -104,27 +136,27 @@ function viewRestrictionList(items) {
104136
}
105137
}
106138

107-
function exportToCSV(){
139+
function exportToCSV() {
108140
storage.getSettings(STORAGE_TABS, function (item) {
109141
toCsv(item);
110142
});
111143
}
112144

113-
function toCsv(tabsData){
145+
function toCsv(tabsData) {
114146
var str = 'domain,time(sec)\r\n';
115147
for (var i = 0; i < tabsData.length; i++) {
116148
var line = tabsData[i].url + ',' + tabsData[i].summaryTime;
117149
str += line + '\r\n';
118150
}
119-
120-
var csvFile = new Blob([str], {type:"text/csv"});
151+
152+
var csvFile = new Blob([str], { type: "text/csv" });
121153
var downloadLink;
122-
downloadLink = document.createElement("a");
123-
downloadLink.download = 'domains.csv';
124-
downloadLink.href = window.URL.createObjectURL(csvFile);
125-
downloadLink.style.display = "none";
126-
document.body.appendChild(downloadLink);
127-
downloadLink.click();
154+
downloadLink = document.createElement("a");
155+
downloadLink.download = 'domains.csv';
156+
downloadLink.href = window.URL.createObjectURL(csvFile);
157+
downloadLink.style.display = "none";
158+
document.body.appendChild(downloadLink);
159+
downloadLink.click();
128160
}
129161

130162
function clearAllData() {

style/settings.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ input[type="button"]:hover {
181181
text-decoration: none;
182182
}
183183

184+
185+
input[type="button"][disabled]{
186+
border: 1px solid #999999;
187+
background-color: #cccccc;
188+
color: #666666;
189+
}
190+
184191
.margin-top-10{
185192
margin-top: 10px;
186193
}
@@ -237,6 +244,10 @@ input[type="button"]:hover {
237244
opacity: 1;
238245
}
239246

247+
.hidden{
248+
display: none;
249+
}
250+
240251
.notify{
241252
width: 200px;
242253
height: 27px;

0 commit comments

Comments
 (0)