From a48e1f9b4021321cfd2940bd2f2b23ce57d87b16 Mon Sep 17 00:00:00 2001 From: Tijl <85572877+xTTLegend@users.noreply.github.com> Date: Thu, 15 Dec 2022 21:01:26 +0100 Subject: [PATCH] v1 --- assets/logo.png | 0 background.js | 0 manifest.json | 15 +++++++++++++++ popup-func.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ popup.css | 22 ++++++++++++++++++++++ popup.html | 10 ++++++++++ 6 files changed, 95 insertions(+) create mode 100644 assets/logo.png create mode 100644 background.js create mode 100644 manifest.json create mode 100644 popup-func.js create mode 100644 popup.css create mode 100644 popup.html diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000..e69de29 diff --git a/background.js b/background.js new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..3c7f2d9 --- /dev/null +++ b/manifest.json @@ -0,0 +1,15 @@ +{ + "name": "redirect", + "version": "0.1.0", + "description": "create a redirect directly", + "permissions": ["storage", "tabs"], + "background": { + "service_worker": "background.js" + }, + "action": { + "default_icon": "assets/icon.png", + "default_title": "redirect", + "default_popup": "popup.html" + }, + "manifest_version": 3 +} \ No newline at end of file diff --git a/popup-func.js b/popup-func.js new file mode 100644 index 0000000..55a70f7 --- /dev/null +++ b/popup-func.js @@ -0,0 +1,48 @@ +const searchButton = document.getElementById('searchButton'); +if (searchButton) { + searchButton.addEventListener('click', () => { + searchRedirect('test'); + }) +} +const newButton = document.getElementById('newButton'); +if (newButton) { + newButton.addEventListener('click', () => { + newRedirect('test'); + }) +} + +function searchRedirect(host) { + const request = new XMLHttpRequest(); + const url = 'https://url.example.com/rest/v3/short-urls'; + request.open('GET', url); + request.setRequestHeader('X-Api-Key', 'apikeyhere'); + request.send(); + request.onload = (e) => { + var shortUrls = request.response + chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => { + let url = tabs[0].url; + alert(shortUrls) + }); + } +} + +function newRedirect(host) { + chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => { + let currentUrl = tabs[0].url; + const url = 'https://url.example.com/rest/v3/short-urls'; + let sendData = { + "longUrl": currentUrl, + "tags": ["Added by BOTv1"] + }; + const request = new XMLHttpRequest(); + request.open('POST', url); + request.setRequestHeader('accept', 'application/json'); + request.setRequestHeader('X-Api-Key', 'apikeyhere'); + request.setRequestHeader('Content-type', 'application/json'); + request.send(JSON.stringify(sendData)); + request.onload = (e) => { + var responseData = request.response; + document.getElementById("p1link").innerHTML = responseData; + } + }); +} \ No newline at end of file diff --git a/popup.css b/popup.css new file mode 100644 index 0000000..9ab62d8 --- /dev/null +++ b/popup.css @@ -0,0 +1,22 @@ +.container { + width: 360px; + color: #314d3e; + } + + .title { + font-size: 16px; + font-weight: bold; + padding: 10px; + } + + .textbox { + width: 100%; + font-size: 10px; + margin: 0; + padding: 0px 2px; + } + + .textbox:focus { + outline: 0; + border-color: #66afe9; + } \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..3a5abf5 --- /dev/null +++ b/popup.html @@ -0,0 +1,10 @@ + + + +
[click new to generate a link]
+