From ae563a614fb8dd2069a2de381621ba6e14e9b098 Mon Sep 17 00:00:00 2001 From: Craftplacer Date: Fri, 24 Jul 2020 10:39:46 +0200 Subject: [PATCH] Optimize remote follow script performance --- scripts/remote-follow.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/remote-follow.js b/scripts/remote-follow.js index 3bef46f..3a27fdc 100644 --- a/scripts/remote-follow.js +++ b/scripts/remote-follow.js @@ -1,15 +1,21 @@ -const form = document.getElementById("followForm"); -form.addEventListener("submit", function (e) { - e.preventDefault(); - - var urlField = document.getElementById("instanceUrl"); - var url = document.createElement('a'); - url.href = urlField.value; +function initializeForm() { + const form = document.getElementById("followForm"); - var followUrl = "https://" + url.hostname + "/ostatus_subscribe?acct=https://enigmatic.observer/users/Husky"; + form.addEventListener("submit", function (e) { + e.preventDefault(); + + var urlField = document.getElementById("instanceUrl"); + var url = document.createElement('a'); + url.href = urlField.value; - window.location = followUrl; -}); + var followUrl = "https://" + url.hostname + "/ostatus_subscribe?acct=https://enigmatic.observer/users/Husky"; -const followButton = document.getElementById("followButton"); -followButton.disabled = false; \ No newline at end of file + window.location = followUrl; + }); + + // we enable the button to indicate that the form is working and accepts input. + const followButton = document.getElementById("followButton"); + followButton.disabled = false; +} + +document.addEventListener("DOMContentLoaded", initializeForm); \ No newline at end of file