Starchik1 commited on
Commit
411b780
·
verified ·
1 Parent(s): 40a909c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +16 -10
index.html CHANGED
@@ -2,7 +2,7 @@
2
  <html lang="ru">
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>Поиск по названию (с CORS-прокси)</title>
6
  <style>
7
  body {
8
  font-family: Arial, sans-serif;
@@ -22,7 +22,7 @@
22
  </style>
23
  </head>
24
  <body>
25
- <h1>Поиск по названию (с CORS‑прокси)</h1>
26
  <input type="text" id="searchInput" placeholder="Введите название" />
27
  <button id="searchBtn">Найти</button>
28
 
@@ -32,8 +32,6 @@
32
  // Клиентский ID и API‑токен
33
  const clientID = "zR0vDH4SV0zd";
34
  const apiToken = "7KRyeRqk77NXXRRQ99R0JDhpvzWesA4L";
35
- // Используем альтернативный CORS‑прокси
36
- const corsProxy = "https://thingproxy.freeboard.io/fetch/";
37
 
38
  document.getElementById('searchBtn').addEventListener('click', function() {
39
  const title = document.getElementById('searchInput').value.trim();
@@ -42,15 +40,16 @@
42
  return;
43
  }
44
 
45
- // Формирование URL запроса к API
46
  const targetUrl = `https://portal.lumex.host/api/short?api_token=${apiToken}&title=${encodeURIComponent(title)}`;
47
- // Обходим CORS‑ограничения через прокси
48
- const url = corsProxy + targetUrl;
 
49
 
50
  const resultsContainer = document.getElementById('results');
51
  resultsContainer.innerHTML = 'Загрузка...';
52
 
53
- fetch(url)
54
  .then(response => {
55
  if (!response.ok) {
56
  throw new Error("Ошибка сети: " + response.status);
@@ -58,8 +57,15 @@
58
  return response.json();
59
  })
60
  .then(data => {
61
- if (data.result) {
62
- const items = data.data;
 
 
 
 
 
 
 
63
  let html = '';
64
  if (items.length === 0) {
65
  html = '<p>Нет результатов</p>';
 
2
  <html lang="ru">
3
  <head>
4
  <meta charset="UTF-8">
5
+ <title>Поиск по названию (с CORS‑прокси через AllOrigins)</title>
6
  <style>
7
  body {
8
  font-family: Arial, sans-serif;
 
22
  </style>
23
  </head>
24
  <body>
25
+ <h1>Поиск по названию (с CORS‑прокси через AllOrigins)</h1>
26
  <input type="text" id="searchInput" placeholder="Введите название" />
27
  <button id="searchBtn">Найти</button>
28
 
 
32
  // Клиентский ID и API‑токен
33
  const clientID = "zR0vDH4SV0zd";
34
  const apiToken = "7KRyeRqk77NXXRRQ99R0JDhpvzWesA4L";
 
 
35
 
36
  document.getElementById('searchBtn').addEventListener('click', function() {
37
  const title = document.getElementById('searchInput').value.trim();
 
40
  return;
41
  }
42
 
43
+ // URL для запроса к API
44
  const targetUrl = `https://portal.lumex.host/api/short?api_token=${apiToken}&title=${encodeURIComponent(title)}`;
45
+
46
+ // Используем AllOrigins для обхода CORS‑ограничений
47
+ const allOriginsUrl = "https://api.allorigins.hexocode.repl.co/get?disableCache=true&url=" + encodeURIComponent(targetUrl);
48
 
49
  const resultsContainer = document.getElementById('results');
50
  resultsContainer.innerHTML = 'Загрузка...';
51
 
52
+ fetch(allOriginsUrl)
53
  .then(response => {
54
  if (!response.ok) {
55
  throw new Error("Ошибка сети: " + response.status);
 
57
  return response.json();
58
  })
59
  .then(data => {
60
+ let jsonData;
61
+ try {
62
+ jsonData = JSON.parse(data.contents);
63
+ } catch (e) {
64
+ throw new Error("Ошибка разбора данных: " + e.message);
65
+ }
66
+
67
+ if (jsonData.result) {
68
+ const items = jsonData.data;
69
  let html = '';
70
  if (items.length === 0) {
71
  html = '<p>Нет результатов</p>';