File size: 3,696 Bytes
d2e5f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3dbe39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!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>