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

23 lines
1.2 KiB
JavaScript
Raw Normal View History

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}`;
var shlinkAppBtnRdUrl = `${config.shlinkAppUrl}/short-code/${responseData.shortCode}/visits`;
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
}
});
}