This repository has been archived on 2023-02-22. You can view files and clone it, but cannot push or open issues or pull requests.
redirect-extention-chrome/popup-func.js
2022-12-26 23:08:35 +01:00

25 lines
1.4 KiB
JavaScript

function newRedirect () {
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let currentUrl = tabs[0].url;
const url = `${config.shlinkUrl}/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', `${config.shlinkApiKey}`);
request.setRequestHeader('Content-type', 'application/json');
request.send(JSON.stringify(sendData));
request.onload = (e) => {
var shortUrlOut = document.getElementById("output-shortUrl");
var responseData = JSON.parse(request.response);
shortUrlOut.value = `${config.shlinkOutUrl}/${responseData.shortCode}`;
shlinkAppBtnRdUrl = `${config.shlinkAppUrl}/short-code/${responseData.shortCode}/${config.shlinkAppOpenMode}`;
//document.getElementById("newButton").style.display = 'none'; //to be worked on
//document.getElementById("cancelButton").style.display = 'block'; //to be worked on
document.getElementById("p1qr-code").src = `${config.shlinkUrl}/${responseData.shortCode}/qr-code?size=160&format=png&margin=2&errorCorrection=L`;
}
});
}