|
|
| שורה 1: |
שורה 1: |
| (function() { | | $('#pt-watchlist').after( |
| // כתובת API של חב"דפדיה
| | $("<li>", {id: "pt-listscripts"}).append( |
| const API = "https://chabadpedia.co.il/api.php";
| | $('<a>', {accesskey: '3'}) |
| | .click(function(){ |
| | importScript('משתמש:מ. רובין/realy.js'); |
|
| |
|
| // פונקציה לבדיקת האם קיים ערך
| | }) |
| function checkPage(title) {
| | .text(" הפניות") |
| 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();
| |
| })();
| |