mirror of
https://github.com/Maks1mS/free-ozon-dpr.git
synced 2024-12-24 02:52:58 +03:00
23 lines
623 B
JavaScript
23 lines
623 B
JavaScript
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;
|
|
} |