diff --git a/src/index.html b/src/index.html
index 68bc570..74a8876 100644
--- a/src/index.html
+++ b/src/index.html
@@ -39,6 +39,7 @@
diff --git a/src/manifest.json b/src/manifest.json
index 8fbd0bd..78ca402 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -3,7 +3,7 @@
"name": "Web Activity Time Tracker",
"short_name": "Web Time Tracker",
- "version": "1.3.4",
+ "version": "1.5.0",
"minimum_chrome_version": "26",
"description": "Track and limit time your activity in the browser every day.",
@@ -27,6 +27,7 @@
],
"optional_permissions": [
"https://www.youtube.com/*",
+ "https://www.netflix.com/*",
"notifications"
],
"offline_enabled": true,
diff --git a/src/options.html b/src/options.html
index 4ac4756..e8f6dda 100644
--- a/src/options.html
+++ b/src/options.html
@@ -82,13 +82,17 @@
+
+
+
+
+
+
+
+
+
+

+
+
+
+
diff --git a/src/scripts/background.js b/src/scripts/background.js
index d069ceb..47d3eef 100644
--- a/src/scripts/background.js
+++ b/src/scripts/background.js
@@ -16,6 +16,7 @@ var setting_notification_list;
var setting_notification_message;
var isHasPermissioForYouTube;
+var isHasPermissioForNetflix;
var isHasPermissioForNotification;
function updateSummaryTime() {
@@ -145,18 +146,28 @@ function isVideoPlayedOnPage() {
function checkDOM(state, activeUrl, tab, activeTab) {
if (state === 'idle' && isDomainEquals(activeUrl, "youtube.com")) {
trackForYT(mainTRacker, activeUrl, tab, activeTab);
+ } else if (state === 'idle' && isDomainEquals(activeUrl, "netflix.com")) {
+ trackForNetflix(mainTRacker, activeUrl, tab, activeTab);
} else activity.closeIntervalForCurrentTab();
}
function trackForYT(callback, activeUrl, tab, activeTab) {
if (isHasPermissioForYouTube) {
- executeScript(callback, activeUrl, tab, activeTab);
+ executeScriptYoutube(callback, activeUrl, tab, activeTab);
} else {
- checkPermissionsForYT(executeScript, activity.closeIntervalForCurrentTab, callback, activeUrl, tab, activeTab);
+ checkPermissionsForYT(executeScriptYoutube, activity.closeIntervalForCurrentTab, callback, activeUrl, tab, activeTab);
}
}
-function executeScript(callback, activeUrl, tab, activeTab) {
+function trackForNetflix(callback, activeUrl, tab, activeTab) {
+ if (isHasPermissioForNetflix) {
+ executeScriptNetflix(callback, activeUrl, tab, activeTab);
+ } else {
+ checkPermissionsForNetflix(executeScriptNetflix, activity.closeIntervalForCurrentTab, callback, activeUrl, tab, activeTab);
+ }
+}
+
+function executeScriptYoutube(callback, activeUrl, tab, activeTab) {
chrome.tabs.executeScript({ code: "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" }, (results) => {
if (results !== undefined && results[0] !== undefined && results[0] === true)
callback(activeUrl, tab, activeTab);
@@ -164,6 +175,16 @@ function executeScript(callback, activeUrl, tab, activeTab) {
});
}
+function executeScriptNetflix(callback, activeUrl, tab, activeTab) {
+ chrome.tabs.executeScript({ code: "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" }, (results) => {
+ if (results !== undefined && results[0] !== undefined && results[0] === true) {
+ callback(activeUrl, tab, activeTab);
+ } else {
+ activity.closeIntervalForCurrentTab();
+ }
+ });
+}
+
function backgroundUpdateStorage() {
if (tabs != undefined && tabs.length > 0)
storage.saveTabs(tabs);
@@ -324,6 +345,7 @@ function loadAddDataFromStorage() {
function loadPermissions() {
checkPermissionsForYT();
+ checkPermissionsForNetflix();
checkPermissionsForNotifications();
}
@@ -340,6 +362,19 @@ function checkPermissionsForYT(callbackIfTrue, callbackIfFalse, ...props) {
});
}
+function checkPermissionsForNetflix(callbackIfTrue, callbackIfFalse, ...props) {
+ chrome.permissions.contains({
+ permissions: ['tabs'],
+ origins: ["https://www.netflix.com/*"]
+ }, function(result) {
+ if (callbackIfTrue != undefined && result)
+ callbackIfTrue(...props);
+ if (callbackIfFalse != undefined && !result)
+ callbackIfFalse();
+ isHasPermissioForNetflix = result;
+ });
+}
+
function checkPermissionsForNotifications(callback, ...props) {
chrome.permissions.contains({
permissions: ["notifications"]
diff --git a/src/scripts/settings.js b/src/scripts/settings.js
index eb33fdf..a1a56b6 100644
--- a/src/scripts/settings.js
+++ b/src/scripts/settings.js
@@ -46,6 +46,9 @@ document.addEventListener('DOMContentLoaded', function () {
document.getElementById('grantPermissionForYT').addEventListener('click', function () {
grantPermissionForYT();
});
+ document.getElementById('grantPermissionForNetflix').addEventListener('click', function () {
+ grantPermissionForNetflix();
+ });
document.getElementById('grantPermissionForNotifications').addEventListener('click', function () {
grantPermissionForNotifications();
});
@@ -107,6 +110,7 @@ function loadSettings() {
document.getElementById('notifyMessage').value = mess;
});
checkPermissionsForYT();
+ checkPermissionsForNetflix();
checkPermissionsForNotifications();
}
@@ -121,6 +125,17 @@ function checkPermissionsForYT() {
});
}
+function checkPermissionsForNetflix() {
+ chrome.permissions.contains({
+ permissions: ['tabs'],
+ origins: ["https://www.netflix.com/*"]
+ }, function (result) {
+ if (result) {
+ setUIForAnyPermissionForNetflix();
+ }
+ });
+}
+
function checkPermissionsForNotifications() {
chrome.permissions.contains({
permissions: ["notifications"]
@@ -156,6 +171,18 @@ function grantPermissionForYT() {
});
}
+function grantPermissionForNetflix() {
+ chrome.permissions.request({
+ permissions: ['tabs'],
+ origins: ["https://www.netflix.com/*"]
+ }, function (granted) {
+ // The callback argument will be true if the user granted the permissions.
+ if (granted) {
+ setUIForAnyPermissionForNetflix();
+ }
+ });
+}
+
function grantPermissionForNotifications() {
chrome.permissions.request({
permissions: ["notifications"]
@@ -172,6 +199,11 @@ function setUIForAnyPermissionForYT() {
document.getElementById('grantPermissionForYT').setAttribute('disabled', 'true');
}
+function setUIForAnyPermissionForNetflix() {
+ document.getElementById('permissionSuccessedBlockForNetflix').hidden = false;
+ document.getElementById('grantPermissionForNetflix').setAttribute('disabled', 'true');
+}
+
function setUIForAnyPermissionForNotifications() {
document.getElementById('permissionSuccessedBlockForNotifications').hidden = false;
document.getElementById('grantPermissionForNotifications').setAttribute('disabled', 'true');