Skip to content

Commit

Permalink
Update newtab.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SurvivaLlama authored Dec 17, 2023
1 parent 45be9e2 commit a754e55
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions newtab.js
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.';
});
}

0 comments on commit a754e55

Please sign in to comment.