From 4faf493d64a3bbc4d665a29ea4a12a49bce2e8e6 Mon Sep 17 00:00:00 2001 From: anvesh singh <127198268+anvesh-singh@users.noreply.github.com> Date: Thu, 10 Oct 2024 01:19:19 +0530 Subject: [PATCH 1/2] added the custom messaages in settings option --- background.js | 9 ++------- options.html | 10 ++++++++++ options.js | 7 +++++++ popup.js | 20 ++++++++++++++++++++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/background.js b/background.js index b891724..1565ef3 100644 --- a/background.js +++ b/background.js @@ -5,7 +5,7 @@ let timerInterval; let startTime; let elapsedTime = 0; let isTimerRunning = false; -const firstIntervalDuration = 20 * 60 * 1000; // 20 minutes in milliseconds +const firstIntervalDuration = 0.1667 * 60 * 1000; // 20 minutes in milliseconds const secondIntervalDuration = 20 * 1000; // 20 seconds for break // Start timer @@ -73,12 +73,7 @@ function formatTime(time) { // Function to notify break time function notifyBreakTime() { - chrome.notifications.create("breakTimeNotification", { - type: "basic", - iconUrl: "images/hourglass.png", - title: "Take a break!", - message: "It's time to take a break. Look at something 20 feet away for 20 seconds." - }); + chrome.runtime.sendMessage({ type: "breakTimeNotification"}); } // Function to start short break timer diff --git a/options.html b/options.html index 95fd0e5..9a6de51 100644 --- a/options.html +++ b/options.html @@ -17,7 +17,17 @@

Keyboard Shortcut

Press the desired key combination and click Save.

+
+

Custom Alert Message

+

Set a custom alert message for yourself as a reminder

+
+ + +
+
+

+ diff --git a/options.js b/options.js index cd9f8bd..86f4d02 100644 --- a/options.js +++ b/options.js @@ -44,3 +44,10 @@ shortcutInput.addEventListener('keydown', function(e) { console.log(`Captured keys: ${keys.join('+')}`); shortcutInput.value = keys.join('+'); }); + +document.getElementById('saveMessage').addEventListener('click', function() { + const message = document.getElementById('userinput').value; + chrome.storage.sync.set({ customMessage: message }, function() { + document.getElementById('messagesaved').textContent = 'Message saved successfully!'; + }); +}); \ No newline at end of file diff --git a/popup.js b/popup.js index 315608e..86ea6f9 100644 --- a/popup.js +++ b/popup.js @@ -4,6 +4,13 @@ const startButton = document.getElementById("start"); const resumeButton = document.getElementById("resume"); const resetButton = document.getElementById("reset"); const themeToggle = document.getElementById("theme-toggle"); +let custom_message="It's time to take a break. Look at something 20 feet away for 20 seconds."; + +chrome.storage.sync.get('customMessage', (data)=> { + if (data.customMessage) { + custom_message=data.customMessage; + } +}); // Schedule Tab elements const startTimeInput = document.getElementById("startTime"); @@ -73,8 +80,21 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { if (message.type === "updateTimer") { timerElement.textContent = message.time; } + else if(message.type === "breakTimeNotification"){ + chrome.notifications.create("breakTimeNotification", { + type: "basic", + iconUrl: "images/hourglass.png", + title: "Take a break!", + message: custom_message + }); + } + + }); + + + // Function to save the schedule saveScheduleButton.addEventListener("click", function() { const startTime = startTimeInput.value; From b20dd00ac373068958a782196f32fb03e7e59d57 Mon Sep 17 00:00:00 2001 From: anvesh singh <127198268+anvesh-singh@users.noreply.github.com> Date: Thu, 10 Oct 2024 01:22:31 +0530 Subject: [PATCH 2/2] fixed final changes --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index 1565ef3..0cbef91 100644 --- a/background.js +++ b/background.js @@ -5,7 +5,7 @@ let timerInterval; let startTime; let elapsedTime = 0; let isTimerRunning = false; -const firstIntervalDuration = 0.1667 * 60 * 1000; // 20 minutes in milliseconds +const firstIntervalDuration = 20 * 60 * 1000; // 20 minutes in milliseconds const secondIntervalDuration = 20 * 1000; // 20 seconds for break // Start timer