2022-12-15 21:01:26 +01:00
|
|
|
const searchButton = document.getElementById('searchButton');
|
|
|
|
if (searchButton) {
|
|
|
|
searchButton.addEventListener('click', () => {
|
2022-12-15 23:49:01 +01:00
|
|
|
searchRedirect();
|
2022-12-15 21:01:26 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
const newButton = document.getElementById('newButton');
|
|
|
|
if (newButton) {
|
|
|
|
newButton.addEventListener('click', () => {
|
2022-12-15 23:49:01 +01:00
|
|
|
newRedirect();
|
2022-12-15 21:01:26 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-15 23:49:01 +01:00
|
|
|
function searchRedirect() {
|
2022-12-15 21:01:26 +01:00
|
|
|
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)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 23:49:01 +01:00
|
|
|
function newRedirect() {
|
2022-12-15 21:01:26 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|