-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45be9e2
commit a754e55
Showing
1 changed file
with
17 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,40 @@ | ||
// Wait for the DOM to load before running the script | ||
document.addEventListener('DOMContentLoaded', function() { | ||
// Grab the elements from the page | ||
// Grab the 'Set Focus' button and input field elements | ||
var setFocusButton = document.getElementById('setFocusButton'); | ||
var newFocusInput = document.getElementById('newFocusInput'); | ||
var focusText = document.getElementById('focusText'); | ||
document.getElementById('newFocusInput').focus(); | ||
}); | ||
|
||
// Automatically set the focus to the input field when the tab is opened | ||
newFocusInput.focus(); | ||
|
||
// Event listener for the 'Set Focus' button click | ||
// Add a click event listener to the 'Set Focus' button | ||
setFocusButton.addEventListener('click', function() { | ||
// Retrieve the focus from the input field | ||
var dailyFocus = newFocusInput.value; | ||
// Save the daily focus into local storage | ||
chrome.storage.local.set({ 'dailyFocus': dailyFocus }, function() { | ||
// Save the entered focus into local storage | ||
chrome.storage.local.set({ 'dailyFocus': newFocusInput.value }, function() { | ||
// Update the display with the new focus | ||
updateFocusDisplay(); | ||
}); | ||
}); | ||
|
||
// Event listener for the 'Enter' key in the input field | ||
// Add a keypress event listener to trigger the focus set on 'Enter' press | ||
newFocusInput.addEventListener('keypress', function(event) { | ||
// Check if the Enter key was pressed | ||
if (event.key === 'Enter') { | ||
// Save the daily focus into local storage | ||
chrome.storage.local.set({ 'dailyFocus': newFocusInput.value }, function() { | ||
// Update the display with the new focus | ||
updateFocusDisplay(); | ||
}); | ||
} | ||
}); | ||
|
||
// Initial call to display the current focus | ||
// Function to update the focus display | ||
function updateFocusDisplay() { | ||
// Get the daily focus from local storage | ||
chrome.storage.local.get('dailyFocus', function(data) { | ||
// Display the focus or a default message if none is set | ||
focusText.textContent = data.dailyFocus || 'No daily focus set for today.'; | ||
}); | ||
} | ||
|
||
// Call updateFocusDisplay to display the focus when the tab is first opened | ||
updateFocusDisplay(); | ||
}); | ||
|
||
// Function to update the focus display on the page | ||
function updateFocusDisplay() { | ||
// Get the daily focus from local storage | ||
chrome.storage.local.get('dailyFocus', function(data) { | ||
// If there's a focus set, display it, otherwise show the default message | ||
focusText.textContent = data.dailyFocus || 'No daily focus set for today.'; | ||
}); | ||
} | ||
|