Skip to content
Open
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
50 changes: 39 additions & 11 deletions visualizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@
//themes are available here: https://github.com/ajaxorg/ace/tree/master/lib/ace/theme
editor.setTheme("ace/theme/tomorrow");
editor.session.setMode("ace/mode/javascript");
editor.getSession().on('change', function() {
saveOnEditorUpdate()
});

if (sessionStorage.getItem("autosave")) {
editor.setValue(sessionStorage.getItem("autosave"));
}

function saveOnEditorUpdate()
{
sessionStorage.setItem("autosave", editor.getValue());
}

var show = document.getElementById('show');

Expand Down Expand Up @@ -431,13 +443,7 @@
let reload = document.getElementById("reload");
let currentSource = null; //{file:file} or {url:url} or null
reload.addEventListener('click', function() {
if (currentSource) {
if (currentSource.file) {
readFile(currentSource.file);
} else if (currentSource.url) {
readURL(currentSource.url);
}
}
location.reload();
});


Expand Down Expand Up @@ -580,6 +586,7 @@
file.addEventListener('change', function(evt){
try {
readFile(file.files[0]);
deleteParam();
file.value = "";
} catch (e) {
console.log(e);
Expand All @@ -589,11 +596,32 @@
});



function addURLParam(key, value){
let params = new URLSearchParams(window.location.search);
params.set(key, value);
const editedURL = window.location.pathname + "?" + params.toString();
history.pushState(null, "", editedURL);
let newParams = new URLSearchParams(window.location.search);
}
function deleteParam(){
window.history.pushState(null, "", window.location.pathname);
}
{ //check for '?load=....' in the URL:
const m = document.location.search.match(/^\?load=(.+)$/);
if (m) {
readURL(m[1]);
}
let params = new URLSearchParams(window.location.search);
let name = params.get("load");
if (name && !isFileEdited()) {
readURL(name);
addURLParam("edited", "true");
updateVisualizer(true);
}
}

function isFileEdited(){
let params = new URLSearchParams(window.location.search);
let edited = params.get("edited");
return edited !== null;

}

</script>
Expand Down