Skip to content

Commit

Permalink
added the custom messaages in settings option
Browse files Browse the repository at this point in the history
  • Loading branch information
anvesh-singh committed Oct 9, 2024
1 parent 0aa138e commit 4faf493
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
9 changes: 2 additions & 7 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ <h2>Keyboard Shortcut</h2>
<p class="hint">Press the desired key combination and click Save.</p>
</div>
<p id="message"></p>
<div class="setting-group">
<h2>Custom Alert Message</h2>
<p>Set a custom alert message for yourself as a reminder</p>
<div class="input-group">
<input type="text" id="userinput" placeholder="your message">
<button id="saveMessage">Save</button>
</div>
</div>
<p id="messagesaved"></p>
</div>

<script src="options.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!';
});
});
20 changes: 20 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4faf493

Please sign in to comment.