Skip to content

Commit

Permalink
Merge pull request #7 from anvesh-singh/main
Browse files Browse the repository at this point in the history
#Fixes Enable users to write custom alert messages #5
  • Loading branch information
Nandika-A authored Oct 10, 2024
2 parents 0aa138e + b20dd00 commit e8cbb46
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
7 changes: 1 addition & 6 deletions background.js
Original file line number Diff line number Diff line change
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 e8cbb46

Please sign in to comment.