s / results.html
AnesKAM's picture
Update results.html
e3c6def verified
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SurfGO - النتائج</title>
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Tajawal', sans-serif; background: #fff; color: #202124; margin: 0; padding: 20px; }
.header { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; border-bottom: 1px solid #eee; padding-bottom: 15px; }
.logo { color: #4285f4; font-weight: 800; font-size: 24px; text-decoration: none; }
.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;}
.result { margin-bottom: 25px; max-width: 650px; }
.result a { color: #1a0dab; text-decoration: none; font-size: 18px; }
.result a:hover { text-decoration: underline; }
.result p { font-size: 14px; color: #4d5156; margin-top: 5px; line-height: 1.5; }
#loader { color: #70757a; font-style: italic; text-align: center; margin-top: 50px; }
.error { color: #d93025; background: #fce8e6; padding: 15px; border-radius: 8px; display: none; line-height: 1.6; }
</style>
</head>
<body>
<div class="header">
<a href="index.html" class="logo">SurfGO</a>
<input type="text" id="q-input" class="search-box">
</div>
<div id="loader">جاري جلب النتائج...</div>
<div id="error" class="error"></div>
<div id="results-area"></div>
<script>
const PROXY_URL = "https://script.google.com/macros/s/AKfycbyt59U3VKEQf6EVk6xe8S_1UietjUWNgjfZtJJy10fMxnBFPQL6SZY2B0BaAunHwkqF/exec";
const SEARXNG_URL = "https://searxng-anesnt-dev.apps.rm1.0a51.p1.openshiftapps.com/search";
const query = new URLSearchParams(window.location.search).get('q');
if (query) {
document.getElementById('q-input').value = query;
fetchResults(query);
}
async function fetchResults(q) {
const area = document.getElementById('results-area');
const loader = document.getElementById('loader');
const errorDiv = document.getElementById('error');
const targetSearch = `${SEARXNG_URL}?q=${encodeURIComponent(q)}&format=json&language=ar`;
const finalUrl = `${PROXY_URL}?url=${encodeURIComponent(targetSearch)}`;
try {
const response = await fetch(finalUrl);
const text = await response.text();
// فحص إذا كان السيرفر أرجع صفحة ويب بدلاً من البيانات
if (text.trim().startsWith("<")) {
console.error("الرد المستلم ليس JSON:", text);
throw new Error("تعذر جلب البيانات. الرجاء التأكد من أن سيرفر SearXNG على OpenShift قيد التشغيل ولم يتوقف، أو أن جوجل يرفض تمرير الطلب.");
}
const data = JSON.parse(text);
loader.style.display = 'none';
if (!data.results || data.results.length === 0) {
area.innerHTML = "<p>لا توجد نتائج بحث لهذه الكلمة.</p>";
return;
}
area.innerHTML = "";
data.results.forEach(item => {
area.innerHTML += `
<div class="result">
<a href="${item.url}" target="_blank">${item.title}</a>
<p>${item.content || ''}</p>
</div>`;
});
} catch (err) {
loader.style.display = 'none';
errorDiv.style.display = 'block';
errorDiv.innerHTML = `<b>حدث خطأ أثناء الاتصال:</b><br>${err.message}`;
console.error(err);
}
}
document.getElementById('q-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
window.location.href = `results.html?q=${encodeURIComponent(e.target.value)}`;
}
});
</script>
</body>
</html>