Fixed getting query urls
This commit is contained in:
parent
e00df8d0fc
commit
06fa44f2bf
46
main.js
46
main.js
|
@ -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;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"description": "A simple url shortener",
|
||||
"short_name": "LinkyLinky",
|
||||
"permissions": [
|
||||
"activeTab",
|
||||
"tabs",
|
||||
"notifications"
|
||||
],
|
||||
"browser_action": {
|
||||
|
|
Loading…
Reference in New Issue