Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

<body>

<div id="notification" class="hidden"></div>

<div id="sidebar" class="sidebar minimised">
<div class="sidebar-handle">
<span class="sidebar-caret"></span>
Expand Down
10 changes: 9 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { showNotification } from "./widgets/notification.js";
import { renderCalendar } from './widgets/calendar.js';
import { renderTodo } from './widgets/todo.js';

Expand Down Expand Up @@ -527,4 +528,11 @@ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e =
if (theme === 'system') {
applyTheme('system');
}
});
});

// On page initialization, check for pending notification
const pendingNotification = localStorage.getItem('pendingNotification');
if (pendingNotification) {
showNotification(pendingNotification, 2000, 'success', false);
localStorage.removeItem('pendingNotification');
}
2 changes: 1 addition & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ <h2>About</h2>
</div>
</div>
<script src="defaultSettings.js"></script>
<script src="options.js"></script>
<script src="options.js" type="module"></script>
</body>

</html>
29 changes: 9 additions & 20 deletions options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { showNotification } from "./widgets/notification.js";

function debounce(func, delay) {
let timeout;
return function(...args) {
Expand All @@ -22,24 +24,6 @@ async function fetchCitySuggestions(query) {
}
}

function showNotification(message, duration = 2000, type = 'success', reload = false) {
const notification = document.getElementById('notification');
notification.textContent = message;
notification.className = 'hidden'; // Reset classes
notification.classList.add(type);
notification.classList.remove('hidden');
notification.classList.add('show');

setTimeout(() => {
notification.classList.remove('show');
setTimeout(() => {
notification.classList.add('hidden');
if (reload) {
location.reload();
}
}, 500); // Wait for fade out before reloading
}, duration);
}

document.addEventListener('DOMContentLoaded', () => {
const settings_keys = [
Expand Down Expand Up @@ -467,7 +451,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (settings_obj.useUnsplash) {
localStorage.removeItem('unsplashData');
}
showNotification("Settings Saved!", 2000, 'success', false);
// Navigate to new tab with a pending notification
localStorage.setItem('pendingNotification', "Settings Saved!");
chrome.tabs.update({ url: "chrome://newtab" });
})

const cityInput = document.getElementById('custom-city');
Expand Down Expand Up @@ -629,7 +615,10 @@ document.getElementById("custom-city").addEventListener('input', () => {
document.getElementById("restore-defaults").addEventListener("click", () => {
localStorage.removeItem("settings");
localStorage.setItem("settings", JSON.stringify(defaultSettings));
showNotification("Settings restored to defaults! Reloading...", 2000, 'restore', true);

// Navigate to new tab with a pending notification
localStorage.setItem('pendingNotification', "Settings restored to defaults!");
chrome.tabs.update({ url: "chrome://newtab" });
});

document.getElementById("show-bookmarks").onchange = (e) => {
Expand Down
19 changes: 19 additions & 0 deletions widgets/notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

export function showNotification(message, duration = 2000, type = 'success', reload = false) {
const notification = window.document.getElementById('notification');
notification.textContent = message;
notification.className = 'hidden'; // Reset classes
notification.classList.add(type);
notification.classList.remove('hidden');
notification.classList.add('show');

setTimeout(() => {
notification.classList.remove('show');
setTimeout(() => {
notification.classList.add('hidden');
if (reload) {
location.reload();
}
}, 500); // Wait for fade out before reloading
}, duration);
}