2020-09-23 11:32:29 -05:00
|
|
|
var prefillInstance = window.localStorage.getItem('mastodon_instance');
|
2020-09-23 11:10:47 -05:00
|
|
|
|
|
|
|
var paramPairs = window.location.search.substr(1).split('&');
|
|
|
|
var paramPairsLength = paramPairs.length;
|
|
|
|
|
|
|
|
for (var i = 0; i < paramPairsLength; i++) {
|
|
|
|
var paramPair = paramPairs[i].split('=');
|
2020-09-23 11:21:33 -05:00
|
|
|
if (paramPair[0] === 'text') {
|
|
|
|
document.getElementById('text').value = decodeURIComponent(paramPair[1]);
|
2020-09-23 11:32:29 -05:00
|
|
|
} else if (paramPair[0] === 'instance') {
|
|
|
|
prefillInstance = decodeURIComponent(paramPair[1]);
|
2020-09-23 11:21:33 -05:00
|
|
|
}
|
2020-09-23 11:10:47 -05:00
|
|
|
}
|
|
|
|
delete i
|
|
|
|
delete paramPair
|
|
|
|
|
2020-09-23 11:32:29 -05:00
|
|
|
if (prefillInstance != null) {
|
|
|
|
document.getElementById('instance').value = prefillInstance;
|
|
|
|
}
|
|
|
|
|
2020-09-23 11:10:47 -05:00
|
|
|
document
|
|
|
|
.getElementById('form')
|
|
|
|
.addEventListener('submit', function (e) {
|
|
|
|
e.preventDefault();
|
2020-09-23 11:21:33 -05:00
|
|
|
var text = e.target.elements['text'].value;
|
2020-09-23 11:10:47 -05:00
|
|
|
var instance = e.target.elements['instance'].value;
|
|
|
|
var remember = e.target.elements['remember'].checked;
|
|
|
|
|
2020-09-23 11:32:36 -05:00
|
|
|
if (instance.indexOf("http://") == -1 && instance.indexOf("https://") == -1) {
|
2020-09-23 11:10:47 -05:00
|
|
|
instance = "https://" + instance;
|
|
|
|
}
|
2020-09-23 11:32:36 -05:00
|
|
|
if (instance.charAt(instance.length - 1) !== '/'){
|
2020-09-23 11:10:47 -05:00
|
|
|
instance = instance + "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remember) {
|
|
|
|
window.localStorage.setItem('mastodon_instance', instance);
|
|
|
|
}
|
|
|
|
|
2020-09-23 11:21:33 -05:00
|
|
|
var shareUrl = instance + "share?text=" + encodeURIComponent(text);
|
2020-09-23 11:10:47 -05:00
|
|
|
window.open(shareUrl, '_blank', 'noopener,noreferrer')
|
|
|
|
})
|