From 37d4b3cda47e9a78136650894e6d596a5a9ebbf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rigal?= Date: Sat, 10 Sep 2022 14:38:33 +0200 Subject: [PATCH] Improve options page --- js/pyload-api.js | 20 ++++++++++++++------ js/storage.js | 5 ++--- manifest.json | 2 +- options.html | 12 +++++++----- options.js | 18 ++++++++++++++++-- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/js/pyload-api.js b/js/pyload-api.js index e9f89e3..5a3585b 100644 --- a/js/pyload-api.js +++ b/js/pyload-api.js @@ -7,20 +7,28 @@ function getServerStatus(callback) { xhr.onreadystatechange = function() { if (xhr.readyState === 4) { try { + if (xhr.status === 404) { + if (callback) callback(false, false, 'Server not found'); + return; + } const response = JSON.parse(xhr.responseText); - if (response.hasOwnProperty('error')) { - if (callback) callback(false, response.error); - } else { - if (callback) callback(true, null, response); + if (xhr.status === 200) { + if (callback) callback(true, false, null, response); + } else if (xhr.status === 403) { + if (callback) callback(false, true, 'Unauthorized', response); + } else if (response.hasOwnProperty('error')) { + if (callback) callback(false, false, response.error); + } else { + if (callback) callback(false, false, null, response); } } catch { - if (callback) callback(false, 'Server unreachable'); + if (callback) callback(false, false, 'Server unreachable'); } } } xhr.timeout = 5000; xhr.ontimeout = function() { - if (callback) callback(false, 'Server unreachable'); + if (callback) callback(false, false, 'Server unreachable'); } xhr.send(); } diff --git a/js/storage.js b/js/storage.js index 8782390..928c064 100644 --- a/js/storage.js +++ b/js/storage.js @@ -16,10 +16,9 @@ function pullStoredData(callback) { } function isLoggedIn(callback) { - getServerStatus(function(success) { + getServerStatus(function(success, unauthorized, error, response) { if (callback) { - if (success) callback(true); - else callback(false); + callback(success, unauthorized, error, response); } }); } diff --git a/manifest.json b/manifest.json index 2ea9541..3d991d5 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Yape", - "version": "1.1.0", + "version": "1.1.1", "description": "Extension for PyLoad to easily monitor and add downloads", "permissions": ["activeTab", "storage", "contextMenus", "scripting"], "host_permissions": ["http://*/", "https://*/"], diff --git a/options.html b/options.html index 106cf8a..95d8c08 100644 --- a/options.html +++ b/options.html @@ -23,13 +23,15 @@
+ +
+ Please provide a valid port +
-
- - -
+ +
Please provide a valid path @@ -37,7 +39,7 @@
- +
diff --git a/options.js b/options.js index 12a83cb..31219d9 100644 --- a/options.js +++ b/options.js @@ -53,11 +53,17 @@ function updateLoggedInStatus(callback) { loginStatusKODiv.hidden = true; loginButton.hidden = true; enableSpinner(); - isLoggedIn(function(loggedIn) { + isLoggedIn(function(loggedIn, unauthorized, error) { disableSpinner(); loginStatusOKDiv.hidden = !loggedIn; loginStatusKODiv.hidden = loggedIn; - loginButton.hidden = loggedIn; + loginStatusKODiv.innerHTML = `` + if (!loggedIn && unauthorized) { + loginStatusKODiv.innerHTML += `Please log in`; + } else { + loginStatusKODiv.innerHTML += error ? error : `You are not logged in`; + } + loginButton.hidden = !unauthorized; saveButton.disabled = false; if (callback) callback(); }); @@ -101,6 +107,14 @@ function validateForm() { serverIpInput.classList.add('is-invalid'); saveButton.disabled = true; } + // Port + const isValidPort = /\d+/.test(serverPortInput.value); + if (isValidPort) { + serverPortInput.classList.remove('is-invalid'); + } else { + serverPortInput.classList.add('is-invalid'); + saveButton.disabled = true; + } // Path const isValidPath = /^((\/[.\w-]+)*\/{0,1}|\/)$/.test(serverPathInput.value); if (isValidPath) {