Skip to content

Commit 6b7db40

Browse files
committed
dynamic favicon, offline mode
1 parent 1ee81eb commit 6b7db40

19 files changed

+214
-113
lines changed

clipboard.min.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

favicon-blue.ico

37.7 KB
Binary file not shown.

favicon-green.ico

38.1 KB
Binary file not shown.

favicon-pink.ico

37.7 KB
Binary file not shown.

favicon-purple.ico

38.1 KB
Binary file not shown.

favicon-yellow.ico

36.6 KB
Binary file not shown.

favicon.ico

8.49 KB
Binary file not shown.

functions.js

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ const colorOptions = {
9090
pink: 'color-scheme-pink'
9191
};
9292

93+
// Define the favicon options
94+
const faviconOptions = {
95+
yellow: 'favicon-yellow.ico',
96+
green: 'favicon-green.ico',
97+
blue: 'favicon-blue.ico',
98+
purple: 'favicon-purple.ico',
99+
pink: 'favicon-pink.ico'
100+
};
101+
93102
// check if there is a color preference stored in localStorage
94103
const colorPref = localStorage.getItem( 'colorPref' );
95104

@@ -105,6 +114,8 @@ Object.keys(colorOptions).forEach(color => {
105114
button.addEventListener('click', () => {
106115
setTheme(colorOptions[color]);
107116
localStorage.setItem('colorPref', color);
117+
updateFavicon( color );
118+
108119
Object.keys(colorOptions).forEach(otherColor => {
109120
const otherButton = document.getElementById(`${otherColor}-button`);
110121
if (color === otherColor) {
@@ -135,23 +146,46 @@ function setTheme(theme) {
135146
});
136147
}
137148

149+
// Update the favicon according to the current color
150+
function updateFavicon(color) {
151+
const favicon = document.querySelector("link[rel*='icon']");
152+
favicon.href = faviconOptions[color];
153+
}
154+
155+
// Update the initial favicon
156+
updateFavicon(colorPref ? colorPref : 'yellow');
157+
138158
// Copy characters to clipboard
139159
var charButtons = document.querySelectorAll( '.char-button' );
140-
charButtons.forEach(function(button) {
141-
button.addEventListener('click', function() {
142-
var charText = this.getAttribute( 'data-clipboard-text' );
143-
navigator.clipboard.writeText(charText).then(function() {
144-
var confirmationText = '<span class="character">' + charText + '</span>' +
160+
charButtons.forEach(function (button) {
161+
button.addEventListener('click', function () {
162+
var charText = this.getAttribute('data-clipboard-text');
163+
navigator.clipboard.writeText(charText).then(function () {
164+
var confirmationText = '<span class="character">' + charText + '</span>' +
145165
'<span class="message"> copied to clipboard</span>';
146-
var confirmationElement = document.getElementById( 'confirmation-message' );
147-
var confirmationInnerElement = confirmationElement.querySelector( '.copy-confirmation-inner' );
148-
confirmationInnerElement.innerHTML = confirmationText;
149-
confirmationElement.classList.add( 'visible' );
150-
setTimeout(function() {
151-
confirmationElement.classList.remove( 'visible' );
152-
}, 750); // Remove "visible" class after 750 mms
153-
}, function() {
154-
console.error( 'Failed to copy to clipboard' );
166+
var confirmationElement = document.getElementById('confirmation-message');
167+
var confirmationInnerElement = confirmationElement.querySelector('.copy-confirmation-inner');
168+
confirmationInnerElement.innerHTML = confirmationText;
169+
confirmationElement.classList.add('visible');
170+
setTimeout(function () {
171+
confirmationElement.classList.remove('visible');
172+
}, 750); // Remove "visible" class after 750 ms
173+
}).catch(function () {
174+
console.error('Failed to copy to clipboard');
155175
});
156176
});
157177
});
178+
179+
// Offline Mode
180+
document.addEventListener('DOMContentLoaded', () => {
181+
function updateOnlineStatus() {
182+
if (navigator.onLine) {
183+
document.body.classList.remove('offline-mode');
184+
} else {
185+
document.body.classList.add('offline-mode');
186+
}
187+
}
188+
window.addEventListener('online', updateOnlineStatus);
189+
window.addEventListener('offline', updateOnlineStatus);
190+
updateOnlineStatus();
191+
});

0 commit comments

Comments
 (0)