משתמש:רובין בוט/הפניות.js: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
(תיקונים) |
אין תקציר עריכה |
||
| שורה 1: | שורה 1: | ||
(function() { | |||
// כתובת API של חב"דפדיה | |||
const API = "https://chabadpedia.co.il/api.php"; | |||
// פונקציה לבדיקת האם קיים ערך | |||
function checkPage(title) { | |||
return fetch(`${API}?action=query&format=json&titles=${encodeURIComponent(title)}&origin=*`) | |||
.then(res => { | |||
if (!res.ok) throw new Error("Network response was not ok"); | |||
return res.json(); | |||
}) | |||
.then(data => { | |||
const pages = data.query.pages; | |||
const pageId = Object.keys(pages)[0]; | |||
return pageId !== "-1"; // מחזיר true אם הערך קיים | |||
}) | |||
.catch(err => { | |||
console.error("שגיאה בקריאת API:", err); | |||
return false; | |||
}); | |||
} | |||
// פונקציה שמוסיפה כפתור ב־UI | |||
function addButton() { | |||
const btn = document.createElement("button"); | |||
btn.innerText = "בדוק בחב״דפדיה"; | |||
btn.style.margin = "5px"; | |||
btn.onclick = async () => { | |||
const title = prompt("איזה ערך לחפש?"); | |||
if (!title) return; | |||
const exists = await checkPage(title); | |||
if (exists) { | |||
alert(`הערך "${title}" קיים בחב״דפדיה ✅`); | |||
} | } else { | ||
alert(`הערך "${title}" לא נמצא ❌`); | |||
} | |||
}; | |||
document.body.appendChild(btn); | |||
} | |||
// הוספת הכפתור לדף | |||
addButton(); | |||
})(); | |||
גרסה מ־09:47, 18 באוגוסט 2025
(function() {
// כתובת API של חב"דפדיה
const API = "https://chabadpedia.co.il/api.php";
// פונקציה לבדיקת האם קיים ערך
function checkPage(title) {
return fetch(`${API}?action=query&format=json&titles=${encodeURIComponent(title)}&origin=*`)
.then(res => {
if (!res.ok) throw new Error("Network response was not ok");
return res.json();
})
.then(data => {
const pages = data.query.pages;
const pageId = Object.keys(pages)[0];
return pageId !== "-1"; // מחזיר true אם הערך קיים
})
.catch(err => {
console.error("שגיאה בקריאת API:", err);
return false;
});
}
// פונקציה שמוסיפה כפתור ב־UI
function addButton() {
const btn = document.createElement("button");
btn.innerText = "בדוק בחב״דפדיה";
btn.style.margin = "5px";
btn.onclick = async () => {
const title = prompt("איזה ערך לחפש?");
if (!title) return;
const exists = await checkPage(title);
if (exists) {
alert(`הערך "${title}" קיים בחב״דפדיה ✅`);
} else {
alert(`הערך "${title}" לא נמצא ❌`);
}
};
document.body.appendChild(btn);
}
// הוספת הכפתור לדף
addButton();
})();