לדלג לתוכן

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

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית
הסרת כל התוכן מהדף
תגית: ריקון
אין תקציר עריכה
שורה 1: שורה 1:
const style = document.createElement('style');
style.textContent = `
  a.redirect-link { color: red; font-weight: bold; text-decoration: underline; cursor: pointer; }
  #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');
btn.id = 'fixAllRedirectsBtn';
btn.textContent = 'תקן את כל קישורי ההפניה';
document.body.prepend(btn);
function markRedirects() {
  const links = Array.from(document.querySelectorAll('a[href^="/wiki/"], a[href^="https://chabadpedia.co.il/wiki/"]'));
  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) {
          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();

גרסה מ־17:19, 4 בספטמבר 2025

const style = document.createElement('style');
style.textContent = `
  a.redirect-link { color: red; font-weight: bold; text-decoration: underline; cursor: pointer; }
  #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');
btn.id = 'fixAllRedirectsBtn';
btn.textContent = 'תקן את כל קישורי ההפניה';
document.body.prepend(btn);

function markRedirects() {
  const links = Array.from(document.querySelectorAll('a[href^="/wiki/"], a[href^="https://chabadpedia.co.il/wiki/"]'));
  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) {
          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();