2022-12-24 01:38:21 +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;
|
2022-12-24 01:38:21 +01:00
|
|
|
const url = `${config.shlinkUrl}/rest/v3/short-urls`;
|
2022-12-15 21:01:26 +01:00
|
|
|
let sendData = {
|
|
|
|
"longUrl": currentUrl,
|
|
|
|
"tags": ["Added by BOTv1"]
|
|
|
|
};
|
|
|
|
const request = new XMLHttpRequest();
|
|
|
|
request.open('POST', url);
|
|
|
|
request.setRequestHeader('accept', 'application/json');
|
2022-12-24 01:38:21 +01:00
|
|
|
request.setRequestHeader('X-Api-Key', `${config.shlinkApiKey}`);
|
2022-12-15 21:01:26 +01:00
|
|
|
request.setRequestHeader('Content-type', 'application/json');
|
|
|
|
request.send(JSON.stringify(sendData));
|
|
|
|
request.onload = (e) => {
|
2022-12-24 01:38:21 +01:00
|
|
|
var shortUrlOut = document.getElementById("output-shortUrl")
|
|
|
|
var responseData = JSON.parse(request.response);
|
|
|
|
shortUrlOut.value = `${config.shlinkOutUrl}/${responseData.shortCode}`;
|
2022-12-25 14:25:24 +01:00
|
|
|
shlinkAppBtnRdUrl = `${config.shlinkAppUrl}/short-code/${responseData.shortCode}/${config.shlinkAppOpenMode}`;
|
2022-12-25 17:59:07 +01:00
|
|
|
//document.getElementById("newButton").style.display = 'none'; //to be worked on
|
|
|
|
//document.getElementById("cancelButton").style.display = 'block'; //to be worked on
|
2022-12-24 01:38:21 +01:00
|
|
|
document.getElementById("p1qr-code").src = `${config.shlinkUrl}/${responseData.shortCode}/qr-code?size=160&format=png&margin=2&errorCorrection=L`;
|
2022-12-15 21:01:26 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|