Update results.html
Browse files- results.html +16 -9
results.html
CHANGED
|
@@ -9,13 +9,13 @@
|
|
| 9 |
body { font-family: 'Tajawal', sans-serif; background: #fff; color: #202124; margin: 0; padding: 20px; }
|
| 10 |
.header { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; border-bottom: 1px solid #eee; padding-bottom: 15px; }
|
| 11 |
.logo { color: #4285f4; font-weight: 800; font-size: 24px; text-decoration: none; }
|
| 12 |
-
.search-box { flex-grow: 1; padding: 10px 15px; border-radius: 24px; border: 1px solid #dfe1e5; outline: none; }
|
| 13 |
.result { margin-bottom: 25px; max-width: 650px; }
|
| 14 |
.result a { color: #1a0dab; text-decoration: none; font-size: 18px; }
|
| 15 |
.result a:hover { text-decoration: underline; }
|
| 16 |
-
.result p { font-size: 14px; color: #4d5156; margin-top: 5px; }
|
| 17 |
#loader { color: #70757a; font-style: italic; text-align: center; margin-top: 50px; }
|
| 18 |
-
.error { color: #d93025; background: #fce8e6; padding:
|
| 19 |
</style>
|
| 20 |
</head>
|
| 21 |
<body>
|
|
@@ -25,12 +25,11 @@
|
|
| 25 |
<input type="text" id="q-input" class="search-box">
|
| 26 |
</div>
|
| 27 |
|
| 28 |
-
<div id="loader">جاري جلب النتائج
|
| 29 |
<div id="error" class="error"></div>
|
| 30 |
<div id="results-area"></div>
|
| 31 |
|
| 32 |
<script>
|
| 33 |
-
// الرابط الذي أكدنا أنه يعمل
|
| 34 |
const PROXY_URL = "https://script.google.com/macros/s/AKfycbwhN620MNa08vQs2qSntQBsPW9JilXcVYg5VEfCciqX1vr2i-YrY35r3ZpYSS1NEZ3I/exec";
|
| 35 |
const SEARXNG_URL = "https://searxng-anesnt-dev.apps.rm1.0a51.p1.openshiftapps.com/search";
|
| 36 |
|
|
@@ -45,13 +44,20 @@
|
|
| 45 |
const loader = document.getElementById('loader');
|
| 46 |
const errorDiv = document.getElementById('error');
|
| 47 |
|
| 48 |
-
|
| 49 |
-
const finalUrl = `${PROXY_URL}?url=${encodeURIComponent(
|
| 50 |
|
| 51 |
try {
|
| 52 |
const response = await fetch(finalUrl);
|
| 53 |
-
const
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
loader.style.display = 'none';
|
| 56 |
|
| 57 |
if (!data.results || data.results.length === 0) {
|
|
@@ -59,6 +65,7 @@
|
|
| 59 |
return;
|
| 60 |
}
|
| 61 |
|
|
|
|
| 62 |
data.results.forEach(item => {
|
| 63 |
area.innerHTML += `
|
| 64 |
<div class="result">
|
|
@@ -70,7 +77,7 @@
|
|
| 70 |
} catch (err) {
|
| 71 |
loader.style.display = 'none';
|
| 72 |
errorDiv.style.display = 'block';
|
| 73 |
-
errorDiv.
|
| 74 |
console.error(err);
|
| 75 |
}
|
| 76 |
}
|
|
|
|
| 9 |
body { font-family: 'Tajawal', sans-serif; background: #fff; color: #202124; margin: 0; padding: 20px; }
|
| 10 |
.header { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; border-bottom: 1px solid #eee; padding-bottom: 15px; }
|
| 11 |
.logo { color: #4285f4; font-weight: 800; font-size: 24px; text-decoration: none; }
|
| 12 |
+
.search-box { flex-grow: 1; padding: 10px 15px; border-radius: 24px; border: 1px solid #dfe1e5; outline: none; font-family: 'Tajawal', sans-serif; font-size: 16px;}
|
| 13 |
.result { margin-bottom: 25px; max-width: 650px; }
|
| 14 |
.result a { color: #1a0dab; text-decoration: none; font-size: 18px; }
|
| 15 |
.result a:hover { text-decoration: underline; }
|
| 16 |
+
.result p { font-size: 14px; color: #4d5156; margin-top: 5px; line-height: 1.5; }
|
| 17 |
#loader { color: #70757a; font-style: italic; text-align: center; margin-top: 50px; }
|
| 18 |
+
.error { color: #d93025; background: #fce8e6; padding: 15px; border-radius: 8px; display: none; line-height: 1.6; }
|
| 19 |
</style>
|
| 20 |
</head>
|
| 21 |
<body>
|
|
|
|
| 25 |
<input type="text" id="q-input" class="search-box">
|
| 26 |
</div>
|
| 27 |
|
| 28 |
+
<div id="loader">جاري جلب النتائج...</div>
|
| 29 |
<div id="error" class="error"></div>
|
| 30 |
<div id="results-area"></div>
|
| 31 |
|
| 32 |
<script>
|
|
|
|
| 33 |
const PROXY_URL = "https://script.google.com/macros/s/AKfycbwhN620MNa08vQs2qSntQBsPW9JilXcVYg5VEfCciqX1vr2i-YrY35r3ZpYSS1NEZ3I/exec";
|
| 34 |
const SEARXNG_URL = "https://searxng-anesnt-dev.apps.rm1.0a51.p1.openshiftapps.com/search";
|
| 35 |
|
|
|
|
| 44 |
const loader = document.getElementById('loader');
|
| 45 |
const errorDiv = document.getElementById('error');
|
| 46 |
|
| 47 |
+
const targetSearch = `${SEARXNG_URL}?q=${encodeURIComponent(q)}&format=json&language=ar`;
|
| 48 |
+
const finalUrl = `${PROXY_URL}?url=${encodeURIComponent(targetSearch)}`;
|
| 49 |
|
| 50 |
try {
|
| 51 |
const response = await fetch(finalUrl);
|
| 52 |
+
const text = await response.text();
|
| 53 |
|
| 54 |
+
// فحص إذا كان السيرفر أرجع صفحة ويب بدلاً من البيانات
|
| 55 |
+
if (text.trim().startsWith("<")) {
|
| 56 |
+
console.error("الرد المستلم ليس JSON:", text);
|
| 57 |
+
throw new Error("تعذر جلب البيانات. الرجاء التأكد من أن سيرفر SearXNG على OpenShift قيد التشغيل ولم يتوقف، أو أن جوجل يرفض تمرير الطلب.");
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
const data = JSON.parse(text);
|
| 61 |
loader.style.display = 'none';
|
| 62 |
|
| 63 |
if (!data.results || data.results.length === 0) {
|
|
|
|
| 65 |
return;
|
| 66 |
}
|
| 67 |
|
| 68 |
+
area.innerHTML = "";
|
| 69 |
data.results.forEach(item => {
|
| 70 |
area.innerHTML += `
|
| 71 |
<div class="result">
|
|
|
|
| 77 |
} catch (err) {
|
| 78 |
loader.style.display = 'none';
|
| 79 |
errorDiv.style.display = 'block';
|
| 80 |
+
errorDiv.innerHTML = `<b>حدث خطأ أثناء الاتصال:</b><br>${err.message}`;
|
| 81 |
console.error(err);
|
| 82 |
}
|
| 83 |
}
|