Skip to content
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

Add the ability to save the last known working URL via localStorage #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 28 additions & 0 deletions webrepl.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
});
term.open(document.getElementById("term"));
show_https_warning();
populate_recent_url();
};
window.addEventListener('resize', function() {
var size = calculate_size(self);
Expand All @@ -132,6 +133,28 @@
}
}

// Test if localStorage is available. via https://stackoverflow.com/questions/16427636
function lsTest(){
var test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
return true;
} catch(e) {
return false;
}
}

function populate_recent_url() {
if (lsTest() === true) {
var recent_url = localStorage.getItem('recent_url');
if (recent_url) {
var input = document.getElementById('url');
input.value = recent_url;
}
}
}

function button_click() {
if (connected) {
ws.close();
Expand Down Expand Up @@ -165,6 +188,11 @@
ws.send(data);
});

// Record url for future use
if (lsTest() === true) {
localStorage.setItem('recent_url', url);
}

term.on('title', function(title) {
document.title = title;
});
Expand Down