לדלג לתוכן

משתמש:רובין בוט/ניסוי.js: הבדלים בין גרסאות בדף

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית
אין תקציר עריכה
אין תקציר עריכה
שורה 1: שורה 1:
const style = document.createElement('style');
mw.loader.using('mediawiki.util', function () {
style.textContent = `
   $(function () {
  a.redirect-link { color: red; font-weight: bold; text-decoration: underline; cursor: pointer; }
    mw.util.addPortletLink('p-tb', '#', 'המר תאריך', 'convert-date-link');
   #fixAllRedirectsBtn { margin: 10px 0; padding: 4px 10px; font-size: 0.9em; background-color: #4CAF50; color: white; border: none; cursor: pointer; }
`;
document.head.appendChild(style);


const btn = document.createElement('button');
    $('#convert-date-link').on('click', function (e) {
btn.id = 'fixAllRedirectsBtn';
      e.preventDefault();
btn.textContent = 'תקן את כל קישורי ההפניה';
      const d = prompt('הכנס תאריך עברי (dd/mm/yyyy)');
document.body.prepend(btn);
      if (!d) return;
 
      fetch(`https://www.hebcal.com/converter?cfg=json&gy=0&hm=0&gd=0&gy=0&h2g=1&date=${d}`)
function markRedirects() {
        .then(r => r.json())
  const links = Array.from(document.querySelectorAll('a[href^="/wiki/"], a[href^="https://chabadpedia.co.il/wiki/"]'));
        .then(data => {
  links.forEach(link => {
           alert('תאריך לועזי: ' + data.gy + '-' + data.gm + '-' + data.gd);
    const title = link.getAttribute('href').split('/wiki/')[1];
         })
    fetch(`https://chabadpedia.co.il/api.php?action=query&titles=${encodeURIComponent(title)}&format=json&redirects&prop=info`)
        .catch(err => {
      .then(resp => resp.json())
          alert('שגיאה: ' + err);
      .then(data => {
        });
        const page = Object.values(data.query.pages)[0];
    });
        if (page && page.redirect !== undefined) {
          link.classList.add('redirect-link');
          link.title = 'זה קישור הפניה. לחץ על הכפתור למטה כדי לתקן.';
        }
      })
      .catch(err => console.log(err));
  });
}
 
btn.addEventListener('click', function() {
  const links = Array.from(document.querySelectorAll('a.redirect-link'));
  links.forEach(link => {
    const title = link.getAttribute('href').split('/wiki/')[1];
    fetch(`https://chabadpedia.co.il/api.php?action=query&titles=${encodeURIComponent(title)}&format=json&redirects&prop=info`)
      .then(resp => resp.json())
      .then(data => {
        const page = Object.values(data.query.pages)[0];
        if (page && page.redirect !== undefined && page.title) {
           link.setAttribute('href', '/wiki/' + encodeURIComponent(page.title));
          link.style.color = 'green';
          link.style.fontWeight = 'normal';
          link.classList.remove('redirect-link');
          link.title = 'קישור תוקן בהצלחה!';
         }
      })
      .catch(err => console.log(err));
   });
   });
  alert("כל הקישורים תוקנו!");
});
});
markRedirects();

גרסה מ־13:52, 5 בספטמבר 2025

mw.loader.using('mediawiki.util', function () {
  $(function () {
    mw.util.addPortletLink('p-tb', '#', 'המר תאריך', 'convert-date-link');

    $('#convert-date-link').on('click', function (e) {
      e.preventDefault();
      const d = prompt('הכנס תאריך עברי (dd/mm/yyyy)');
      if (!d) return;
      fetch(`https://www.hebcal.com/converter?cfg=json&gy=0&hm=0&gd=0&gy=0&h2g=1&date=${d}`)
        .then(r => r.json())
        .then(data => {
          alert('תאריך לועזי: ' + data.gy + '-' + data.gm + '-' + data.gd);
        })
        .catch(err => {
          alert('שגיאה: ' + err);
        });
    });
  });
});