Fixed getting query urls

This commit is contained in:
Nicolai Ort 2021-08-14 15:32:03 +02:00
parent e00df8d0fc
commit 06fa44f2bf
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
2 changed files with 26 additions and 22 deletions

46
main.js
View File

@ -14,29 +14,33 @@ clipboard.on('success', function (e) {
document.getElementById("create").onclick = createUrl;
// Calls the api to create a new short url
function createUrl() {
shorturl = {
target: window.location.href,
shortcode: document.getElementById("shortcode").value
};
if (shorturl.shortcode == "" | !shorturl.shortcode) {
delete shorturl.shortcode;
}
chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => {
let shorturl = {
target: tabs[0].url,
shortcode: document.getElementById("shortcode").value
};
fetch(`${baseurl}/api`, {
method: "POST",
body: JSON.stringify(shorturl),
headers: new Headers({
'Content-Type': 'application/json'
if (shorturl.shortcode == "" | !shorturl.shortcode) {
delete shorturl.shortcode;
}
fetch(`${baseurl}/api`, {
method: "POST",
body: JSON.stringify(shorturl),
headers: new Headers({
'Content-Type': 'application/json'
})
})
})
.then(res => res.json())
.then(res => {
document.getElementById("shorturl").innerText = res.url;
document.getElementById("shorturl_container").className = "";
document.getElementById("shortcode_container").className = "hidden";
document.getElementById("create").classList.add("hidden");
document.getElementById("reset").classList.remove("hidden");
});
.then(res => res.json())
.then(res => {
document.getElementById("shorturl").innerText = res.url;
document.getElementById("shorturl_container").className = "";
document.getElementById("shortcode_container").className = "hidden";
document.getElementById("create").classList.add("hidden");
document.getElementById("reset").classList.remove("hidden");
});
});
}
document.getElementById("reset").onclick = reset;

View File

@ -5,7 +5,7 @@
"description": "A simple url shortener",
"short_name": "LinkyLinky",
"permissions": [
"activeTab",
"tabs",
"notifications"
],
"browser_action": {