From ebb291ee875b4d103d2efa06c895f8940bcccc9f Mon Sep 17 00:00:00 2001 From: Zan1456 <62830223+Zan1456@users.noreply.github.com> Date: Sun, 8 Jun 2025 21:42:51 +0200 Subject: [PATCH] Title and icon --- global/theme.js | 61 +++++++++++++++++++++++++++++++++++++++------ settings/index.html | 4 ++- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/global/theme.js b/global/theme.js index a3b7d6a..498b5b7 100644 --- a/global/theme.js +++ b/global/theme.js @@ -21,6 +21,33 @@ } } + function setPageTitleAndFavicon() { + try { + document.title = 'Firka - KRÉTA'; + + const existingFavicons = document.querySelectorAll('link[rel="icon"], link[rel="shortcut icon"]'); + existingFavicons.forEach(link => link.remove()); + + if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.getURL) { + const favicon = document.createElement('link'); + favicon.rel = 'icon'; + favicon.type = 'image/png'; + favicon.href = chrome.runtime.getURL('images/firka_logo_128.png'); + document.head.appendChild(favicon); + + const shortcutIcon = document.createElement('link'); + shortcutIcon.rel = 'shortcut icon'; + shortcutIcon.type = 'image/png'; + shortcutIcon.href = chrome.runtime.getURL('images/firka_logo_128.png'); + document.head.appendChild(shortcutIcon); + } + + console.log('Page title and favicon updated to Firka'); + } catch (error) { + console.error('Error setting page title and favicon:', error); + } + } + function initializeTheme() { const cookieTheme = cookieManager.get('themePreference'); const localStorageTheme = localStorage.getItem('themePreference'); @@ -28,6 +55,7 @@ const theme = cookieTheme || localStorageTheme || 'light-blue'; setTheme(theme); + setPageTitleAndFavicon(); if (cookieTheme !== localStorageTheme) { if (cookieTheme) { @@ -39,11 +67,7 @@ } if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', () => { - initializeTheme(); - }); - - initializeTheme(); + document.addEventListener('DOMContentLoaded', initializeTheme); } else { initializeTheme(); } @@ -63,7 +87,8 @@ return true; }); - + let titleCheckTimeout; + const observer = new MutationObserver((mutations) => { const currentTheme = document.documentElement.getAttribute('data-theme'); const savedTheme = cookieManager.get('themePreference') || localStorage.getItem('themePreference'); @@ -71,20 +96,42 @@ if ((!currentTheme && savedTheme) || (currentTheme !== savedTheme && savedTheme)) { setTheme(savedTheme); } + + const titleChanged = mutations.some(mutation => + mutation.type === 'childList' && + mutation.target === document.head && + Array.from(mutation.addedNodes).some(node => node.tagName === 'TITLE') + ); + + if (titleChanged || document.title !== 'Firka - KRÉTA') { + clearTimeout(titleCheckTimeout); + titleCheckTimeout = setTimeout(() => { + if (document.title !== 'Firka - KRÉTA') { + setPageTitleAndFavicon(); + } + }, 100); + } }); - if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }); + observer.observe(document.head, { + childList: true, + subtree: true + }); }); } else { observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }); + observer.observe(document.head, { + childList: true, + subtree: true + }); } })(); \ No newline at end of file diff --git a/settings/index.html b/settings/index.html index 974f18f..f14de9d 100644 --- a/settings/index.html +++ b/settings/index.html @@ -3,7 +3,9 @@
-