Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Notplayingallday383 committed Mar 18, 2024
1 parent bf2d938 commit 2d3d380
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 10 deletions.
75 changes: 70 additions & 5 deletions components/modules/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default async function loadSettings() {
const title = localStorage.getItem('websiteTitle');
const icon = localStorage.getItem('websiteIcon');
const favicon = localStorage.getItem('websiteIcon');
const useRandomize = localStorage.getItem('useRandomizer')
const css = localStorage.getItem('websiteCSS');
const metaThemeColor = localStorage.getItem('metaThemeColor');
const webmetaThemeColor = localStorage.getItem('metaThemeColor');
const iconInput = document.getElementById('icon-input');
const customCSS = localStorage.getItem('websiteCSS');
if (title) {
Expand All @@ -13,6 +13,7 @@ export default async function loadSettings() {
if (icon) {
const favicon = document.getElementById('favicon');
if (favicon) {
// @ts-expect-error stfu
favicon.href = icon;
favicon.setAttribute('type', 'image/png');
}
Expand All @@ -24,19 +25,26 @@ export default async function loadSettings() {
const randomFaviconIndex = Math.floor(Math.random() * favicons.length);
document.title = titles[randomTitleIndex];
const faviconLink = document.querySelector("link[rel*='icon']") || document.createElement('link');
// @ts-expect-error stfu
faviconLink.type = 'image/x-icon';
// @ts-expect-error stfu
faviconLink.rel = 'icon';
// @ts-expect-error stfu
faviconLink.href = favicons[randomFaviconIndex];
const head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(faviconLink);
console.log('Randomized!')
}
if (css) {
// @ts-expect-error stfu
applyCSS(css);
const cssSelect = document.getElementById('css-select');
if (cssSelect) {
// @ts-expect-error stfu
for (let i = 0; i < cssSelect.options.length; i++) {
// @ts-expect-error stfu
if (cssSelect.options[i].value === css) {
// @ts-expect-error stfu
cssSelect.selectedIndex = i;
break;
}
Expand All @@ -50,6 +58,7 @@ export default async function loadSettings() {
styleSheet.textContent = customCSS;
document.head.appendChild(styleSheet);
} else {
// @ts-expect-error stfu
applyCSS(customCSS);
}
} else {
Expand All @@ -61,6 +70,7 @@ export default async function loadSettings() {
}
const metaThemeColor = localStorage.getItem('metaThemeColor');
if (metaThemeColor) {
// @ts-expect-error stfu
document.getElementById('meta-theme-color').value = metaThemeColor;
const metaThemeColorTag = document.querySelector('meta[name="theme-color"]');
if (metaThemeColorTag) {
Expand All @@ -72,17 +82,22 @@ export default async function loadSettings() {
if (metaThemeColorTag) {
metaThemeColorTag.setAttribute('content', metaThemeColor);
}
}
}
console.log('%c Sodium Settings Loader ',`background: #16d495; color: white; font-weight: bold; border-radius: 5px;`, '' + 'Sodium Settings have been loaded!')
}

export async function saveSettings() {
const titleInput = document.getElementById('title-input');
// @ts-expect-error stfu
const title = titleInput.value.trim();
const iconInput = document.getElementById('icon-input');
// @ts-expect-error stfu
const icon = iconInput.value.trim();
const searchEngineSelect = document.getElementById('search-engine-select');
// @ts-expect-error stfu
const searchEngine = searchEngineSelect.value;
const proxySelect = document.getElementById('proxySelect');
// @ts-expect-error stfu
const selectedOption = proxySelect.options[proxySelect.selectedIndex].value;
const use24HourTimeCheckbox = document.getElementById('use-24hour-checkbox');
const blobwindow = document.getElementById('open-blob-window');
Expand All @@ -93,14 +108,18 @@ export async function saveSettings() {
const fallbackUrlInput = document.getElementById('fallback-url-input');
const useSecondsCheckbox = document.getElementById('use-seconds-checkbox');
const clockCheckbox = document.getElementById('disable-clock');
// @ts-expect-error stfu
const metaThemeColor = document.getElementById('meta-theme-color').value.trim();
const bareServerInput = document.getElementById('custom-bare-server-input');
// @ts-expect-error stfu
const localforage = window.localforage

localStorage.setItem('websiteTitle', title);
console.log('Title saved:', title);
localStorage.setItem('websiteIcon', icon);
console.log('Icon saved:', icon);
if (searchEngine === 'custom') {
// @ts-expect-error stfu
const customSearchUrl = document.getElementById('custom-search-engine-input').value.trim();
if (customSearchUrl !== '') {
localStorage.setItem('searchEngine', customSearchUrl);
Expand All @@ -112,41 +131,49 @@ export async function saveSettings() {
}
localStorage.setItem('proxyOption', selectedOption);
console.log('Default Proxy Saved:', selectedOption);
// @ts-expect-error stfu
if (toggleBeta.checked) {
localStorage.setItem('betaMode', 'true');
} else {
localStorage.removeItem('betaMode');
}
// @ts-expect-error stfu
if (blobwindow.checked) {
localStorage.setItem('openblobwindow', 'true');
localStorage.setItem('usingnewtab', 'true');
} else {
localStorage.removeItem('openblobwindow');
localStorage.removeItem('usingnewtab');
}
// @ts-expect-error stfu
if (titlerandomizer.checked) {
// @ts-expect-error stfu
localStorage.setItem('useRandomizer', true);
console.log('Use Tab Randomizer: true')
} else {
localStorage.removeItem('useRandomizer');
console.log('Use Tab Randomizer: false')
}
if (emergencyHotkeyInput) {
// @ts-expect-error stfu
const emergencyHotkey = emergencyHotkeyInput.value.trim().toLowerCase();
localStorage.setItem('emergencyHotkey', emergencyHotkey);
console.log('Emergency hotkey saved:', emergencyHotkey);
}
if (emergencyURLInput) {
// @ts-expect-error stfu
const emergencyURL = emergencyURLInput.value.trim();
localStorage.setItem('emergencyURL', emergencyURL);
console.log('Emergency URL saved:', emergencyURL);
}
if (fallbackUrlInput) {
// @ts-expect-error stfu
const fallbackUrl = fallbackUrlInput.value.trim();
localStorage.setItem('fallbackUrl', fallbackUrl);
console.log('Fallback URL saved:', fallbackUrl);
}
if (bareServerInput) {
// @ts-expect-error stfu
const bareServer = bareServerInput.value.trim();
caches.open('bareServerCache').then(cache => {
cache.put('bareServerKey', new Response(bareServer));
Expand All @@ -170,19 +197,28 @@ export async function saveSettings() {
console.log('BareServer URL saved:', bareServer);
}
if (use24HourTimeCheckbox) {
// @ts-expect-error stfu
localStorage.setItem('use24HourTime', use24HourTimeCheckbox.checked.toString());
// @ts-expect-error stfu
console.log('Use 24 Hour Time Saved:', use24HourTimeCheckbox.checked);
}
// @ts-expect-error stfu
if (includeDateCheckbox) {
// @ts-expect-error stfu
localStorage.setItem('showDate', includeDateCheckbox.checked.toString());
// @ts-expect-error stfu
console.log('Show Date Saved:', includeDateCheckbox.checked);
}
if (useSecondsCheckbox) {
// @ts-expect-error stfu
localStorage.setItem('useSeconds', useSecondsCheckbox.checked);
// @ts-expect-error stfu
console.log('Include Seconds in TimeBar:', useSecondsCheckbox.checked);
}
if (clockCheckbox) {
// @ts-expect-error stfu
localStorage.setItem('noClock', clockCheckbox.checked);
// @ts-expect-error stfu
console.log('Disable Clock:', clockCheckbox.checked);
}
if (metaThemeColor) {
Expand All @@ -191,7 +227,8 @@ export async function saveSettings() {
}

setTimeout(function () {
const notification = document.getElementById('notification');
// @ts-expect-error stfu
const notification: HTMLElement = document.getElementById('notification');
notification.textContent = 'Settings Saved!';
notification.classList.remove('hidden');

Expand Down Expand Up @@ -226,18 +263,23 @@ export async function exportSettings() {

export async function importSettings() {
const fileInput = document.getElementById('importFile');
// @ts-expect-error stfu
fileInput.addEventListener('change', impSets(), false);
// @ts-expect-error stfu
fileInput.click();
const impSets = () => {
// @ts-expect-error stfu
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function (e) {
try {
// @ts-expect-error stfu
const importedData = JSON.parse(e.target.result);
Object.keys(importedData).forEach((key) => {
localStorage.setItem(key, importedData[key]);
});
const notification = document.getElementById('notification');
// @ts-expect-error stfu
const notification: HTMLElement = document.getElementById('notification');
notification.textContent = 'Settings Imported Successfully';
notification.classList.remove('hidden');
setTimeout(() => {
Expand Down Expand Up @@ -268,6 +310,7 @@ export async function getSettings() {
const emergencyHotkeyInput = document.getElementById('emergency-switch-hotkey');
const proxyOption = localStorage.getItem('proxyOption');
const proxySelect = document.getElementById('proxySelect');
// @ts-expect-error stfu
const options = proxySelect.options;
const emergencyURL = localStorage.getItem('emergencyURL');
const emergencyURLInput = document.getElementById('emergency-url-input');
Expand All @@ -289,48 +332,63 @@ export async function getSettings() {
const useSecondsCheckbox = document.getElementById('use-seconds-checkbox');
const clockCheckbox = document.getElementById('disable-clock');
if (websiteTitleElem) {
// @ts-expect-error stfu
websiteTitleElem.textContent = title;
}
if (toggleBeta) {
const betaMode = localStorage.getItem('betaMode');
// @ts-expect-error stfu
toggleBeta.checked = betaMode === 'true';
}
if (bareServerInput) {
// @ts-expect-error stfu
bareServerInput.value = localStorage.getItem('bareServer') || '';
}
// @ts-expect-error stfu
if (titleInput && iconInput) {
// @ts-expect-error stfu
titleInput.value = title || '';
// @ts-expect-error stfu
iconInput.value = icon || '';
}
if (emergencyHotkey && emergencyHotkeyInput) {
// @ts-expect-error stfu
emergencyHotkeyInput.value = emergencyHotkey;
}
if (emergencyHotkeyInput) {
emergencyHotkeyInput.addEventListener('click', function (event) {
event.preventDefault();
document.addEventListener('keydown', function (keyEvent) {
keyEvent.preventDefault();
// @ts-expect-error stfu
emergencyHotkeyInput.value = keyEvent.key.toLowerCase();
// @ts-expect-error stfu
document.removeEventListener('keydown', arguments.callee);
});
});
}
if (emergencyURL && emergencyURLInput) {
// @ts-expect-error stfu
emergencyURLInput.value = emergencyURL;
}
if (toggleAboutBlank) {
// @ts-expect-error stfu
toggleAboutBlank.checked = openNewWindow === 'true';
}
if (toggleblobBlank) {
// @ts-expect-error stfu
toggleblobBlank.checked = openblobWindow === 'true';
}
if (titlerandomizer) {
// @ts-expect-error stfu
titlerandomizer.checked = titlerandomizerls === 'true';
}
if (toggleDebugging) {
// @ts-expect-error stfu
toggleDebugging.checked = debugging === 'true';
}
if (fallbackUrl && fallbackUrlInput) {
// @ts-expect-error stfu
fallbackUrlInput.value = fallbackUrl;
}
for (let i = 0; i < options.length; i++) {
Expand All @@ -340,28 +398,34 @@ export async function getSettings() {
}
}
if (searchEngineSelect) {
// @ts-expect-error stfu
searchEngineSelect.value = searchEngine;
if (searchEngine === 'custom') {
if (customSearchEngineInput) {
customSearchEngineInput.style.display = 'block';
// @ts-expect-error stfu
customSearchEngineInput.value = localStorage.getItem('customSearchEngineUrl') || '';
}
}
}
if (use24HourTimeCheckbox) {
const use24HourTime = localStorage.getItem('use24HourTime');
// @ts-expect-error stfu
use24HourTimeCheckbox.checked = use24HourTime === 'true';
}
if (includeDateCheckbox) {
const includeDate = localStorage.getItem('showDate');
// @ts-expect-error stfu
includeDateCheckbox.checked = includeDate === 'true';
}
if (useSecondsCheckbox) {
const useSeconds = localStorage.getItem('useSeconds');
// @ts-expect-error stfu
useSecondsCheckbox.checked = useSeconds === 'true';
}
if (clockCheckbox) {
const useSeconds = localStorage.getItem('noClock');
// @ts-expect-error stfu
clockCheckbox.checked = useSeconds === 'true';
}
}
Expand All @@ -372,6 +436,7 @@ function applyCSS() {
for (let i = 0; i < styleSheets.length; i++) {
const styleSheet = styleSheets[i];
if (styleSheet.getAttribute('id') === 'custom-css') {
// @ts-expect-error stfu
styleSheet.href = selectedCSS;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/404.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Nav from "../components/Nav"
import Footer from "../components/Footer"
export default function notfound() {
// @ts-expect-error stfu
import Nav from "@components/nav.tsx"
// @ts-expect-error stfu
import Footer from "@components/footer"
export default function Notfound() {
async function regSW() {
console.log('Waiting on SW Cache to Register...');
const stockSW = "/sw.js";
Expand Down
15 changes: 13 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Nav from "@components/nav.tsx"
// @ts-expect-error stfu
import Footer from "@components/footer"
// @ts-expect-error stfu
import { loadSettings } from "@components/modules/inject"
import loadSettings from "@components/modules/settings"
import "../public/assets/css/home.css"
import Notfound from "./404"
export default function Home() {
loadSettings()
return (
Expand Down Expand Up @@ -61,5 +62,15 @@ export default function Home() {
}

window.addEventListener('load', () => {
document.body.appendChild(<Home />);
if (window.location.href === '/') {
document.body.appendChild(<Home />);
} else if (window.location.href === '/games') {

} else if (window.location.href === '/apps') {

} else if (window.location.href === '/settings') {

} else {
document.body.appendChild(<Notfound />);
}
})

0 comments on commit 2d3d380

Please sign in to comment.