Normalize URL coming from URI parameters
This commit is contained in:
parent
2bc5833fca
commit
1e754fbfc2
1 changed files with 12 additions and 9 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
function normalizeUrl(url) {
|
||||||
|
if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) {
|
||||||
|
url = "https://" + url;
|
||||||
|
}
|
||||||
|
if (url.charAt(url.length - 1) !== '/'){
|
||||||
|
url = url + "/";
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
var prefillInstance = window.localStorage.getItem('mastodon_instance');
|
var prefillInstance = window.localStorage.getItem('mastodon_instance');
|
||||||
|
|
||||||
var paramPairs = window.location.search.substr(1).split('&');
|
var paramPairs = window.location.search.substr(1).split('&');
|
||||||
|
@ -15,7 +25,7 @@ delete i
|
||||||
delete paramPair
|
delete paramPair
|
||||||
|
|
||||||
if (prefillInstance != null) {
|
if (prefillInstance != null) {
|
||||||
document.getElementById('instance').value = prefillInstance;
|
document.getElementById('instance').value = normalizeUrl(prefillInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
document
|
document
|
||||||
|
@ -23,16 +33,9 @@ document
|
||||||
.addEventListener('submit', function (e) {
|
.addEventListener('submit', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var text = e.target.elements['text'].value;
|
var text = e.target.elements['text'].value;
|
||||||
var instance = e.target.elements['instance'].value;
|
var instance = normalizeUrl(e.target.elements['instance'].value);
|
||||||
var remember = e.target.elements['remember'].checked;
|
var remember = e.target.elements['remember'].checked;
|
||||||
|
|
||||||
if (instance.indexOf("http://") == -1 && instance.indexOf("https://") == -1) {
|
|
||||||
instance = "https://" + instance;
|
|
||||||
}
|
|
||||||
if (instance.charAt(instance.length - 1) !== '/'){
|
|
||||||
instance = instance + "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remember) {
|
if (remember) {
|
||||||
window.localStorage.setItem('mastodon_instance', instance);
|
window.localStorage.setItem('mastodon_instance', instance);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue