From c84f6b65eb00ff03141101d3d53b7a1485336079 Mon Sep 17 00:00:00 2001 From: James <58501310+J4mez@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:17:34 +0100 Subject: [PATCH 1/2] fixed some scaling issues --- src/popup/global.js | 28 +++++++++++++++++++++++ src/popup/index.html | 5 +++-- src/popup/index.js | 42 +++++++++-------------------------- src/popup/share.html | 2 +- src/popup/share.js | 53 +++++++++++++++----------------------------- 5 files changed, 60 insertions(+), 70 deletions(-) diff --git a/src/popup/global.js b/src/popup/global.js index 8b42616..40d710b 100644 --- a/src/popup/global.js +++ b/src/popup/global.js @@ -95,3 +95,31 @@ function hideSuccess() { successMessage.textContent = ""; successDiv.classList.add("d-none"); } + +//gets the current URL and displays it in the popup. Later this will be used to generate a short URL +const DEFAULT_URL = "https://example.com"; + +function getDefaultUrl() { + let tabs = [{ url: DEFAULT_URL }]; + return Promise.resolve(tabs[0].url); +} + +async function getCurrentTabUrl() { + if (typeof browser === "undefined" || !browser.tabs) { + return getDefaultUrl(); + } + try { + let tabs = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + //check if the tab is valid and has http or https in the URL if not return the default URL + if (tabs[0].url === undefined || !tabs[0].url.startsWith("http")) { + return getDefaultUrl(); + } + return tabs[0].url; + } catch (error) { + throw new Error("An error occurred: " + error); + } +} + diff --git a/src/popup/index.html b/src/popup/index.html index b06c39b..3691087 100644 --- a/src/popup/index.html +++ b/src/popup/index.html @@ -6,7 +6,8 @@
@@ -20,6 +21,6 @@