From be913b6d456481e7a3d3f944861ae9d07e83f06c Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Wed, 18 Jun 2025 11:42:48 -0600 Subject: [PATCH 1/7] add new settings --- 404.html | 6 +- index.html | 494 ++++++++++++----------------------------------------- main.css | 293 +++++++++++++++++++++++++++++++ main.js | 175 +++++++++++++++++++ sw.js | 13 +- 5 files changed, 596 insertions(+), 385 deletions(-) create mode 100644 main.css create mode 100644 main.js diff --git a/404.html b/404.html index 52afe3e..ff893f3 100644 --- a/404.html +++ b/404.html @@ -33,13 +33,13 @@ @keyframes glow { 0% { - filter: drop-shadow(0 0 10px white); + filter: drop-shadow(0 0 8px white); } 50% { - filter: drop-shadow(0 0 20px white); + filter: drop-shadow(0 0 16px white); } 100% { - filter: drop-shadow(0 0 10px white); + filter: drop-shadow(0 0 8px white); } } diff --git a/index.html b/index.html index 34248b3..c075fe9 100644 --- a/index.html +++ b/index.html @@ -8,269 +8,7 @@ - +
@@ -291,7 +29,7 @@

EmulatorJS Demo

-

Enable Debuging:

+

Clean Cache:


+

Language:


+

Custom Path:

Offline Status: CHECKING

Offline Cores will be available soon.

Remove All Saved Versions:

-

Install PWA:

+

Install PWA:


- +
+ diff --git a/main.css b/main.css new file mode 100644 index 0000000..1bf4cb3 --- /dev/null +++ b/main.css @@ -0,0 +1,293 @@ +body, +html { + height: 100%; + background-color: black; + color: white; +} + +body { + margin: 0; + overflow: hidden; +} + +body, +#box, +#top { + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; +} + +#box { + color: #aaa; + height: 20em; + width: 30em; + max-width: 80%; + max-height: 80%; + background-color: #333; + border-radius: 0.4em; + border: 2px solid #555; + position: relative; + flex-direction: column; + transition-duration: 0.2s; + overflow: hidden; + font-family: monospace; + font-weight: bold; + font-size: 20px; + margin: 5px; + padding: 10px; + text-align: center; +} + +#box:hover, +#box[drag] { + border-color: #1AAFFF; + color: #ddd +} + +#input { + cursor: pointer; + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 100%; + opacity: 0; +} + +#display { + width: 100%; + height: 100% +} + +select, +input[type="text"], +button { + padding: 0 0.4em; + margin: 0.5em 0.1em; + width: 15em; + max-width: 100%; + font-family: monospace; + font-weight: bold; + font-size: 16px; + background-color: #444; + color: #aaa; + border-radius: 0.4em; + border: 1px solid #555; + cursor: pointer; + transition-duration: 0.2s; + vertical-align: top; + height: 2.5em; +} + +select:hover, +button:hover { + background-color: #666; + color: #ddd +} + +.logo { + width: 130px; + height: 130px; + filter: drop-shadow(0 0 8px white); +} + +#top, +#version { + margin: 5px; +} + +#version button { + fill: #aaa; + width: auto; + padding: 0.2em 0.3em; + text-align: center; + margin: 0.5em 0.1em; +} + +#version svg { + margin-top: 0.05em; + margin-left: 0.05em; + width: 1.8em; +} + +.popup { + position: fixed; + top: 50%; + left: 50%; + width: 100%; + height: 100%; + z-index: 2000; + visibility: hidden; + -webkit-backface-visibility: hidden; + -moz-backface-visibility: hidden; + backface-visibility: hidden; +} + +.popup .content { + background-color: #333; + border-radius: 0.4em; + border: 2px solid #555; + padding: 1em; + max-width: 80%; + max-height: 80%; + min-width: 30%; + width: min-content; + position: fixed; +} + +.show { + visibility: visible; +} + +.popup-overlay { + position: fixed; + width: 100%; + height: 100%; + visibility: hidden; + top: 0; + left: 0; + z-index: 1000; + opacity: 0; + background-color: rgba(0, 0, 0, 0.5); + -webkit-transition: all 0.3s; + transition: all 0.3s; +} + +.show~.popup-overlay { + opacity: 1; + visibility: visible; +} + +.popup-animate .content { + -webkit-transform: translateX(-50%) translateY(-50%) scale(0.7); + -ms-transform: translateX(-50%) translateY(-50%) scale(0.7); + transform: translateX(-50%) translateY(-50%) scale(0.7); + opacity: 0; + -webkit-transition: all 0.3s; + transition: all 0.3s; +} + +.show.popup-animate .content { + -webkit-transform: translateX(-50%) translateY(-50%) scale(1); + -ms-transform: translateX(-50%) translateY(-50%) scale(1); + transform: translateX(-50%) translateY(-50%) scale(1); + opacity: 1; +} + +.popup .title, +.popup .options p { + display: flex; + align-items: center; +} + +.popup .options p { + margin: 0.9em 0; + font-size: 18px; +} + +.popup .title h1 { + margin: 0 0 0.3em; + font-size: 48px; +} + +.popup .bottom { + display: flex; + justify-content: flex-end; + align-items: center; + margin-top: 1em; +} + +.buttonbox { + display: inline-flex; + align-items: baseline; +} + +.buttonbox.last p { + margin-bottom: 0 !important; +} + +.buttonbox p { + margin-top: 0 !important; +} + +.buttonbox select, +.buttonbox input[type="text"], +.buttonbox button { + padding: 0 0.4em; + margin: 0 0.5em;; + width: auto; + font-size: 14px; + height: 2em; +} + +button:disabled { + background-color: #666; + color: #aaa; + cursor: not-allowed; +} + +.hide { + display: none !important; +} + +.switch { + position: relative; + display: inline-block; + width: 51px; + height: 25px; + margin: 0 0.5em; +} + +.switch input { + opacity: 0; + width: 0; + height: 0; +} + +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .4s; + transition: .4s; +} + +.slider:before { + position: absolute; + content: ""; + height: 18px; + width: 18px; + left: 4px; + bottom: 4px; + background-color: white; + -webkit-transition: .4s; + transition: .4s; +} + +input:checked+.slider { + background-color: #1AAFFF; +} + +input:focus+.slider { + box-shadow: 0 0 1px #1AAFFF; +} + +input:checked+.slider:before { + -webkit-transform: translateX(26px); + -ms-transform: translateX(26px); + transform: translateX(26px); +} + +.slider.round { + border-radius: 34px; +} + +.slider.round:before { + border-radius: 50%; +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..1cc42fc --- /dev/null +++ b/main.js @@ -0,0 +1,175 @@ +function loadJSON(url, callback) { + if (typeof fetch === 'function') { + fetch(url) + .then(response => { + if (response.ok) { + return response.text(); + } else { + return null; + } + }) + .then(data => callback(data)) + .catch(() => callback(null)); + } else { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open('GET', url, true); + + xobj.onreadystatechange = function () { + if (xobj.readyState === 4) { + if (xobj.status === 200) { + callback(xobj.responseText); + } else { + callback(null); + } + } + }; + + xobj.send(); + } +} + +function loadVersions(response) { + const version_select = document.getElementById("version-select"); + var versions = JSON.parse(response); + version_select.innerHTML = ""; + addOptions(version_select, versions.releases, versions.default, versions.github); + addOptions(version_select, { "custom": "" }, versions.default); + addOptions(version_select, versions.versions, versions.default); + version_select.addEventListener("change", () => { + localStorage.setItem("version", version_select[version_select.selectedIndex].textContent); + setCDNPath(version_select[version_select.selectedIndex].value); + }); +} + +function setCDNPath(option) { + console.log("Setting CDN path to:", option); + if (option === "custom") { + console.log("Using custom path"); + window.cdn = localStorage.getItem("custom_cdn") || "https://cdn.emulatorjs.org/stable/data/"; + } else { + window.cdn = "https://cdn.emulatorjs.org/" + option + "data/"; + } +} + +function detectAdBlock(url) { + let adBlockEnabled = false; + try { + const adframe = document.querySelector('iframe[src="' + window.EJS_AdUrl + '"]'); + var adpage = adframe.contentWindow.document; + window.EJS_AdUrl = adframe.src; + if (!adpage) { + adBlockEnabled = true; + } + } catch (e) { + adBlockEnabled = true; + } + if (adBlockEnabled) { + window.EJS_adBlocked(url); + } +} + +function addOptions(select, options, default_option, github) { + for (const version in options) { + const option = document.createElement("option"); + option.value = options[version]; + if (version == "stable") { + option.textContent = "stable (" + github + ")"; + } else { + option.textContent = version; + } + if (version === "custom") { + option.id = "custom-version"; + if (localStorage.getItem("custom_cdn")) { + option.value = localStorage.getItem("custom_cdn"); + } else { + option.disabled = true; + } + } + if ((localStorage.getItem("version") && localStorage.getItem("version") === version) || version.includes(default_option)) { + if (version !== "custom" || (version === "custom" && localStorage.getItem("custom_cdn"))) { + option.selected = true; + setCDNPath(options[version]); + } + } + select.appendChild(option); + } +} + +function openSettings() { + document.getElementById("popup-settings").classList.add("show"); + if (localStorage.getItem("pwa") == "false") { + checkinstall(); + } +} + +function closeSettings() { + document.getElementById("popup-settings").classList.remove("show"); +} + +function checkinstall(overide) { + console.log("Checking install"); + if (navigator.userAgent.includes("Firefox") || (navigator.userAgent.includes("OPR") && !navigator.userAgent.includes("Mobile"))) { + installButton.style.display = "none"; + installBoxText.innerHTML = "PWA's are not supported on this browser."; + return; + } + if (window.matchMedia('(display-mode: standalone)').matches || overide) { + installButton.textContent = "Installed"; + installButton.disabled = true; + installButton.style.display = "inline"; + installBoxText.innerHTML = "Install PWA: "; + } else { + installButton.style.display = "none"; + if (navigator.userAgent.includes("Safari") && !navigator.userAgent.includes("Chrome")) { + installBoxText.innerHTML = "PWA's are supported on this browser, but prompt is not supported.
Please install manually"; + return; + } + if ('getInstalledRelatedApps' in navigator) { + navigator.getInstalledRelatedApps().then((relatedApps) => { + if (relatedApps.length > 0) { + checkinstall(true); + return; + } + }); + } + installBoxText.innerHTML = "PWA is either already installed, or prompt is not supported on this browser.
Please install manually.
Note: PWA's are not supported in Incognito/Private mode."; + } +} + +function loadLanguages(sysLang, lang_select) { + langs = { + "auto": "Auto (" + sysLang + ")", + "en": "English", + "pt": "Portuguese", + "es": "Spanish", + "el": "Greek", + "ja": "Japanese", + "zh": "Chinese", + "hi": "Hindi", + "ar": "Arabic", + "jv": "Javanese", + "bn": "Bengali", + "ru": "Russian", + "de": "German", + "ko": "Korean", + "af": "French", + "it": "Italian", + "tr": "Turkish", + "fa": "Persian", + "ro": "Romanian", + "vi": "Vietnamese" + }; + for (const lang in langs) { + const option = document.createElement("option"); + option.value = lang; + option.textContent = langs[lang]; + lang_select.appendChild(option); + } + let selectedLang = localStorage.getItem("language"); + if (selectedLang) { + lang_select.value = selectedLang; + } else { + localStorage.setItem("language", "auto"); + } +} \ No newline at end of file diff --git a/sw.js b/sw.js index fb62999..661d0d2 100644 --- a/sw.js +++ b/sw.js @@ -1,7 +1,8 @@ const CACHE_NAME = "offline-demo"; -const STABLE_EJS_VER = "4.2.1"; const OFFLINE_FILES = [ "index.html", + "main.js", + "main.css", "404.html", "favicon.ico", "manifest.json", @@ -21,6 +22,16 @@ const OFFLINE_FILES = [ "https://cdn.emulatorjs.org/stable/data/compression/libunrar.js", "https://cdn.emulatorjs.org/stable/data/compression/libunrar.wasm" ]; +let STABLE_EJS_VER = "4.2.2"; // Fallback version if the request fails + +importScripts('/main.js'); + +loadJSON("https://cdn.emulatorjs.org/versions.json", (response) => { + if (response) { + STABLE_EJS_VER = JSON.parse(response).github; + } + console.log("Stable EmulatorJS version:", STABLE_EJS_VER); +}); self.addEventListener("install", (event) => { event.waitUntil( From 8aa869bd7aa938b7fe39ca2dfb1b52d6df9aa199 Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Wed, 18 Jun 2025 11:45:53 -0600 Subject: [PATCH 2/7] fix loging --- main.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.js b/main.js index 1cc42fc..92ffdf5 100644 --- a/main.js +++ b/main.js @@ -14,7 +14,6 @@ function loadJSON(url, callback) { var xobj = new XMLHttpRequest(); xobj.overrideMimeType("application/json"); xobj.open('GET', url, true); - xobj.onreadystatechange = function () { if (xobj.readyState === 4) { if (xobj.status === 200) { @@ -24,7 +23,6 @@ function loadJSON(url, callback) { } } }; - xobj.send(); } } @@ -43,7 +41,6 @@ function loadVersions(response) { } function setCDNPath(option) { - console.log("Setting CDN path to:", option); if (option === "custom") { console.log("Using custom path"); window.cdn = localStorage.getItem("custom_cdn") || "https://cdn.emulatorjs.org/stable/data/"; From fbf0274154c817d9ac508ddf9ca5e2d657156910 Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Wed, 18 Jun 2025 14:54:32 -0600 Subject: [PATCH 3/7] fix language list --- main.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/main.js b/main.js index 92ffdf5..3160b7d 100644 --- a/main.js +++ b/main.js @@ -137,25 +137,25 @@ function checkinstall(overide) { function loadLanguages(sysLang, lang_select) { langs = { "auto": "Auto (" + sysLang + ")", - "en": "English", - "pt": "Portuguese", - "es": "Spanish", - "el": "Greek", - "ja": "Japanese", - "zh": "Chinese", - "hi": "Hindi", - "ar": "Arabic", - "jv": "Javanese", - "bn": "Bengali", - "ru": "Russian", - "de": "German", - "ko": "Korean", - "af": "French", - "it": "Italian", - "tr": "Turkish", - "fa": "Persian", - "ro": "Romanian", - "vi": "Vietnamese" + "en-US": "English (US)", + "pt-BR": "Portuguese (Brazil)", + "es-419": "Spanish (Latin America)", + "el-GR": "Greek (Modern Greek)", + "ja-JP": "Japanese (Japan)", + "zh-CN": "Chinese (Simplified)", + "hi-IN": "Hindi (India)", + "ar-SA": "Arabic (Saudi Arabia)", + "jv-ID": "Javanese (Indonesia)", + "bn-BD": "Bengali (Bangladesh)", + "ru-RU": "Russian (Russia)", + "de-DE": "German (Germany)", + "ko-KR": "Korean (South Korea)", + "af-FR": "French (France)", + "it-IT": "Italian (Italy)", + "tr-TR": "Turkish (Turkey)", + "fa-AF": "Persian (Afghanistan)", + "ro-RO": "Romanian (Romania)", + "vi-VN": "Vietnamese (Vietnam)" }; for (const lang in langs) { const option = document.createElement("option"); From 7552f52a5dc5690e89d821fb74979b83ed2bfc43 Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Thu, 19 Jun 2025 22:48:48 -0600 Subject: [PATCH 4/7] fix codes --- main.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/main.js b/main.js index 3160b7d..a688f29 100644 --- a/main.js +++ b/main.js @@ -137,25 +137,25 @@ function checkinstall(overide) { function loadLanguages(sysLang, lang_select) { langs = { "auto": "Auto (" + sysLang + ")", - "en-US": "English (US)", - "pt-BR": "Portuguese (Brazil)", - "es-419": "Spanish (Latin America)", - "el-GR": "Greek (Modern Greek)", - "ja-JP": "Japanese (Japan)", - "zh-CN": "Chinese (Simplified)", - "hi-IN": "Hindi (India)", - "ar-SA": "Arabic (Saudi Arabia)", - "jv-ID": "Javanese (Indonesia)", - "bn-BD": "Bengali (Bangladesh)", - "ru-RU": "Russian (Russia)", - "de-DE": "German (Germany)", - "ko-KR": "Korean (South Korea)", - "af-FR": "French (France)", - "it-IT": "Italian (Italy)", - "tr-TR": "Turkish (Turkey)", - "fa-AF": "Persian (Afghanistan)", - "ro-RO": "Romanian (Romania)", - "vi-VN": "Vietnamese (Vietnam)" + "en": "English (US)", + "pt": "Portuguese (Brazil)", + "es": "Spanish (Latin America)", + "el": "Greek (Modern Greek)", + "ja": "Japanese (Japan)", + "zh": "Chinese (Simplified)", + "hi": "Hindi (India)", + "ar": "Arabic (Saudi Arabia)", + "jv": "Javanese (Indonesia)", + "bn": "Bengali (Bangladesh)", + "ru": "Russian (Russia)", + "de": "German (Germany)", + "ko": "Korean (South Korea)", + "af": "French (France)", + "it": "Italian (Italy)", + "tr": "Turkish (Turkey)", + "fa": "Persian (Afghanistan)", + "ro": "Romanian (Romania)", + "vi": "Vietnamese (Vietnam)" }; for (const lang in langs) { const option = document.createElement("option"); From 9815755709e02d35e4438a82626fe63a4bdbd167 Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Wed, 25 Jun 2025 12:32:07 -0600 Subject: [PATCH 5/7] language --- index.html | 123 +++----------------------------------- main.css | 20 ++++--- main.js | 172 ++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 176 insertions(+), 139 deletions(-) diff --git a/index.html b/index.html index c075fe9..c7c2996 100644 --- a/index.html +++ b/index.html @@ -41,9 +41,9 @@

EmulatorJS Demo

Settings

-

Enable Debuging:

+

Enable Debuging:


Clean Cache:


-

Language:


+

Language:


Custom Path:

Offline Status: CHECKING

Offline Cores will be available soon.

@@ -60,7 +60,6 @@

Settings

diff --git a/main.css b/main.css index 1bf4cb3..72d7e8c 100644 --- a/main.css +++ b/main.css @@ -135,6 +135,7 @@ button:hover { min-width: 30%; width: min-content; position: fixed; + overflow-x: auto; } .show { @@ -183,7 +184,7 @@ button:hover { } .popup .options p { - margin: 0.9em 0; + margin: 0.5em 0; font-size: 18px; } @@ -202,27 +203,31 @@ button:hover { .buttonbox { display: inline-flex; align-items: baseline; + flex-wrap: wrap; + margin-bottom: 0.2em; } -.buttonbox.last p { +.buttonbox.last { margin-bottom: 0 !important; } .buttonbox p { - margin-top: 0 !important; + margin: 0 !important; } .buttonbox select, .buttonbox input[type="text"], .buttonbox button { padding: 0 0.4em; - margin: 0 0.5em;; + margin: 0.5em;; width: auto; font-size: 14px; height: 2em; } -button:disabled { +.buttonbox button:disabled, +.buttonbox select:disabled, +.buttonbox input[type="text"]:disabled { background-color: #666; color: #aaa; cursor: not-allowed; @@ -237,7 +242,7 @@ button:disabled { display: inline-block; width: 51px; height: 25px; - margin: 0 0.5em; + margin: 0.5em; } .switch input { @@ -290,4 +295,5 @@ input:checked+.slider:before { .slider.round:before { border-radius: 50%; -} \ No newline at end of file +} + diff --git a/main.js b/main.js index a688f29..f7c830c 100644 --- a/main.js +++ b/main.js @@ -35,15 +35,28 @@ function loadVersions(response) { addOptions(version_select, { "custom": "" }, versions.default); addOptions(version_select, versions.versions, versions.default); version_select.addEventListener("change", () => { + versionChange(); + }); +} + +function versionChange(key, value) { + if (key && value) { + localStorage.setItem("version", value); + setCDNPath(key); + checkSettings(value); + } else { + const version_select = document.getElementById("version-select"); localStorage.setItem("version", version_select[version_select.selectedIndex].textContent); setCDNPath(version_select[version_select.selectedIndex].value); - }); + checkSettings(version_select[version_select.selectedIndex].textContent); + } } function setCDNPath(option) { - if (option === "custom") { + console.log("CDN Path: " + option); + if (option === "custom/") { console.log("Using custom path"); - window.cdn = localStorage.getItem("custom_cdn") || "https://cdn.emulatorjs.org/stable/data/"; + window.cdn = localStorage.getItem("custom_cdn"); } else { window.cdn = "https://cdn.emulatorjs.org/" + option + "data/"; } @@ -75,33 +88,160 @@ function addOptions(select, options, default_option, github) { } else { option.textContent = version; } + const saveVersion = localStorage.getItem("version"); if (version === "custom") { option.id = "custom-version"; if (localStorage.getItem("custom_cdn")) { - option.value = localStorage.getItem("custom_cdn"); + option.value = "custom/"; } else { option.disabled = true; } - } - if ((localStorage.getItem("version") && localStorage.getItem("version") === version) || version.includes(default_option)) { - if (version !== "custom" || (version === "custom" && localStorage.getItem("custom_cdn"))) { - option.selected = true; - setCDNPath(options[version]); - } + } + if ((saveVersion && saveVersion === version) || (!saveVersion && version === default_option.split("/")[0]) || saveVersion.includes(version)) { + option.selected = true; + versionChange(option.value, option.textContent); } select.appendChild(option); } } -function openSettings() { - document.getElementById("popup-settings").classList.add("show"); - if (localStorage.getItem("pwa") == "false") { - checkinstall(); +function loadSettings() { + const settingsButton = document.getElementById("settings"); + const settingsClose = document.getElementById("settings-close"); + settingsButton.addEventListener("click", () => { + document.getElementById("popup-settings").classList.add("show"); + if (localStorage.getItem("pwa") == "false") { + checkinstall(); + } + }); + settingsClose.addEventListener("click", () => { + document.getElementById("popup-settings").classList.remove("show"); + }); + + window.debug = false; + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const debugCheckbox = document.getElementById("debug"); + if (parseInt(urlParams.get('debug')) === 1 || urlParams.get('debug') === "true") { + debug = true; + console.log("Debug is enabled"); + debugCheckbox.checked = true; + } else { + console.log("Debug is disabled"); + debugCheckbox.checked = false; + } + + debugCheckbox.addEventListener("change", () => { + enableDebug = debugCheckbox.checked; + console.log("Debug is now " + (enableDebug ? "enabled" : "disabled")); + if (enableDebug) { + history.replaceState(null, '', '?debug=1'); + } else { + history.replaceState(null, '', window.location.pathname); + } + }); + + let systemLang; + try { + systemLang = Intl.DateTimeFormat().resolvedOptions().locale; + } catch(e) {} + console.log("System language: " + systemLang); + const lang_select = document.getElementById("language"); + loadLanguages(systemLang, lang_select); + lang_select.addEventListener("change", () => { + const selectedLang = lang_select.value; + window.language = selectedLang; + localStorage.setItem("language", selectedLang); + console.log("Language changed to: " + selectedLang); + }); + + const customPathInput = document.getElementById("customPath"); + const customPathValid = document.getElementById("customPathValid"); + const savedPath = localStorage.getItem("custom_cdn"); + const urlRegex = /^(https?:\/\/)(localhost|\d{1,3}(\.\d{1,3}){3}|([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(:\d+)?(\/.*)?\/$/; + if (savedPath && urlRegex.test(savedPath)) { + customPathInput.value = savedPath; + customPathValid.textContent = "Valid URL"; + customPathValid.style.color = "green"; + } else { + localStorage.removeItem("custom_cdn"); } + let pathValid = false; + customPathInput.addEventListener("input", () => { + const customPath = customPathInput.value.trim(); + + if (urlRegex.test(customPath)) { + customPathValid.textContent = "Valid URL"; + customPathValid.style.color = "green"; + pathValid = true; + } else if(customPath === "") { + customPathValid.textContent = ""; + customPathValid.style.color = ""; + pathValid = false; + } else { + customPathValid.textContent = "Invalid URL"; + customPathValid.style.color = "red"; + pathValid = false; + } + }); + customPathInput.addEventListener("change", () => { + const customOption = document.getElementById("custom-version"); + const versionSelect = document.getElementById("version-select"); + const customPath = customPathInput.value.trim(); + if (pathValid) { + customOption.disabled = false; + versionSelect.selectedIndex = 3; + localStorage.setItem("custom_cdn", customPath); + } else { + customOption.disabled = true; + versionSelect.selectedIndex = 0; + localStorage.removeItem("custom_cdn"); + } + versionChange(); + }); + + const cacheButton = document.getElementById("cache"); + cacheButton.addEventListener("click", () => { + if (confirm("Are you sure you want to clear the cache? This will remove all saved data.")) { + localStorage.clear(); + console.log("Cleared localStorage"); + indexedDB.databases().then(dbs => { + dbs.forEach(db => { + if (db.name) { + indexedDB.deleteDatabase(db.name); + console.log(`Deleted IndexedDB: ${db.name}`); + } + }); + }); + caches.keys().then(cacheNames => { + return Promise.all( + cacheNames.map(name => { + console.log(`Deleting cache: ${name}`); + return caches.delete(name); + }) + ); + }); + } + }); } -function closeSettings() { - document.getElementById("popup-settings").classList.remove("show"); +function checkSettings(version) { + if (version.includes("stable")) { + version = version.replace("stable (", "").replace(")", ""); + } + const lang_select = document.getElementById("language"); + const langHelp = document.getElementById("languageHelp"); + if (version === "custom" || version === "latest" || version === "nightly" || version > "4.2.2") { + console.log("Language Support: Enabled"); + lang_select.disabled=false; + lang_select.style.width = "auto"; + langHelp.innerHTML = ""; + } else { + console.log("Language Support: Disabled"); + lang_select.disabled=true; + lang_select.style.width = "140px"; + langHelp.innerHTML = "Language selection isn't available for versions 4.2.2 and below."; + } } function checkinstall(overide) { From 0b1a3aff8faecd9d859d2a1908ce04822d7b5b5b Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Wed, 25 Jun 2025 12:38:31 -0600 Subject: [PATCH 6/7] try catch --- sw.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sw.js b/sw.js index 661d0d2..b72becf 100644 --- a/sw.js +++ b/sw.js @@ -26,12 +26,17 @@ let STABLE_EJS_VER = "4.2.2"; // Fallback version if the request fails importScripts('/main.js'); -loadJSON("https://cdn.emulatorjs.org/versions.json", (response) => { - if (response) { - STABLE_EJS_VER = JSON.parse(response).github; - } - console.log("Stable EmulatorJS version:", STABLE_EJS_VER); -}); +try { + loadJSON("https://cdn.emulatorjs.org/versions.json", (response) => { + if (response) { + STABLE_EJS_VER = JSON.parse(response).github; + } + console.log("Stable EmulatorJS version:", STABLE_EJS_VER); + }); +} catch (e) { + console.warn("Failed to get Stable EmulatorJS version:", e, "Using fallback version:", STABLE_EJS_VER); +} + self.addEventListener("install", (event) => { event.waitUntil( From bcf13f7f4957340e7a6eea054d659bbb96421ce3 Mon Sep 17 00:00:00 2001 From: Allan Niles Date: Wed, 9 Jul 2025 18:25:24 -0600 Subject: [PATCH 7/7] newlines --- 404.html | 2 +- CNAME | 2 +- README.md | 2 +- ads.txt | 2 +- main.css | 1 - main.js | 2 +- manifest.json | 3 ++- sw.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/404.html b/404.html index ff893f3..92ae6e1 100644 --- a/404.html +++ b/404.html @@ -55,4 +55,4 @@

404 - Page not found!

- \ No newline at end of file + diff --git a/CNAME b/CNAME index 7032dd5..f174eee 100644 --- a/CNAME +++ b/CNAME @@ -1 +1 @@ -demo.emulatorjs.org \ No newline at end of file +demo.emulatorjs.org diff --git a/README.md b/README.md index 0ddd004..cefa46e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # EmulatorJS - Demo This has version selection from the cdn. ## Usage -You can access the demo page at: [https://demo.emulatorjs.org](https://demo.emulatorjs.org) \ No newline at end of file +You can access the demo page at: [https://demo.emulatorjs.org](https://demo.emulatorjs.org) diff --git a/ads.txt b/ads.txt index 4cad853..c62ac5e 100644 --- a/ads.txt +++ b/ads.txt @@ -1 +1 @@ -google.com, pub-8832864985153925, DIRECT, f08c47fec0942fa0 \ No newline at end of file +google.com, pub-8832864985153925, DIRECT, f08c47fec0942fa0 diff --git a/main.css b/main.css index 72d7e8c..f346a93 100644 --- a/main.css +++ b/main.css @@ -296,4 +296,3 @@ input:checked+.slider:before { .slider.round:before { border-radius: 50%; } - diff --git a/main.js b/main.js index f7c830c..f570e91 100644 --- a/main.js +++ b/main.js @@ -309,4 +309,4 @@ function loadLanguages(sysLang, lang_select) { } else { localStorage.setItem("language", "auto"); } -} \ No newline at end of file +} diff --git a/manifest.json b/manifest.json index 51c2440..908a9b5 100644 --- a/manifest.json +++ b/manifest.json @@ -35,4 +35,5 @@ "purpose": "maskable" } ] - } \ No newline at end of file + } + \ No newline at end of file diff --git a/sw.js b/sw.js index b72becf..070de9e 100644 --- a/sw.js +++ b/sw.js @@ -22,7 +22,7 @@ const OFFLINE_FILES = [ "https://cdn.emulatorjs.org/stable/data/compression/libunrar.js", "https://cdn.emulatorjs.org/stable/data/compression/libunrar.wasm" ]; -let STABLE_EJS_VER = "4.2.2"; // Fallback version if the request fails +let STABLE_EJS_VER = "4.2.3"; // Fallback version if the request fails importScripts('/main.js');