mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
add support for load from url
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -50,8 +50,7 @@ let keyHandler = (e) => {
|
||||
mask = 128;
|
||||
break;
|
||||
case 'KeyR':
|
||||
if(isKeyDown)
|
||||
{
|
||||
if (isKeyDown) {
|
||||
runModule(currentData);
|
||||
}
|
||||
break;
|
||||
@@ -66,7 +65,7 @@ let keyHandler = (e) => {
|
||||
window.onkeydown = keyHandler;
|
||||
window.onkeyup = keyHandler;
|
||||
|
||||
async function runModule(data) {
|
||||
async function runModule(data, keepUrl) {
|
||||
if (cancelFunction) {
|
||||
cancelFunction();
|
||||
cancelFunction = null;
|
||||
@@ -82,16 +81,17 @@ async function runModule(data) {
|
||||
currentData = data;
|
||||
|
||||
let newURL = window.location.pathname;
|
||||
if (cartridgeSize <= 1024) {
|
||||
if (cartridgeSize <= 1024 && !keepUrl) {
|
||||
let dataString = '';
|
||||
for (let byte of U8(data)) {
|
||||
dataString += String.fromCharCode(byte);
|
||||
}
|
||||
newURL += '#' + btoa(dataString);
|
||||
}
|
||||
|
||||
if (newURL != window.location.pathname + window.location.hash) {
|
||||
history.pushState(null, null, newURL);
|
||||
}
|
||||
}
|
||||
|
||||
screen.width = screen.width;
|
||||
|
||||
@@ -220,14 +220,18 @@ async function runModule(data) {
|
||||
}
|
||||
}
|
||||
|
||||
async function runModuleFromURL(url) {
|
||||
runModule(await (await fetch(url)).arrayBuffer());
|
||||
async function runModuleFromURL(url, keepUrl) {
|
||||
runModule(await (await fetch(url)).arrayBuffer(), keepUrl);
|
||||
}
|
||||
|
||||
function runModuleFromHash() {
|
||||
let base64Data = window.location.hash.slice(1);
|
||||
if (base64Data.length > 0) {
|
||||
runModuleFromURL('data:;base64,' + base64Data);
|
||||
let hash = window.location.hash.slice(1);
|
||||
if (hash.length > 0) {
|
||||
if (hash.startsWith("url=")) {
|
||||
runModuleFromURL(hash.slice(4), true);
|
||||
} else {
|
||||
runModuleFromURL('data:;base64,' + hash);
|
||||
}
|
||||
} else {
|
||||
runModule(new ArrayBuffer(0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user