diff --git a/Scripts/settings.js b/Scripts/settings.js index 6dd4cf7..c725fe3 100644 --- a/Scripts/settings.js +++ b/Scripts/settings.js @@ -22,6 +22,11 @@ document.addEventListener("DOMContentLoaded", function() { // New elements for weather functionality const toggleWeatherCheckbox = document.getElementById("toggle-weather"); // Checkbox for toggling weather const weatherWidget = document.getElementById("weather-widget"); // Weather widget element + + // File upload element + const fileUploadButton = document.getElementById("file-upload"); + + // Variables to track changes let newBackground = ''; @@ -123,67 +128,72 @@ document.addEventListener("DOMContentLoaded", function() { // Only apply changes after pressing the save button saveButton.addEventListener("click", () => { - // Get values from inputs - newBackground = backgroundInput.value.trim(); - newGreeting = document.getElementById("greeting").value.trim(); - newSearchEngine = searchEngineSelect.value; - newSearchVisible = toggleSearchCheckbox.checked; - newQuickLinksVisible = toggleQuickLinksCheckbox.checked; - newTimeVisible = toggleTimeCheckbox.checked; - newTimeFormat = timeFormatSelect.value; - newWeatherVisible = toggleWeatherCheckbox.checked; - - // Apply background settings - if (newBackground === "") { - removeBackground(); - document.body.classList.add("gradient-active"); - localStorage.removeItem("background"); - } else { - localStorage.setItem("background", newBackground); - setBackground(newBackground); - document.body.classList.remove("gradient-active"); - } + try { + // Get values from inputs + newBackground = backgroundInput.value.trim(); + newGreeting = document.getElementById("greeting").value.trim(); + newSearchEngine = searchEngineSelect.value; + newSearchVisible = toggleSearchCheckbox.checked; + newQuickLinksVisible = toggleQuickLinksCheckbox.checked; + newTimeVisible = toggleTimeCheckbox.checked; + newTimeFormat = timeFormatSelect.value; + newWeatherVisible = toggleWeatherCheckbox.checked; - // Apply greeting settings - if (newGreeting === "") { - greetingElement.textContent = "Hello!"; // Default greeting - localStorage.setItem("greeting", "Hello!"); - } else { - greetingElement.textContent = newGreeting; - localStorage.setItem("greeting", newGreeting); - } + // Apply background settings + if (newBackground === "") { + removeBackground(); + document.body.classList.add("gradient-active"); + localStorage.removeItem("background"); + } else { + try { + localStorage.setItem("background", newBackground); + setBackground(newBackground); + document.body.classList.remove("gradient-active"); + } catch (error) { + console.error('Error saving background:', error); + alert('Error saving background. Please try again.'); + } + } - // Apply visibility settings - searchBox.style.display = newSearchVisible ? 'block' : 'none'; - quickLinksDiv.style.display = newQuickLinksVisible ? 'block' : 'none'; - clockElement.style.display = newTimeVisible ? 'block' : 'none'; + // Apply greeting settings + if (newGreeting === "") { + greetingElement.textContent = "Hello!"; // Default greeting + localStorage.setItem("greeting", "Hello!"); + } else { + greetingElement.textContent = newGreeting; + localStorage.setItem("greeting", newGreeting); + } - // Set weather visibility based on newWeatherVisible - weatherWidget.style.display = newWeatherVisible ? 'block' : 'none'; - localStorage.setItem("weatherVisible", newWeatherVisible); + // Apply visibility settings + searchBox.style.display = newSearchVisible ? 'block' : 'none'; + quickLinksDiv.style.display = newQuickLinksVisible ? 'block' : 'none'; + clockElement.style.display = newTimeVisible ? 'block' : 'none'; - // Save settings to localStorage - localStorage.setItem("searchEngine", newSearchEngine); - localStorage.setItem("searchBarVisible", newSearchVisible); - localStorage.setItem("quickLinksVisible", newQuickLinksVisible); - localStorage.setItem("timeVisible", newTimeVisible); - localStorage.setItem("timeFormat", newTimeFormat); + // Set weather visibility based on newWeatherVisible + weatherWidget.style.display = newWeatherVisible ? 'block' : 'none'; + localStorage.setItem("weatherVisible", newWeatherVisible); - // Update search form action - searchForm.action = newSearchEngine; + localStorage.setItem("searchEngine", newSearchEngine); + localStorage.setItem("searchBarVisible", newSearchVisible); + localStorage.setItem("quickLinksVisible", newQuickLinksVisible); + localStorage.setItem("timeVisible", newTimeVisible); + localStorage.setItem("timeFormat", newTimeFormat); - // Call updateClock to reflect the new format immediately - updateClock(); + searchForm.action = newSearchEngine; - // Close settings sidebar after saving - closeSidebar(); + updateClock(); + + closeSidebar(); + } catch (error) { + console.error('Error in save button handler:', error); + alert('Error saving settings. Please try again.'); + } }); - // Add these new functions function setBackground(url) { removeBackground(); - if (url.toLowerCase().endsWith('.mp4')) { + if (url.toLowerCase().endsWith('.mp4') || url.includes('data:video/mp4')) { const video = document.createElement('video'); video.id = 'background-video'; video.autoplay = true; @@ -217,4 +227,112 @@ document.addEventListener("DOMContentLoaded", function() { } document.body.style.backgroundImage = ''; } + + + function processFile(file) { + if (!file.type.startsWith('image/') && file.type !== 'video/mp4') { + alert('Only image and MP4 video files are supported'); + return; + } + + const reader = new FileReader(); + reader.onload = (e) => { + try { + const dataUrl = e.target.result; + if (backgroundInput) { + backgroundInput.value = dataUrl; + document.body.classList.remove("gradient-active"); + setBackground(dataUrl); + } else { + console.error('Background input element not found'); + } + } catch (error) { + console.error('Error processing file:', error); + alert('Error processing file. Please try another file.'); + } + }; + + reader.onerror = () => { + console.error('Error reading file'); + alert('Error reading file. Please try again.'); + }; + + try { + reader.readAsDataURL(file); + } catch (error) { + console.error('Error initiating file read:', error); + alert('Error reading file. Please try again.'); + } + } + + fileUploadButton.addEventListener("click", (e) => { + e.preventDefault(); + const input = document.createElement("input"); + input.type = "file"; + input.accept = "image/*,video/mp4"; + + input.onchange = async (e) => { + const file = e.target.files[0]; + if (file) { + processFile(file); + } + }; + + input.click(); + }); + + let dragCounter = 0; + + document.addEventListener("dragenter", (e) => { + e.preventDefault(); + dragCounter++; + document.body.classList.add('drag-over'); + }); + + document.addEventListener("dragleave", (e) => { + e.preventDefault(); + dragCounter--; + if (dragCounter === 0) { + document.body.classList.remove('drag-over'); + } + }); + + document.addEventListener("dragover", (e) => { + e.preventDefault(); + }); + + document.addEventListener("drop", (e) => { + e.preventDefault(); + dragCounter = 0; + document.body.classList.remove('drag-over'); + + const file = e.dataTransfer.files[0]; + if (file) { + processFile(file); + } + }); + + saveButton.addEventListener("click", () => { + try { + const newBackground = backgroundInput?.value?.trim() ?? ''; + + if (newBackground === "") { + removeBackground(); + document.body.classList.add("gradient-active"); + localStorage.removeItem("background"); + } else { + try { + localStorage.setItem("background", newBackground); + setBackground(newBackground); + document.body.classList.remove("gradient-active"); + } catch (error) { + console.error('Error saving background:', error); + alert('Error saving background. Please try again.'); + } + } + } catch (error) { + console.error('Error in save button handler:', error); + alert('Error saving settings. Please try again.'); + } + }); }); diff --git a/manifest.json b/manifest.json index 1c131ca..daa5c28 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "StyTab", - "version": "1.1.7", + "version": "1.1.8", "description": "Stytab - A minimalist Startpage that meets your needs.", "chrome_url_overrides": { "newtab": "startpage.html" diff --git a/startpage.html b/startpage.html index ddf6bc7..c3df829 100644 --- a/startpage.html +++ b/startpage.html @@ -85,8 +85,15 @@

Settings

- + + +
+ OR +
+ + + @@ -116,6 +123,7 @@

Settings

+

Display Settings

@@ -152,7 +160,7 @@

Display Settings

- + diff --git a/styles/settings.css b/styles/settings.css index 6c3f81e..3849c9d 100644 --- a/styles/settings.css +++ b/styles/settings.css @@ -84,7 +84,7 @@ color: white; } -.settings-sidebar button { +.settings-sidebar .save-settings, .settings-sidebar .file-upload { font-size: 15px; padding: 10px; background-color: #00b894; @@ -94,10 +94,12 @@ cursor: pointer; transition: background-color 0.3s ease; width: 100%; - margin-bottom: 30px; } -.settings-sidebar button:hover { +.settings-sidebar .save-settings { + margin-bottom: 30px; +} +.settings-sidebar .save-settings:hover, .settings-sidebar .file-upload:hover { background-color: #009874; } @@ -161,3 +163,12 @@ input:checked + .slider { input:checked + .slider:before { transform: translateX(98px); } + +.settings-sidebar .or-divider { + text-align: center; + margin-bottom: 10px; +} + +.settings-sidebar .or-divider span { + color: #888; +}