diff --git a/img/icon-16.png b/img/icon-16.png index eb6f788..c54286e 100644 Binary files a/img/icon-16.png and b/img/icon-16.png differ diff --git a/img/icon-24.png b/img/icon-24.png index cba43ce..da30a0d 100644 Binary files a/img/icon-24.png and b/img/icon-24.png differ diff --git a/img/icon-48.png b/img/icon-48.png index 369f8a8..2839add 100644 Binary files a/img/icon-48.png and b/img/icon-48.png differ diff --git a/img/icon-96.png b/img/icon-96.png index 5a120c7..af6c749 100644 Binary files a/img/icon-96.png and b/img/icon-96.png differ diff --git a/img/icon.afdesign b/img/icon.afdesign new file mode 100644 index 0000000..63c8704 Binary files /dev/null and b/img/icon.afdesign differ diff --git a/img/icon.png b/img/icon.png new file mode 100644 index 0000000..df953e7 Binary files /dev/null and b/img/icon.png differ diff --git a/img/icon.svg b/img/icon.svg index 014523c..e868268 100644 --- a/img/icon.svg +++ b/img/icon.svg @@ -1,23 +1,11 @@ - - - - - - - + + + + + + + + + + diff --git a/img/icon_disabled.png b/img/icon_disabled.png new file mode 100644 index 0000000..2567606 Binary files /dev/null and b/img/icon_disabled.png differ diff --git a/img/icon_disabled.svg b/img/icon_disabled.svg deleted file mode 100644 index 3a5a0ce..0000000 --- a/img/icon_disabled.svg +++ /dev/null @@ -1,58 +0,0 @@ - -image/svg+xml - - - - - diff --git a/img/icon_orange.png b/img/icon_orange.png new file mode 100644 index 0000000..8a56b77 Binary files /dev/null and b/img/icon_orange.png differ diff --git a/img/icon_orange.svg b/img/icon_orange.svg deleted file mode 100644 index 2586655..0000000 --- a/img/icon_orange.svg +++ /dev/null @@ -1,58 +0,0 @@ - -image/svg+xml - - - - - diff --git a/img/icon_red.png b/img/icon_red.png new file mode 100644 index 0000000..550685a Binary files /dev/null and b/img/icon_red.png differ diff --git a/img/icon_red.svg b/img/icon_red.svg deleted file mode 100644 index 4d4c61f..0000000 --- a/img/icon_red.svg +++ /dev/null @@ -1,58 +0,0 @@ - -image/svg+xml - - - - - diff --git a/img/icon_yellow.png b/img/icon_yellow.png new file mode 100644 index 0000000..e1114cf Binary files /dev/null and b/img/icon_yellow.png differ diff --git a/img/icon_yellow.svg b/img/icon_yellow.svg deleted file mode 100644 index b56f3c2..0000000 --- a/img/icon_yellow.svg +++ /dev/null @@ -1,58 +0,0 @@ - -image/svg+xml - - - - - diff --git a/js/background.js b/js/background.js index 60102c9..5177558 100644 --- a/js/background.js +++ b/js/background.js @@ -1,5 +1,6 @@ var timeSpentToday = 0; -//var timeSpentAlways = 0; +var lastNotification = {}; +var lastNotificationDate = 0; var currentUrl = ""; var oldUrl = ""; @@ -16,7 +17,7 @@ var activeTabId; const linkReview = ["https://addons.mozilla.org/firefox/addon/limite/"]; //{firefox add-ons} const linkDonate = ["https://www.paypal.com/pools/c/8yl6auiU6e", "https://ko-fi.com/saveriomorelli", "https://liberapay.com/Sav22999/donate"]; //{paypal, ko-fi} -const icons = ["icon.svg", "icon_disabled.svg", "icon_yellow.svg", "icon_orange.svg", "icon_red.svg"]; +const icons = ["icon.png", "icon_disabled.png", "icon_yellow.png", "icon_orange.png", "icon_red.png"]; function loaded() { browser.tabs.query({active: true, currentWindow: true}, function (tabs) { @@ -86,7 +87,10 @@ function checkStatusEnabled(enabled, force = false) { } else { saveUrlToData(enabled, 0); } - if (!enabled) changeIcon(1); + if (!enabled) { + changeIcon(1); + setBadgeText(""); + } } function tabUpdated(tabId, changeInfo, tabInfo) { @@ -176,6 +180,27 @@ function saveUrlToData(enabled, time = 0) { }); } } + + if (timeSpentToday >= 0 && timeSpentToday < 60 * 30) { + //30 minutes || OK + changeIcon(0); + setBadgeText(((timeSpentToday - (timeSpentToday % 60)) / 60).toString() + "m"); + } else if (timeSpentToday >= 60 * 30 && timeSpentToday < 60 * 60) { + //60 minutes (1 hour) || Yellow + changeIcon(2); + createNotification(2, currentUrl, "30 minutes", "You have already spent 30 minutes on this site today"); + setBadgeText(((timeSpentToday - (timeSpentToday % 60)) / 60).toString() + "m", "#FFD400", "#000000"); + } else if (timeSpentToday >= 60 * 60 && timeSpentToday < 60 * 60 * 3) { + //3 hours || Orange + changeIcon(3); + createNotification(3, currentUrl, "1 hour", "You have already spent 1 hour on this site today"); + setBadgeText(((timeSpentToday - (timeSpentToday % (60 * 60))) / (60 * 60)).toString() + "h", "#FF7C00", "#000000"); + } else if (timeSpentToday >= 60 * 60 * 3) { + //>3 hours || Red + changeIcon(4); + createNotification(4, currentUrl, "3 hours", "You have already spent 3 hours on this site today"); + setBadgeText(">3h", "#FF0000"); + } }) } @@ -192,7 +217,7 @@ function getSavedData(url) { let enabled = false; if (websites_json[urlToUse]["enabled"] != undefined) enabled = websites_json[urlToUse]["enabled"]; switchToOnOrOff(true, enabled); - timeSpentToday=0; + timeSpentToday = 0; if (websites_json[urlToUse][getToday()] != undefined) { timeSpentToday = websites_json[urlToUse][getToday()]; } @@ -261,36 +286,25 @@ function increaseTime(url) { if (url == currentUrl) { saveUrlToData(true, 1); } - - if (timeSpentToday >= 0 && timeSpentToday < 60 * 30) { - //30 minutes || OK - changeIcon(0); - } else if (timeSpentToday >= 60 * 30 && timeSpentToday < 60 * 60) { - //60 minutes (1 hour) || Yellow - changeIcon(2); - //createNotification("30 minutes", "You have already spent 30 minutes on this site today"); - } else if (timeSpentToday >= 60 * 60 && timeSpentToday < 60 * 60 * 3) { - //3 hours || Orange - changeIcon(3); - //createNotification("1 hour", "You have already spent 1 hour on this site today"); - } else if (timeSpentToday >= 60 * 60 * 3) { - //+3 hours || Red - changeIcon(4); - //createNotification("3 hours", "You have already spent 1 hours on this site today"); - } - - //console.log("All websites: " + JSON.stringify(websites_json)); } } -function createNotification(title, content) { +function createNotification(type, url, title, content) { //send a notification - browser.notifications.create({ - "type": "basic", - "iconUrl": "./img/icon-96.png", - "title": title, - "message": content - }); + if (getToday() != lastNotificationDate || lastNotification[url] != type) { + lastNotificationDate = getToday(); + lastNotification[url] = type; + browser.notifications.create({ + "type": "basic", + "iconUrl": "./img/icon-48.png", + "title": title, + "message": content + }); + } else { + //already sent + } + + //console.log(JSON.stringify(lastNotification)); } function getToday() { @@ -320,4 +334,10 @@ function changeIcon(index) { browser.browserAction.setIcon({path: "../img/" + icons[index], tabId: activeTabId}); } -loaded(); \ No newline at end of file +function setBadgeText(text, background_color = "#0080FF", text_color = "#FFFFFF") { + browser.browserAction.setBadgeText({text: text}); + browser.browserAction.setBadgeTextColor({color: text_color}); + browser.browserAction.setBadgeBackgroundColor({color: background_color}); +} + +loaded(); diff --git a/manifest.json b/manifest.json index 6589e18..d1a1968 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Limite", - "version": "1.0.2", + "version": "1.1.1", "description": "Check how much time you spend on each website every day.\nOptimise your productivity, your time and your life as well.\nDon't lose precious time!", "icons": { "16": "./img/icon-16.png",