Skip to content

Commit

Permalink
Merge pull request #9 from J4mez/dev
Browse files Browse the repository at this point in the history
Fixed the scaling issues with 1.3
  • Loading branch information
J4mez authored Jan 22, 2024
2 parents adbd3c5 + 93973a6 commit 49c5c4b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -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",

Expand Down
28 changes: 28 additions & 0 deletions src/popup/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

5 changes: 3 additions & 2 deletions src/popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
</head>
<style>
body {
overflow: auto;
overflow-y: auto;
max-width: 300px;
}
</style>
<body class="container py-3">
Expand All @@ -20,6 +21,6 @@ <h1 class="mb-4">Share this URL!</h1>
<button id="shareButton" class="btn btn-primary mt-3">Share URL</button>
</div>
</body>
<script src="index.js"></script>
<script src="global.js"></script>
<script src="index.js"></script>
</html>
42 changes: 10 additions & 32 deletions src/popup/index.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 1 addition & 1 deletion src/popup/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h1 class="text-center">Share this URL!</h1>
</div>
</div>
</div>
<script src="share.js"></script>
<script src="global.js"></script>
<script src="share.js"></script>
</body>
</html>
53 changes: 18 additions & 35 deletions src/popup/share.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 49c5c4b

Please sign in to comment.