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 @@ + + + +
+
+
redirect
+ + +
+
\ No newline at end of file