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 @@

Share this URL!

- + diff --git a/src/popup/index.js b/src/popup/index.js index 605abe5..2af9e00 100644 --- a/src/popup/index.js +++ b/src/popup/index.js @@ -1,37 +1,15 @@ -//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); - } -} - getCurrentTabUrl() .then((currentUrl) => { - document.getElementById("currentUrl").textContent = ("URL to share: " + currentUrl); + //trimm the URL if it's loger than 50 characters + if (currentUrl.length > 50) { + var showCurrentUrl = currentUrl.substring(0, 50) + "..."; + } + else { + var showCurrentUrl = currentUrl; + } + document.getElementById("currentUrl").textContent = + "URL to share: " + showCurrentUrl; }) .catch((error) => { console.error(error); - }); \ No newline at end of file + }); diff --git a/src/popup/share.html b/src/popup/share.html index a469742..8a296b8 100644 --- a/src/popup/share.html +++ b/src/popup/share.html @@ -72,7 +72,7 @@

Share this URL!

- + diff --git a/src/popup/share.js b/src/popup/share.js index a2af38f..e43a218 100644 --- a/src/popup/share.js +++ b/src/popup/share.js @@ -1,3 +1,21 @@ +//show the current URL in the popup +getCurrentTabUrl() + .then((currentUrl) => { + //trimm the URL if it's loger than 50 characters + if (currentUrl.length > 50) { + var showCurrentUrl = currentUrl.substring(0, 50) + "..."; + } + else { + var showCurrentUrl = currentUrl; + } + document.getElementById("currentUrl").textContent = + "URL to share: " + showCurrentUrl; + }) + .catch((error) => { + console.error(error); + }); + + async function generateShortURL(options) { const longUrl = await getCurrentTabUrl(); @@ -41,41 +59,6 @@ function generatePreview() { "Preview: " + previewUrl; } -//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); - } -} - -getCurrentTabUrl() - .then((currentUrl) => { - document.getElementById("currentUrl").textContent = - "URL to share: " + currentUrl; - }) - .catch((error) => { - console.error(error); - }); //handle the slug setting in the share form. This overrites the slug in the options page and is saved when the user clicks on the share button const form = document.getElementById("sharingOptionsForm"); From 93973a6c6642c7e6a12243fac106215003882def Mon Sep 17 00:00:00 2001 From: James <58501310+J4mez@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:18:07 +0100 Subject: [PATCH 2/2] bumped manifest --- src/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manifest.json b/src/manifest.json index 5036c0c..b41f8d6 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "FireLink", - "version": "1.3", + "version": "1.4", "description": "Creates sharable links with a click of a button",