Skip to content

Updated startup script #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 43 additions & 32 deletions iwsy/iwsystart.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,53 @@ window.onload = () => {
return xhr;
};

const scriptElement = document.getElementById(`iwsy-script`);
if (scriptElement) {
const request = createCORSRequest(`${scriptElement.innerText}?v=${Math.floor(Date.now())}`);
if (!request) {
throw Error(`Unable to access the JSON script`);
}
const start = mode => {
const container = document.getElementById(`iwsy-container`);
const scriptElement = document.getElementById(`iwsy-script`);
const path = scriptElement.innerText;
if (scriptElement) {
const request = createCORSRequest(`${path}?v=${Math.floor(Date.now())}`);
if (!request) {
throw Error(`Unable to access the JSON script`);
}

request.onload = () => {
if (200 <= request.status && request.status < 400) {
const script = JSON.parse(request.responseText);
const iwsy = IWSY(document.getElementById(`iwsy-container`), script);
iwsy.onStep(index => {
});
const run = () => {
iwsy.run(() => {
request.onload = () => {
if (200 <= request.status && request.status < 400) {
const script = JSON.parse(request.responseText);
const iwsy = IWSY(container, script);
const slash = path.lastIndexOf(`/`);
iwsy.setPath(path.slice(0, slash + 1));
iwsy.onStep(index => {
});
iwsy.run(`normal`, mode, () => {
console.log(`All done`);
});
};
// Wait for a click/tap or a keypress to start
document.addEventListener(`click`, run);
document.onkeydown = function (event) {
if (event.code === `Enter`) {
mode = `auto`;
}
run();
return true;
};
} else {
} else {
throw Error(`Unable to access the JSON script`);
}
};

request.onerror = () => {
throw Error(`Unable to access the JSON script`);
}
};
};

request.onerror = () => {
throw Error(`Unable to access the JSON script`);
};
request.send();
}
};

request.send();
}
// Wait for a click/tap or a keypress to start
document.addEventListener(`click`, () => {
document.removeEventListener(`click`);
start(`auto`);
});
document.onkeydown = event => {
document.onkeydown = null;
if (event.code === `Enter`) {
start(`auto`);
}
else {
start(`manual`);
}
return true;
};
};