This repository has been archived on 2024-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
share2fedi/src/script/index.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-09-23 11:10:47 -05:00
var remembered = window.localStorage.getItem('mastodon_instance');
if (remembered != null) {
document.getElementById('instance').value = remembered;
}
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]);
break;
}
2020-09-23 11:10:47 -05:00
}
delete i
delete paramPair
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;
if (!(instance.startsWith("https://") || instance.startsWith("http://"))) {
instance = "https://" + instance;
}
if (!instance.endsWith("/")){
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')
})