|
|
| (2 גרסאות ביניים של משתמש אחר אחד אינן מוצגות) |
| שורה 1: |
שורה 1: |
| mw.loader.using(["jquery.spinner", "mediawiki.diff.styles", "mediawiki.api"]).then(() => {
| | $('#pt-watchlist').after( |
| | $("<li>", {id: "pt-listscripts"}).append( |
| | $('<a>', {accesskey: '3'}) |
| | .click(function(){ |
| | importScript('משתמש:מ. רובין/realy.js'); |
|
| |
|
| // פונקציה לשליפת הפניות מחב"דפדיה
| | }) |
| function getAll() {
| | .text(" הפניות") |
| 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.com/w/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/w/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();
| |
| }
| |
| | |
| });
| |