0
0
mirror of https://github.com/Maks1mS/free-ozon-dpr.git synced 2024-12-24 02:52:58 +03:00
free-ozon-dpr/scripts/utils.js

23 lines
623 B
JavaScript
Raw Normal View History

2024-06-05 14:56:19 +03:00
export async function getFinalURL(url) {
let response = await fetch(url, {
method: "HEAD",
redirect: "manual",
});
while (
response.status >= 300 &&
response.status < 400 &&
response.headers.get("location") &&
new URL(url).hostname !== 'ozon.ru'
) {
url = response.headers.get("location");
if (!url.startsWith("http")) {
const baseUrl = new URL(response.url);
url = `${baseUrl.protocol}//${baseUrl.host}${url}`;
}
response = await fetch(url, {
method: "HEAD",
redirect: "manual",
});
}
return url;
}