From ee1089ef65e39d27fb8266ae82174ba3e975ea2f Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Wed, 23 Sep 2020 18:32:29 +0200 Subject: [PATCH] Allow prefilling instance URL from parameter --- src/script/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/script/index.js b/src/script/index.js index 6386d6b..043b8ea 100644 --- a/src/script/index.js +++ b/src/script/index.js @@ -1,7 +1,4 @@ -var remembered = window.localStorage.getItem('mastodon_instance'); -if (remembered != null) { - document.getElementById('instance').value = remembered; -} +var prefillInstance = window.localStorage.getItem('mastodon_instance'); var paramPairs = window.location.search.substr(1).split('&'); var paramPairsLength = paramPairs.length; @@ -10,12 +7,17 @@ for (var i = 0; i < paramPairsLength; i++) { var paramPair = paramPairs[i].split('='); if (paramPair[0] === 'text') { document.getElementById('text').value = decodeURIComponent(paramPair[1]); - break; + } else if (paramPair[0] === 'instance') { + prefillInstance = decodeURIComponent(paramPair[1]); } } delete i delete paramPair +if (prefillInstance != null) { + document.getElementById('instance').value = prefillInstance; +} + document .getElementById('form') .addEventListener('submit', function (e) {