hgfj / index.html
Starchik1's picture
Update index.html
d2e5f0d verified
raw
history blame
3.7 kB
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Поиск по названию (с CORS-прокси)</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#results {
margin-top: 20px;
}
.item {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
.item h3 {
margin: 0;
}
</style>
</head>
<body>
<h1>Поиск по названию (с CORS-прокси)</h1>
<input type="text" id="searchInput" placeholder="Введите название" />
<button id="searchBtn">Найти</button>
<div id="results"></div>
<script>
// Клиентский ID и API-токен
const clientID = "zR0vDH4SV0zd";
const apiToken = "7KRyeRqk77NXXRRQ99R0JDhpvzWesA4L";
// URL публичного CORS-прокси. Для работы может потребоваться предварительное получение доступа.
const corsProxy = "https://cors-anywhere.herokuapp.com/";
document.getElementById('searchBtn').addEventListener('click', function() {
const title = document.getElementById('searchInput').value.trim();
if (!title) {
alert('Введите название для поиска');
return;
}
// Формирование URL запроса к API
const targetUrl = `https://portal.lumex.host/api/short?api_token=${apiToken}&title=${encodeURIComponent(title)}`;
// Добавляем URL CORS-прокси для обхода ограничений CORS
const url = corsProxy + targetUrl;
const resultsContainer = document.getElementById('results');
resultsContainer.innerHTML = 'Загрузка...';
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error("Ошибка сети: " + response.status);
}
return response.json();
})
.then(data => {
if (data.result) {
const items = data.data;
let html = '';
if (items.length === 0) {
html = '<p>Нет результатов</p>';
} else {
items.forEach(item => {
// Если ссылка для iframe начинается с //, дополняем протоколом
let iframeUrl = item.iframe_src;
if (iframeUrl && iframeUrl.startsWith('//')) {
iframeUrl = 'https:' + iframeUrl;
}
html += `<div class="item">
<h3>${item.title}</h3>
<p><strong>ID:</strong> ${item.id}</p>
<p><strong>Kinopoisk ID:</strong> ${item.kp_id}</p>
<p><strong>IMDB ID:</strong> ${item.imdb_id}</p>
<p><strong>Тип:</strong> ${item.type}</p>
<p><strong>Год:</strong> ${item.year}</p>`;
if (iframeUrl) {
html += `<p><a href="${iframeUrl}" target="_blank">Смотреть видео</a></p>`;
}
html += `</div>`;
});
}
resultsContainer.innerHTML = html;
} else {
resultsContainer.innerHTML = '<p>Ошибка при получении данных</p>';
}
})
.catch(error => {
console.error('Ошибка:', error);
resultsContainer.innerHTML = '<p>Ошибка при выполнении запроса: ' + error.message + '</p>';
});
});
</script>
</body>
</html>