From 06fa44f2bf4e57d2c85248104fe7c9d94d48d7bd Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sat, 14 Aug 2021 15:32:03 +0200 Subject: [PATCH] Fixed getting query urls --- main.js | 46 +++++++++++++++++++++++++--------------------- manifest.json | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/main.js b/main.js index e4d2fd4..e3d6da1 100644 --- a/main.js +++ b/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; diff --git a/manifest.json b/manifest.json index f1d7116..a17515a 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": "A simple url shortener", "short_name": "LinkyLinky", "permissions": [ - "activeTab", + "tabs", "notifications" ], "browser_action": {