משתמש:רובין בוט/הפניות.js: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
(יצירת דף עם התוכן "mw.loader.using(["jquery.spinner", "mediawiki.diff.styles", "mediawiki.api"]).then(() => { // פונקציה לשליפת הפניות מחב"דפדיה function getAll() { var PageNameLocal = mw.config.get("wgPageName"); var checkParams = { action: "query", format: "json", prop: "linkshere", indexpageids: 1, lhprop: "title", lhshow: "redirect", lhnamespace: "0", lhlimit: "max", titles: dec...") |
(תיקונים) |
||
| שורה 18: | שורה 18: | ||
}; | }; | ||
var apiEndpoint = "https://chabadpedia. | var apiEndpoint = "https://chabadpedia.co.il/api.php"; | ||
$.ajax({ | $.ajax({ | ||
| שורה 41: | שורה 41: | ||
function checkChabadTzitut(oneRedirect) { | function checkChabadTzitut(oneRedirect) { | ||
fetch( | fetch( | ||
"https://zitut.chabadpedia.com | "https://zitut.chabadpedia.com/api.php?action=query&prop=info|revisions&titles=" + | ||
encodeURIComponent(oneRedirect) + | encodeURIComponent(oneRedirect) + | ||
"&indexpageids=true&rvlimit=1&rvprop=size|ids&format=json&origin=*" | "&indexpageids=true&rvlimit=1&rvprop=size|ids&format=json&origin=*" | ||
גרסה מ־09:45, 18 באוגוסט 2025
mw.loader.using(["jquery.spinner", "mediawiki.diff.styles", "mediawiki.api"]).then(() => {
// פונקציה לשליפת הפניות מחב"דפדיה
function getAll() {
var PageNameLocal = mw.config.get("wgPageName");
var checkParams = {
action: "query",
format: "json",
prop: "linkshere",
indexpageids: 1,
lhprop: "title",
lhshow: "redirect",
lhnamespace: "0",
lhlimit: "max",
titles: decodeURIComponent(PageNameLocal),
origin: "*",
};
var apiEndpoint = "https://chabadpedia.co.il/api.php";
$.ajax({
url: apiEndpoint,
data: checkParams,
dataType: "json",
})
.done(function (result) {
if (!result || !result.query) return;
var pages = result.query.pages[result.query.pageids[0]];
if (!pages.linkshere) return;
for (var l of pages.linkshere) {
var oneRedirect = l.title;
checkChabadTzitut(oneRedirect);
}
});
}
// בדיקה אם ההפניה קיימת בציטוט
function checkChabadTzitut(oneRedirect) {
fetch(
"https://zitut.chabadpedia.com/api.php?action=query&prop=info|revisions&titles=" +
encodeURIComponent(oneRedirect) +
"&indexpageids=true&rvlimit=1&rvprop=size|ids&format=json&origin=*"
)
.then((response) => response.json())
.then(function (result) {
if (result && result.query) {
if (result.query.pageids[0] == "-1") {
// לא קיים בציטוט → מייבא
saveChabadTzitut(oneRedirect);
}
}
});
}
// שמירה בציטוט
function saveChabadTzitut(page) {
var apiEndpoint =
"https://chabadpedia.com/w/api.php?action=parse&page=" +
encodeURIComponent(page) +
"&format=json&prop=wikitext&origin=*";
fetch(apiEndpoint)
.then((response) => response.json())
.then(function (result) {
if (result && result.parse) {
var textpage = result.parse.wikitext["*"];
var red = decodeURIComponent(result.parse.title);
if (confirm("ההפניה הבאה קיימת בחב\"דפדיה:\n " + red + "\nלייבא לחב\"דציטוט?")) {
$.post(
"https://zitut.chabadpedia.com/w/api.php",
{
action: "edit",
format: "json",
tags: "ייבוא-הפניות",
bot: 1,
watchlist: "nochange",
recreate: false,
title: result.parse.title,
text: textpage,
token: mw.user.tokens.get("csrfToken"),
},
function (data) {
if (data && data.edit) {
mw.notify("ייבוא ההפניה \"" + decodeURIComponent(data.edit["title"]) + "\" הושלם בהצלחה");
} else {
console.log(data);
}
}
);
}
}
})
.catch((error) =>
mw.notify("אירעה שגיאה בייבוא ההפניה. תיאור השגיאה הוא: " + error)
);
}
// הפעלה
if (
mw.config.get("wgArticleId") > 0 &&
mw.config.get("wgNamespaceNumber") === 0 &&
mw.config.get("wgPageName") != "עמוד_ראשי" &&
mw.config.get("wgAction") === "view" &&
location.href.indexOf("&diff") == -1
) {
getAll();
}
});