From 04948e24f94b5b687e8718de846604af07c6d9cc Mon Sep 17 00:00:00 2001 From: and94x Date: Wed, 17 Aug 2022 20:50:55 +0200 Subject: [PATCH] predict wss url --- base/settings/settings.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/base/settings/settings.js b/base/settings/settings.js index 411892a..0e87002 100644 --- a/base/settings/settings.js +++ b/base/settings/settings.js @@ -55,7 +55,7 @@ function save() { // Restores select box and checkbox state using the preferences // stored in chrome.storage. -function load() { +function load(){ if (chrome && chrome.storage && chrome.storage.local) { chrome.storage.local.get({ baseURL: getMessage("settingsFormInputRequired"), @@ -69,5 +69,23 @@ function load() { } } -document.addEventListener('DOMContentLoaded', load); -saveButton.addEventListener('click', validateAndSave); \ No newline at end of file +function autofillWSSURL() { + console.log('here am i'); + if (stammTVBaseUrl.value.startsWith('http')) { + let predictedWSSURL = stammTVBaseUrl.value.replace('https', 'wss').replace('http', 'wss'); + if (predictedWSSURL.endsWith('/')) { + predictedWSSURL += 'wss' + } else { + predictedWSSURL += '/wss' + } + stammTVWSSUrl.value = predictedWSSURL; + } +} + +document.addEventListener('DOMContentLoaded', init); + +function init() { + stammTVBaseUrl.onchange = autofillWSSURL; + saveButton.addEventListener('click', validateAndSave); + load(); +} \ No newline at end of file