Update results.html
Browse files- results.html +46 -42
results.html
CHANGED
|
@@ -3,101 +3,105 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>SurfGO -
|
| 7 |
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
| 9 |
:root { --primary: #4285f4; --bg: #ffffff; --text: #202124; --border: #ebebeb; --link: #1a0dab; }
|
| 10 |
@media (prefers-color-scheme: dark) { :root { --bg: #202124; --text: #bdc1c6; --border: #3c4043; --link: #8ab4f8; } }
|
| 11 |
|
| 12 |
body { font-family: 'Tajawal', sans-serif; background: var(--bg); color: var(--text); margin: 0; }
|
| 13 |
-
header { background: var(--bg); padding:
|
| 14 |
-
.logo
|
| 15 |
-
.
|
| 16 |
|
| 17 |
-
.
|
| 18 |
-
.stats { font-size: 13px; color:
|
| 19 |
-
.
|
| 20 |
-
.
|
| 21 |
-
.
|
| 22 |
-
.
|
| 23 |
-
.
|
| 24 |
-
.
|
| 25 |
|
| 26 |
-
#loader { text-align: center; margin: 50px 0;
|
| 27 |
-
.error { display: none; padding:
|
|
|
|
| 28 |
</style>
|
| 29 |
</head>
|
| 30 |
<body>
|
| 31 |
|
| 32 |
<header>
|
| 33 |
-
<a href="index.html" class="logo
|
| 34 |
-
<input type="text" id="
|
| 35 |
</header>
|
| 36 |
|
| 37 |
-
<div class="
|
| 38 |
<div id="stats" class="stats"></div>
|
| 39 |
-
<div id="loader">جاري
|
| 40 |
<div id="results-list"></div>
|
| 41 |
-
<div id="error
|
| 42 |
</div>
|
| 43 |
|
| 44 |
<script>
|
| 45 |
-
|
| 46 |
-
const
|
|
|
|
| 47 |
|
| 48 |
const params = new URLSearchParams(window.location.search);
|
| 49 |
const query = params.get('q');
|
| 50 |
|
| 51 |
if (query) {
|
| 52 |
-
document.getElementById('
|
| 53 |
-
|
| 54 |
}
|
| 55 |
|
| 56 |
-
async function
|
| 57 |
const list = document.getElementById('results-list');
|
| 58 |
const loader = document.getElementById('loader');
|
| 59 |
-
const
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
const
|
|
|
|
| 63 |
|
| 64 |
try {
|
| 65 |
-
const
|
| 66 |
-
const text = await
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
const data = JSON.parse(text);
|
| 73 |
loader.style.display = 'none';
|
| 74 |
|
| 75 |
if (!data.results || data.results.length === 0) {
|
| 76 |
-
|
| 77 |
return;
|
| 78 |
}
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
data.results.forEach(res => {
|
| 83 |
list.innerHTML += `
|
| 84 |
-
<div class="
|
| 85 |
<cite>${res.url}</cite>
|
| 86 |
<a href="${res.url}" target="_blank"><h3>${res.title}</h3></a>
|
| 87 |
-
<p>${res.content || '
|
| 88 |
-
</div>
|
| 89 |
-
`;
|
| 90 |
});
|
| 91 |
|
| 92 |
-
} catch (
|
| 93 |
loader.style.display = 'none';
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
console.error(err);
|
| 97 |
}
|
| 98 |
}
|
| 99 |
|
| 100 |
-
|
|
|
|
| 101 |
if (e.key === 'Enter') {
|
| 102 |
window.location.href = `results.html?q=${encodeURIComponent(e.target.value)}`;
|
| 103 |
}
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>SurfGO - نتائج البحث</title>
|
| 7 |
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
| 9 |
:root { --primary: #4285f4; --bg: #ffffff; --text: #202124; --border: #ebebeb; --link: #1a0dab; }
|
| 10 |
@media (prefers-color-scheme: dark) { :root { --bg: #202124; --text: #bdc1c6; --border: #3c4043; --link: #8ab4f8; } }
|
| 11 |
|
| 12 |
body { font-family: 'Tajawal', sans-serif; background: var(--bg); color: var(--text); margin: 0; }
|
| 13 |
+
header { background: var(--bg); padding: 12px 5%; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 20px; position: sticky; top: 0; z-index: 100; }
|
| 14 |
+
.logo { font-size: 24px; font-weight: 800; color: var(--primary); text-decoration: none; }
|
| 15 |
+
.search-input { flex-grow: 1; max-width: 600px; padding: 10px 20px; border-radius: 24px; border: 1px solid var(--border); background: var(--bg); color: var(--text); outline: none; font-family: 'Tajawal'; }
|
| 16 |
|
| 17 |
+
.container { max-width: 700px; margin: 20px auto; padding: 0 20px; }
|
| 18 |
+
.stats { font-size: 13px; color: gray; margin-bottom: 20px; }
|
| 19 |
+
.result-item { margin-bottom: 30px; animation: fadeIn 0.3s ease; }
|
| 20 |
+
.result-item cite { font-style: normal; font-size: 13px; color: #70757a; display: block; margin-bottom: 2px; }
|
| 21 |
+
.result-item h3 { margin: 0; font-size: 19px; font-weight: 500; }
|
| 22 |
+
.result-item a { color: var(--link); text-decoration: none; }
|
| 23 |
+
.result-item a:hover { text-decoration: underline; }
|
| 24 |
+
.result-item p { margin: 5px 0 0; font-size: 14px; line-height: 1.5; opacity: 0.9; }
|
| 25 |
|
| 26 |
+
#loader { text-align: center; margin: 50px 0; color: var(--primary); font-weight: bold; }
|
| 27 |
+
.error-msg { display: none; padding: 15px; background: #fff5f5; border: 1px solid #feb2b2; border-radius: 8px; color: #c53030; }
|
| 28 |
+
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
| 29 |
</style>
|
| 30 |
</head>
|
| 31 |
<body>
|
| 32 |
|
| 33 |
<header>
|
| 34 |
+
<a href="index.html" class="logo">SurfGO</a>
|
| 35 |
+
<input type="text" id="top-search" class="search-input">
|
| 36 |
</header>
|
| 37 |
|
| 38 |
+
<div class="container">
|
| 39 |
<div id="stats" class="stats"></div>
|
| 40 |
+
<div id="loader">جاري جلب النتائج من باتنة...</div>
|
| 41 |
<div id="results-list"></div>
|
| 42 |
+
<div id="error" class="error-msg"></div>
|
| 43 |
</div>
|
| 44 |
|
| 45 |
<script>
|
| 46 |
+
// الإعدادات
|
| 47 |
+
const PROXY_URL = "https://script.google.com/macros/s/AKfycbjeBvaYPii1RKJUM62us9AZndZORwS7yWoTKaWddW43FrIwyobcLj5AWO88TR-95ww/exec";
|
| 48 |
+
const API_BASE = "https://searxng-anesnt-dev.apps.rm1.0a51.p1.openshiftapps.com/search";
|
| 49 |
|
| 50 |
const params = new URLSearchParams(window.location.search);
|
| 51 |
const query = params.get('q');
|
| 52 |
|
| 53 |
if (query) {
|
| 54 |
+
document.getElementById('top-search').value = query;
|
| 55 |
+
performSearch(query);
|
| 56 |
}
|
| 57 |
|
| 58 |
+
async function performSearch(q) {
|
| 59 |
const list = document.getElementById('results-list');
|
| 60 |
const loader = document.getElementById('loader');
|
| 61 |
+
const errDiv = document.getElementById('error');
|
| 62 |
+
const stats = document.getElementById('stats');
|
| 63 |
|
| 64 |
+
// بناء الرابط
|
| 65 |
+
const target = `${API_BASE}?q=${encodeURIComponent(q)}&format=json&language=ar`;
|
| 66 |
+
const finalUrl = `${PROXY_URL}?url=${encodeURIComponent(target)}`;
|
| 67 |
|
| 68 |
try {
|
| 69 |
+
const response = await fetch(finalUrl);
|
| 70 |
+
const text = await response.text();
|
| 71 |
|
| 72 |
+
// فحص إذا كان الرد HTML (يعني فشل البروكسي في الصلاحيات)
|
| 73 |
+
if (text.trim().startsWith("<")) {
|
| 74 |
+
throw new Error("تلقى الموقع رد HTML بدلاً من بيانات. يرجى مراجعة إعدادات Anyone في Google Script.");
|
| 75 |
}
|
| 76 |
|
| 77 |
const data = JSON.parse(text);
|
| 78 |
loader.style.display = 'none';
|
| 79 |
|
| 80 |
if (!data.results || data.results.length === 0) {
|
| 81 |
+
stats.innerText = "لم يتم العثور على نتائج لهذه الكلمة.";
|
| 82 |
return;
|
| 83 |
}
|
| 84 |
|
| 85 |
+
stats.innerText = `تم العثور على حوالي ${data.results.length} نتيجة لـ "${q}"`;
|
| 86 |
|
| 87 |
data.results.forEach(res => {
|
| 88 |
list.innerHTML += `
|
| 89 |
+
<div class="result-item">
|
| 90 |
<cite>${res.url}</cite>
|
| 91 |
<a href="${res.url}" target="_blank"><h3>${res.title}</h3></a>
|
| 92 |
+
<p>${res.content || 'وصف غير متوفر.'}</p>
|
| 93 |
+
</div>`;
|
|
|
|
| 94 |
});
|
| 95 |
|
| 96 |
+
} catch (e) {
|
| 97 |
loader.style.display = 'none';
|
| 98 |
+
errDiv.style.display = 'block';
|
| 99 |
+
errDiv.innerHTML = `<b>عذراً! حدث خطأ في الاتصال:</b><br>${e.message}`;
|
|
|
|
| 100 |
}
|
| 101 |
}
|
| 102 |
|
| 103 |
+
// السماح بالبحث بالضغط على Enter
|
| 104 |
+
document.getElementById('top-search').addEventListener('keypress', (e) => {
|
| 105 |
if (e.key === 'Enter') {
|
| 106 |
window.location.href = `results.html?q=${encodeURIComponent(e.target.value)}`;
|
| 107 |
}
|