-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Split: Weather, UserText, browser-utils (#494)
* Code Split * ID changed * fix browserUtils * minor changes * Update browser-utils.js Typo fix and isSafari more robust * Update ai-tools.js Reverted to avoid conflicts with #495 * Update index.html * Update script.js fix * Fix browser-utils.js * Update bookmarks.js * Update script.js * Update script.js * Update browser-utils.js final * Create background.js * Update manifest(firefox).json
- Loading branch information
Showing
17 changed files
with
448 additions
and
401 deletions.
There are no files selected for viewing
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,4 +189,4 @@ resetbtn.addEventListener("click", () => { | |
localStorage.clear(); | ||
location.reload(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Material You NewTab | ||
* Copyright (c) 2023-2025 XengShi | ||
* Licensed under the GNU General Public License v3.0 (GPL-3.0) | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// Constants to detect the browser and platform details | ||
|
||
// Check if the browser is Firefox | ||
const isFirefox = typeof browser !== "undefined" || navigator.userAgent.toLowerCase().includes("firefox"); | ||
|
||
// Check if the browser is Chromium-based | ||
const isChromiumBased = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime) && !isFirefox; | ||
|
||
// Check if the browser is Edge | ||
const isEdge = /Edg/.test(navigator.userAgent); | ||
|
||
// Check if the browser is Brave | ||
const isBrave = !!(navigator.brave && navigator.brave.isBrave()); | ||
|
||
// Check if the browser is Opera | ||
const isOpera = /OPR/.test(navigator.userAgent); | ||
|
||
// Check if the browser is Chrome | ||
const isChrome = (/Chrome|CriOS/.test(navigator.userAgent)) && /Google Inc/.test(navigator.vendor) && !isEdge && !isBrave && !isOpera; | ||
|
||
// Check if the browser is Safari | ||
const isSafari = /Safari/.test(navigator.userAgent) && !isChromiumBased && /Apple Computer/.test(navigator.vendor); | ||
|
||
// Check if the operating system is macOS | ||
const isMac = /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.platform); | ||
|
||
// Check if the device is a desktop (not mobile) | ||
const isDesktop = !/Android|iPhone|iPad|iPod/.test(navigator.userAgent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Material You NewTab | ||
* Copyright (c) 2023-2025 XengShi | ||
* Licensed under the GNU General Public License v3.0 (GPL-3.0) | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// Custom text | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const userTextDiv = document.getElementById("userText"); | ||
const userTextCheckbox = document.getElementById("userTextCheckbox"); | ||
|
||
// Load and apply the checkbox state | ||
const isUserTextVisible = localStorage.getItem("userTextVisible") !== "false"; | ||
userTextCheckbox.checked = isUserTextVisible; | ||
userTextDiv.style.display = isUserTextVisible ? "block" : "none"; | ||
|
||
// Toggle userText display based on checkbox state | ||
userTextCheckbox.addEventListener("change", () => { | ||
const isVisible = userTextCheckbox.checked; | ||
userTextDiv.style.display = isVisible ? "block" : "none"; | ||
localStorage.setItem("userTextVisible", isVisible); | ||
}); | ||
|
||
// Set the default language to English if no language is saved | ||
const savedLang = localStorage.getItem("selectedLanguage") || "en"; | ||
applyLanguage(savedLang); | ||
|
||
// Load the stored text if it exists | ||
const storedValue = localStorage.getItem("userText"); | ||
if (storedValue) { | ||
userTextDiv.textContent = storedValue; | ||
} else { | ||
// Fallback to the placeholder based on the selected language | ||
const placeholder = userTextDiv.dataset.placeholder || translations["en"].userText; // Fallback to English | ||
userTextDiv.textContent = placeholder; | ||
} | ||
|
||
// Handle input event | ||
userTextDiv.addEventListener("input", function () { | ||
localStorage.setItem("userText", userTextDiv.textContent); | ||
}); | ||
|
||
// Remove placeholder text when the user starts editing | ||
userTextDiv.addEventListener("focus", function () { | ||
if (userTextDiv.textContent === userTextDiv.dataset.placeholder) { | ||
userTextDiv.textContent = ""; // Clear the placeholder when focused | ||
} | ||
}); | ||
|
||
// Restore placeholder if the user leaves the div empty after editing | ||
userTextDiv.addEventListener("blur", function () { | ||
if (userTextDiv.textContent === "") { | ||
userTextDiv.textContent = userTextDiv.dataset.placeholder; // Show the placeholder again if empty | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
/* | ||
* Material You NewTab | ||
* Copyright (c) 2023-2025 XengShi | ||
* Licensed under the GNU General Public License v3.0 (GPL-3.0) | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// Set Loading Screen Color before Everything Loads | ||
document.documentElement.style.setProperty('--Loading-Screen-Color',localStorage.getItem('LoadingScreenColor') || "#bbd6fd"); | ||
document.documentElement.style.setProperty('--Loading-Screen-Color', localStorage.getItem('LoadingScreenColor') || "#bbd6fd"); |
Oops, something went wrong.