-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from J4mez/dev
Fixed the scaling issues with 1.3
- Loading branch information
Showing
6 changed files
with
61 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters