Update script.js
Browse files
script.js
CHANGED
|
@@ -1,41 +1,21 @@
|
|
| 1 |
// بيانات الروابط (تم توليدها من ملف Excel)
|
| 2 |
const DATA = [{"name": "أحمد حمود محمد الحربي", "url": "https://stat2025-map.static.hf.space/BCS/59.html"}, {"name": "أروى سعيد بن عبدالله القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/29.html"}, {"name": "أماني مصطفى بن عبدالله الطيب", "url": "https://stat2025-map.static.hf.space/BCS/42.html"}, {"name": "أمل احمد محمد مجرشي", "url": "https://stat2025-map.static.hf.space/BCS/01.html"}, {"name": "أمل بنت علي بن علي السماعيل", "url": "https://stat2025-map.static.hf.space/BCS/50.html"}, {"name": "أمل جعفر بن علي آل حماد", "url": "https://stat2025-map.static.hf.space/BCS/40.html"}, {"name": "أمل صالح بن احمد آل مزعل", "url": "https://stat2025-map.static.hf.space/BCS/06.html"}, {"name": "احلام صالح معيوض العصيمي", "url": "https://stat2025-map.static.hf.space/BCS/43.html"}, {"name": "احمد متعب بن عوض الحربي", "url": "https://stat2025-map.static.hf.space/BCS/56.html"}, {"name": "اسراء محمد بن علي الاصيل", "url": "https://stat2025-map.static.hf.space/BCS/39.html"}, {"name": "اسعد بن ماجد بن احمد الهاشم", "url": "https://stat2025-map.static.hf.space/BCS/37.html"}, {"name": "اسماء بنت محمد بن حسين العدساني", "url": "https://stat2025-map.static.hf.space/BCS/52.html"}, {"name": "الجازي معيض هادي ال دعلان", "url": "https://stat2025-map.static.hf.space/BCS/36.html"}, {"name": "ايمان عبدالعزيز بن صالح الصالح", "url": "https://stat2025-map.static.hf.space/BCS/09.html"}, {"name": "ايمان عبدالعزيز بن صالح الصالح", "url": "https://stat2025-map.static.hf.space/BCS/23.html"}, {"name": "باسمه احمد بن محمد القرني", "url": "https://stat2025-map.static.hf.space/BCS/31.html"}, {"name": "باقر عبدالله بن هاشم الهاشم", "url": "https://stat2025-map.static.hf.space/BCS/47.html"}, {"name": "بخيته عادل احمد الدوسري", "url": "https://stat2025-map.static.hf.space/BCS/12.html"}, {"name": "حسن عادل بن حسين الوصيبعي", "url": "https://stat2025-map.static.hf.space/BCS/48.html"}, {"name": "حسين علي بن صالح الربيعه", "url": "https://stat2025-map.static.hf.space/BCS/19.html"}, {"name": "حنين محمد مبارك آل مبارك", "url": "https://stat2025-map.static.hf.space/BCS/28.html"}, {"name": "روان سعود بن مرشد الرحيلي", "url": "https://stat2025-map.static.hf.space/BCS/45.html"}, {"name": "ريم بنت محمد بن عبدالعزيز الملحم", "url": "https://stat2025-map.static.hf.space/BCS/04.html"}, {"name": "زهراء بنت عايش بن علي الصاهود", "url": "https://stat2025-map.static.hf.space/BCS/13.html"}, {"name": "ساره حسين بن عبدالهادي بوخمسين", "url": "https://stat2025-map.static.hf.space/BCS/18.html"}, {"name": "ساره خالد سليمان المحيسن", "url": "https://stat2025-map.static.hf.space/BCS/20.html"}, {"name": "سراب حميد عبدالمجيد السليمان", "url": "https://stat2025-map.static.hf.space/BCS/25.html"}, {"name": "سلافه عباس محمد العلوي", "url": "https://stat2025-map.static.hf.space/BCS/30.html"}, {"name": "سميه سامى بن احمد النعيم", "url": "https://stat2025-map.static.hf.space/BCS/51.html"}, {"name": "شريفه ابراهيم بن عبدالله العقيل", "url": "https://stat2025-map.static.hf.space/BCS/33.html"}, {"name": "شيماء عبدالرحمن بن دحباش سودي", "url": "https://stat2025-map.static.hf.space/BCS/26.html"}, {"name": "صالح دلي بن عقلاء الشمري", "url": "https://stat2025-map.static.hf.space/BCS/46.html"}, {"name": "طيبه فالح بن عبدالله الرويشد", "url": "https://stat2025-map.static.hf.space/BCS/11.html"}, {"name": "عائشه سليمان بن نايف الحربي", "url": "https://stat2025-map.static.hf.space/BCS/44.html"}, {"name": "عبدالمجيد مشعل محمد الحربي", "url": "https://stat2025-map.static.hf.space/BCS/58.html"}, {"name": "عبدالهادي عون بن سعييد القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/05.html"}, {"name": "عقيله محمدحسين بن علي الجباره", "url": "https://stat2025-map.static.hf.space/BCS/53.html"}, {"name": "غاده سعد بن عبدالرحمن القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/08.html"}, {"name": "غشمه محمد بن سعد الشهراني", "url": "https://stat2025-map.static.hf.space/BCS/14.html"}, {"name": "فايزه محمد مسعود الحازمي", "url": "https://stat2025-map.static.hf.space/BCS/22.html"}, {"name": "فوز عائد نومان المطيري", "url": "https://stat2025-map.static.hf.space/BCS/61.html"}, {"name": "فيصل تركي فيصل القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/34.html"}, {"name": "قنوت محمد بن عبدالله آل حماد", "url": "https://stat2025-map.static.hf.space/BCS/03.html"}, {"name": "لطيفه صالح بن عبدالرحمن العبد القادر", "url": "https://stat2025-map.static.hf.space/BCS/32.html"}, {"name": "لطيفه علي بن حسين النعيم", "url": "https://stat2025-map.static.hf.space/BCS/16.html"}, {"name": "لولوه بدر بن حمد الصياح", "url": "https://stat2025-map.static.hf.space/BCS/21.html"}, {"name": "لين أحمد بن عبدالعزيز القصير", "url": "https://stat2025-map.static.hf.space/BCS/35.html"}, {"name": "محمد فهد محمد الحربي", "url": "https://stat2025-map.static.hf.space/BCS/60.html"}, {"name": "مرتضى عبدالجليل بن عيسى الحكيم", "url": "https://stat2025-map.static.hf.space/BCS/38.html"}, {"name": "مصطفى احمد بن جمعه الرمضان", "url": "https://stat2025-map.static.hf.space/BCS/49.html"}, {"name": "منيره سعد بن احمد الجديدي", "url": "https://stat2025-map.static.hf.space/BCS/54.html"}, {"name": "ناصر عبدالله بن ناصر القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/57.html"}, {"name": "نبأ عادل بن عبدالكريم آل رضوان", "url": "https://stat2025-map.static.hf.space/BCS/15.html"}, {"name": "نجود عبدالعزيز بن عقيل العمري", "url": "https://stat2025-map.static.hf.space/BCS/24.html"}, {"name": "ندى ابراهيم بن علي المنصور", "url": "https://stat2025-map.static.hf.space/BCS/17.html"}, {"name": "نوره عبدالله بن زهير الرزقي", "url": "https://stat2025-map.static.hf.space/BCS/10.html"}, {"name": "نوف سعود بن سالم الخثعمي", "url": "https://stat2025-map.static.hf.space/BCS/02.html"}, {"name": "نوف صالح بن محمد السميح", "url": "https://stat2025-map.static.hf.space/BCS/55.html"}, {"name": "نيللي حسين عبدالله الجعص", "url": "https://stat2025-map.static.hf.space/BCS/27.html"}, {"name": "وضحاء نائف سعد الشريف", "url": "https://stat2025-map.static.hf.space/BCS/07.html"}, {"name": "يحي علي بن يحي المسين", "url": "https://stat2025-map.static.hf.space/BCS/41.html"}];
|
| 3 |
|
| 4 |
-
|
| 5 |
function normalizeArabic(s) {
|
| 6 |
if (!s) return "";
|
| 7 |
return String(s)
|
| 8 |
.trim()
|
| 9 |
.toLowerCase()
|
| 10 |
-
// إزالة التشكيل
|
| 11 |
.replace(/[\u064B-\u065F\u0670\u06D6-\u06ED]/g, "")
|
| 12 |
-
// إزالة التطويل
|
| 13 |
.replace(/\u0640/g, "")
|
| 14 |
-
// توحيد الهمزات
|
| 15 |
.replace(/[إأآٱ]/g, "ا")
|
| 16 |
-
// توحيد الياء والألف المقصورة
|
| 17 |
.replace(/ى/g, "ي")
|
| 18 |
-
// توحيد الهاء/التاء المربوطة (اختياري - يساعد في نتائج أكثر)
|
| 19 |
.replace(/ة/g, "ه")
|
| 20 |
-
|
| 21 |
.replace(/\s+/g, " ");
|
| 22 |
}
|
| 23 |
|
| 24 |
-
function highlightMatch(name, query) {
|
| 25 |
-
// تظليل بسيط بناءً على النص الأصلي (بدون تطبيع كامل لتفادي تعقيد الفهارس)
|
| 26 |
-
if (!query) return escapeHtml(name);
|
| 27 |
-
const q = query.trim();
|
| 28 |
-
if (!q) return escapeHtml(name);
|
| 29 |
-
|
| 30 |
-
// نبحث عن أول ظهور لنفس سلسلة المستخدم في الاسم الأصلي (حرفيًا)
|
| 31 |
-
const idx = name.indexOf(q);
|
| 32 |
-
if (idx === -1) return escapeHtml(name);
|
| 33 |
-
const before = escapeHtml(name.slice(0, idx));
|
| 34 |
-
const mid = escapeHtml(name.slice(idx, idx + q.length));
|
| 35 |
-
const after = escapeHtml(name.slice(idx + q.length));
|
| 36 |
-
return `${before}<mark>${mid}</mark>${after}`;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
function escapeHtml(str) {
|
| 40 |
return String(str)
|
| 41 |
.replaceAll("&", "&")
|
|
@@ -45,65 +25,110 @@ function escapeHtml(str) {
|
|
| 45 |
.replaceAll("'", "'");
|
| 46 |
}
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
const elQ = document.getElementById("q");
|
| 50 |
const elResults = document.getElementById("results");
|
| 51 |
-
const
|
| 52 |
-
const
|
| 53 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
function renderResults(list, rawQuery) {
|
| 56 |
elResults.innerHTML = "";
|
| 57 |
|
| 58 |
if (!list.length) {
|
| 59 |
-
|
| 60 |
-
elResults.innerHTML = `<div class="empty">لا توجد
|
| 61 |
return;
|
| 62 |
}
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
const frag = document.createDocumentFragment();
|
| 67 |
|
| 68 |
list.forEach(item => {
|
| 69 |
-
const
|
| 70 |
-
|
| 71 |
|
| 72 |
-
const left = document.createElement("div");
|
| 73 |
const nm = document.createElement("div");
|
| 74 |
nm.className = "name";
|
| 75 |
nm.innerHTML = highlightMatch(item.name, rawQuery);
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
});
|
| 93 |
|
| 94 |
elResults.appendChild(frag);
|
| 95 |
}
|
| 96 |
|
| 97 |
function doSearch() {
|
| 98 |
-
const raw = elQ.value || "";
|
| 99 |
const q = normalizeArabic(raw);
|
| 100 |
|
| 101 |
if (!q) {
|
| 102 |
-
|
|
|
|
| 103 |
return;
|
| 104 |
}
|
| 105 |
|
| 106 |
-
// يدعم البحث بكلمة أو أكثر (كل الكلمات يجب أن تظهر)
|
| 107 |
const tokens = q.split(" ").filter(Boolean);
|
| 108 |
|
| 109 |
const matched = DATA.filter(d => {
|
|
@@ -111,37 +136,44 @@ function doSearch() {
|
|
| 111 |
return tokens.every(t => nameNorm.includes(t));
|
| 112 |
});
|
| 113 |
|
| 114 |
-
// ترتيب بسيط: الأقرب (أقصر اسم) ثم أبجدي
|
| 115 |
matched.sort((a, b) => {
|
| 116 |
const al = (a.name || "").length;
|
| 117 |
const bl = (b.name || "").length;
|
| 118 |
if (al !== bl) return al - bl;
|
| 119 |
-
return (a.name || "").localeCompare(b.name || "","ar");
|
| 120 |
});
|
| 121 |
|
| 122 |
-
renderResults(matched, raw
|
| 123 |
}
|
| 124 |
|
| 125 |
-
btnSearch.addEventListener("click", doSearch);
|
| 126 |
-
|
| 127 |
-
btnClear.addEventListener("click", () => {
|
| 128 |
elQ.value = "";
|
| 129 |
elQ.focus();
|
| 130 |
elResults.innerHTML = "";
|
| 131 |
-
|
| 132 |
});
|
| 133 |
|
| 134 |
-
// بحث تلقائي أثناء الكتابة (مع تأخير بسيط)
|
| 135 |
let t = null;
|
| 136 |
elQ.addEventListener("input", () => {
|
| 137 |
clearTimeout(t);
|
| 138 |
-
t = setTimeout(doSearch,
|
| 139 |
});
|
| 140 |
|
| 141 |
-
// Enter للبحث
|
| 142 |
elQ.addEventListener("keydown", (e) => {
|
| 143 |
if (e.key === "Enter") doSearch();
|
| 144 |
});
|
| 145 |
|
| 146 |
-
//
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
// بيانات الروابط (تم توليدها من ملف Excel)
|
| 2 |
const DATA = [{"name": "أحمد حمود محمد الحربي", "url": "https://stat2025-map.static.hf.space/BCS/59.html"}, {"name": "أروى سعيد بن عبدالله القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/29.html"}, {"name": "أماني مصطفى بن عبدالله الطيب", "url": "https://stat2025-map.static.hf.space/BCS/42.html"}, {"name": "أمل احمد محمد مجرشي", "url": "https://stat2025-map.static.hf.space/BCS/01.html"}, {"name": "أمل بنت علي بن علي السماعيل", "url": "https://stat2025-map.static.hf.space/BCS/50.html"}, {"name": "أمل جعفر بن علي آل حماد", "url": "https://stat2025-map.static.hf.space/BCS/40.html"}, {"name": "أمل صالح بن احمد آل مزعل", "url": "https://stat2025-map.static.hf.space/BCS/06.html"}, {"name": "احلام صالح معيوض العصيمي", "url": "https://stat2025-map.static.hf.space/BCS/43.html"}, {"name": "احمد متعب بن عوض الحربي", "url": "https://stat2025-map.static.hf.space/BCS/56.html"}, {"name": "اسراء محمد بن علي الاصيل", "url": "https://stat2025-map.static.hf.space/BCS/39.html"}, {"name": "اسعد بن ماجد بن احمد الهاشم", "url": "https://stat2025-map.static.hf.space/BCS/37.html"}, {"name": "اسماء بنت محمد بن حسين العدساني", "url": "https://stat2025-map.static.hf.space/BCS/52.html"}, {"name": "الجازي معيض هادي ال دعلان", "url": "https://stat2025-map.static.hf.space/BCS/36.html"}, {"name": "ايمان عبدالعزيز بن صالح الصالح", "url": "https://stat2025-map.static.hf.space/BCS/09.html"}, {"name": "ايمان عبدالعزيز بن صالح الصالح", "url": "https://stat2025-map.static.hf.space/BCS/23.html"}, {"name": "باسمه احمد بن محمد القرني", "url": "https://stat2025-map.static.hf.space/BCS/31.html"}, {"name": "باقر عبدالله بن هاشم الهاشم", "url": "https://stat2025-map.static.hf.space/BCS/47.html"}, {"name": "بخيته عادل احمد الدوسري", "url": "https://stat2025-map.static.hf.space/BCS/12.html"}, {"name": "حسن عادل بن حسين الوصيبعي", "url": "https://stat2025-map.static.hf.space/BCS/48.html"}, {"name": "حسين علي بن صالح الربيعه", "url": "https://stat2025-map.static.hf.space/BCS/19.html"}, {"name": "حنين محمد مبارك آل مبارك", "url": "https://stat2025-map.static.hf.space/BCS/28.html"}, {"name": "روان سعود بن مرشد الرحيلي", "url": "https://stat2025-map.static.hf.space/BCS/45.html"}, {"name": "ريم بنت محمد بن عبدالعزيز الملحم", "url": "https://stat2025-map.static.hf.space/BCS/04.html"}, {"name": "زهراء بنت عايش بن علي الصاهود", "url": "https://stat2025-map.static.hf.space/BCS/13.html"}, {"name": "ساره حسين بن عبدالهادي بوخمسين", "url": "https://stat2025-map.static.hf.space/BCS/18.html"}, {"name": "ساره خالد سليمان المحيسن", "url": "https://stat2025-map.static.hf.space/BCS/20.html"}, {"name": "سراب حميد عبدالمجيد السليمان", "url": "https://stat2025-map.static.hf.space/BCS/25.html"}, {"name": "سلافه عباس محمد العلوي", "url": "https://stat2025-map.static.hf.space/BCS/30.html"}, {"name": "سميه سامى بن احمد النعيم", "url": "https://stat2025-map.static.hf.space/BCS/51.html"}, {"name": "شريفه ابراهيم بن عبدالله العقيل", "url": "https://stat2025-map.static.hf.space/BCS/33.html"}, {"name": "شيماء عبدالرحمن بن دحباش سودي", "url": "https://stat2025-map.static.hf.space/BCS/26.html"}, {"name": "صالح دلي بن عقلاء الشمري", "url": "https://stat2025-map.static.hf.space/BCS/46.html"}, {"name": "طيبه فالح بن عبدالله الرويشد", "url": "https://stat2025-map.static.hf.space/BCS/11.html"}, {"name": "عائشه سليمان بن نايف الحربي", "url": "https://stat2025-map.static.hf.space/BCS/44.html"}, {"name": "عبدالمجيد مشعل محمد الحربي", "url": "https://stat2025-map.static.hf.space/BCS/58.html"}, {"name": "عبدالهادي عون بن سعييد القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/05.html"}, {"name": "عقيله محمدحسين بن علي الجباره", "url": "https://stat2025-map.static.hf.space/BCS/53.html"}, {"name": "غاده سعد بن عبدالرحمن القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/08.html"}, {"name": "غشمه محمد بن سعد الشهراني", "url": "https://stat2025-map.static.hf.space/BCS/14.html"}, {"name": "فايزه محمد مسعود الحازمي", "url": "https://stat2025-map.static.hf.space/BCS/22.html"}, {"name": "فوز عائد نومان المطيري", "url": "https://stat2025-map.static.hf.space/BCS/61.html"}, {"name": "فيصل تركي فيصل القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/34.html"}, {"name": "قنوت محمد بن عبدالله آل حماد", "url": "https://stat2025-map.static.hf.space/BCS/03.html"}, {"name": "لطيفه صالح بن عبدالرحمن العبد القادر", "url": "https://stat2025-map.static.hf.space/BCS/32.html"}, {"name": "لطيفه علي بن حسين النعيم", "url": "https://stat2025-map.static.hf.space/BCS/16.html"}, {"name": "لولوه بدر بن حمد الصياح", "url": "https://stat2025-map.static.hf.space/BCS/21.html"}, {"name": "لين أحمد بن عبدالعزيز القصير", "url": "https://stat2025-map.static.hf.space/BCS/35.html"}, {"name": "محمد فهد محمد الحربي", "url": "https://stat2025-map.static.hf.space/BCS/60.html"}, {"name": "مرتضى عبدالجليل بن عيسى الحكيم", "url": "https://stat2025-map.static.hf.space/BCS/38.html"}, {"name": "مصطفى احمد بن جمعه الرمضان", "url": "https://stat2025-map.static.hf.space/BCS/49.html"}, {"name": "منيره سعد بن احمد الجديدي", "url": "https://stat2025-map.static.hf.space/BCS/54.html"}, {"name": "ناصر عبدالله بن ناصر القحطاني", "url": "https://stat2025-map.static.hf.space/BCS/57.html"}, {"name": "نبأ عادل بن عبدالكريم آل رضوان", "url": "https://stat2025-map.static.hf.space/BCS/15.html"}, {"name": "نجود عبدالعزيز بن عقيل العمري", "url": "https://stat2025-map.static.hf.space/BCS/24.html"}, {"name": "ندى ابراهيم بن علي المنصور", "url": "https://stat2025-map.static.hf.space/BCS/17.html"}, {"name": "نوره عبدالله بن زهير الرزقي", "url": "https://stat2025-map.static.hf.space/BCS/10.html"}, {"name": "نوف سعود بن سالم الخثعمي", "url": "https://stat2025-map.static.hf.space/BCS/02.html"}, {"name": "نوف صالح بن محمد السميح", "url": "https://stat2025-map.static.hf.space/BCS/55.html"}, {"name": "نيللي حسين عبدالله الجعص", "url": "https://stat2025-map.static.hf.space/BCS/27.html"}, {"name": "وضحاء نائف سعد الشريف", "url": "https://stat2025-map.static.hf.space/BCS/07.html"}, {"name": "يحي علي بن يحي المسين", "url": "https://stat2025-map.static.hf.space/BCS/41.html"}];
|
| 3 |
|
| 4 |
+
|
| 5 |
function normalizeArabic(s) {
|
| 6 |
if (!s) return "";
|
| 7 |
return String(s)
|
| 8 |
.trim()
|
| 9 |
.toLowerCase()
|
|
|
|
| 10 |
.replace(/[\u064B-\u065F\u0670\u06D6-\u06ED]/g, "")
|
|
|
|
| 11 |
.replace(/\u0640/g, "")
|
|
|
|
| 12 |
.replace(/[إأآٱ]/g, "ا")
|
|
|
|
| 13 |
.replace(/ى/g, "ي")
|
|
|
|
| 14 |
.replace(/ة/g, "ه")
|
| 15 |
+
.replace(/^ال\s+/g, "")
|
| 16 |
.replace(/\s+/g, " ");
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
function escapeHtml(str) {
|
| 20 |
return String(str)
|
| 21 |
.replaceAll("&", "&")
|
|
|
|
| 25 |
.replaceAll("'", "'");
|
| 26 |
}
|
| 27 |
|
| 28 |
+
function highlightMatch(name, rawQuery) {
|
| 29 |
+
if (!rawQuery) return escapeHtml(name);
|
| 30 |
+
const tokens = rawQuery.trim().split(/\s+/).filter(Boolean);
|
| 31 |
+
if (!tokens.length) return escapeHtml(name);
|
| 32 |
+
|
| 33 |
+
const t = tokens[0];
|
| 34 |
+
const idx = name.indexOf(t);
|
| 35 |
+
if (idx === -1) return escapeHtml(name);
|
| 36 |
+
|
| 37 |
+
const before = escapeHtml(name.slice(0, idx));
|
| 38 |
+
const mid = escapeHtml(name.slice(idx, idx + t.length));
|
| 39 |
+
const after = escapeHtml(name.slice(idx + t.length));
|
| 40 |
+
return `${before}<mark>${mid}</mark>${after}`;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
const elQ = document.getElementById("q");
|
| 44 |
const elResults = document.getElementById("results");
|
| 45 |
+
const elCount = document.getElementById("countPill");
|
| 46 |
+
const elTotal = document.getElementById("totalChip");
|
| 47 |
+
const toast = document.getElementById("toast");
|
| 48 |
+
const toastText = document.getElementById("toastText");
|
| 49 |
+
|
| 50 |
+
elTotal.innerHTML = `إجمالي: <b>${DATA.length}</b>`;
|
| 51 |
+
|
| 52 |
+
function showToast(msg = "تم نسخ الرابط") {
|
| 53 |
+
toastText.textContent = msg;
|
| 54 |
+
toast.classList.add("show");
|
| 55 |
+
clearTimeout(window.__toastT);
|
| 56 |
+
window.__toastT = setTimeout(() => toast.classList.remove("show"), 1200);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
async function copyLink(url) {
|
| 60 |
+
try {
|
| 61 |
+
await navigator.clipboard.writeText(url);
|
| 62 |
+
showToast();
|
| 63 |
+
} catch (e) {
|
| 64 |
+
const ta = document.createElement("textarea");
|
| 65 |
+
ta.value = url;
|
| 66 |
+
document.body.appendChild(ta);
|
| 67 |
+
ta.select();
|
| 68 |
+
document.execCommand("copy");
|
| 69 |
+
document.body.removeChild(ta);
|
| 70 |
+
showToast();
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
|
| 74 |
function renderResults(list, rawQuery) {
|
| 75 |
elResults.innerHTML = "";
|
| 76 |
|
| 77 |
if (!list.length) {
|
| 78 |
+
elCount.textContent = "النتائج: 0";
|
| 79 |
+
elResults.innerHTML = `<div class="empty">لا توجد نتائج</div>`;
|
| 80 |
return;
|
| 81 |
}
|
| 82 |
|
| 83 |
+
elCount.textContent = `النتائج: ${list.length}`;
|
|
|
|
| 84 |
const frag = document.createDocumentFragment();
|
| 85 |
|
| 86 |
list.forEach(item => {
|
| 87 |
+
const row = document.createElement("div");
|
| 88 |
+
row.className = "result";
|
| 89 |
|
|
|
|
| 90 |
const nm = document.createElement("div");
|
| 91 |
nm.className = "name";
|
| 92 |
nm.innerHTML = highlightMatch(item.name, rawQuery);
|
| 93 |
+
|
| 94 |
+
const actions = document.createElement("div");
|
| 95 |
+
actions.className = "actions";
|
| 96 |
+
|
| 97 |
+
const open = document.createElement("a");
|
| 98 |
+
open.className = "openBtn";
|
| 99 |
+
open.href = item.url;
|
| 100 |
+
open.target = "_blank";
|
| 101 |
+
open.rel = "noopener";
|
| 102 |
+
open.innerHTML = `فتح <span aria-hidden="true">↗</span>`;
|
| 103 |
+
|
| 104 |
+
const copy = document.createElement("button");
|
| 105 |
+
copy.className = "copyBtn";
|
| 106 |
+
copy.type = "button";
|
| 107 |
+
copy.innerHTML = `نسخ <span aria-hidden="true">⧉</span>`;
|
| 108 |
+
copy.addEventListener("click", () => copyLink(item.url));
|
| 109 |
+
|
| 110 |
+
actions.appendChild(open);
|
| 111 |
+
actions.appendChild(copy);
|
| 112 |
+
|
| 113 |
+
row.appendChild(nm);
|
| 114 |
+
row.appendChild(actions);
|
| 115 |
+
|
| 116 |
+
frag.appendChild(row);
|
| 117 |
});
|
| 118 |
|
| 119 |
elResults.appendChild(frag);
|
| 120 |
}
|
| 121 |
|
| 122 |
function doSearch() {
|
| 123 |
+
const raw = (elQ.value || "").trim();
|
| 124 |
const q = normalizeArabic(raw);
|
| 125 |
|
| 126 |
if (!q) {
|
| 127 |
+
elCount.textContent = "النتائج: 0";
|
| 128 |
+
elResults.innerHTML = "";
|
| 129 |
return;
|
| 130 |
}
|
| 131 |
|
|
|
|
| 132 |
const tokens = q.split(" ").filter(Boolean);
|
| 133 |
|
| 134 |
const matched = DATA.filter(d => {
|
|
|
|
| 136 |
return tokens.every(t => nameNorm.includes(t));
|
| 137 |
});
|
| 138 |
|
|
|
|
| 139 |
matched.sort((a, b) => {
|
| 140 |
const al = (a.name || "").length;
|
| 141 |
const bl = (b.name || "").length;
|
| 142 |
if (al !== bl) return al - bl;
|
| 143 |
+
return (a.name || "").localeCompare(b.name || "", "ar");
|
| 144 |
});
|
| 145 |
|
| 146 |
+
renderResults(matched, raw);
|
| 147 |
}
|
| 148 |
|
| 149 |
+
document.getElementById("btnSearch").addEventListener("click", doSearch);
|
| 150 |
+
document.getElementById("btnClear").addEventListener("click", () => {
|
|
|
|
| 151 |
elQ.value = "";
|
| 152 |
elQ.focus();
|
| 153 |
elResults.innerHTML = "";
|
| 154 |
+
elCount.textContent = "النتائج: 0";
|
| 155 |
});
|
| 156 |
|
|
|
|
| 157 |
let t = null;
|
| 158 |
elQ.addEventListener("input", () => {
|
| 159 |
clearTimeout(t);
|
| 160 |
+
t = setTimeout(doSearch, 140);
|
| 161 |
});
|
| 162 |
|
|
|
|
| 163 |
elQ.addEventListener("keydown", (e) => {
|
| 164 |
if (e.key === "Enter") doSearch();
|
| 165 |
});
|
| 166 |
|
| 167 |
+
// Persist last query (invisible)
|
| 168 |
+
try {
|
| 169 |
+
const last = localStorage.getItem("maps_last_query");
|
| 170 |
+
if (last) {
|
| 171 |
+
elQ.value = last;
|
| 172 |
+
doSearch();
|
| 173 |
+
}
|
| 174 |
+
elQ.addEventListener("input", () => {
|
| 175 |
+
localStorage.setItem("maps_last_query", elQ.value || "");
|
| 176 |
+
});
|
| 177 |
+
} catch(_){}
|
| 178 |
+
|
| 179 |
+
elCount.textContent = "النتائج: 0";
|