אונטערשייד צווישן ווערסיעס פון "באַניצער:תנא קמא/tanachLinks.js"

קיין רעדאגירונג באמערקונג
אין תקציר עריכה
אין תקציר עריכה
שורה 1: שורה 1:
// Function to convert Tanakh citations to Sefaria links
importScript('באַניצער:צמא_לדעת/צאל-באקוקט.js');
function convertTanakhCitations(wikitext) {
importUserScript(62);
  // Regular expression to match the {{תנ"ך|Sefer|Chapter|Verse}} pattern
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Jon_Harald_Søby/diffedit.js&action=raw&ctype=text/javascript');
  const regex = /{{תנ"ך\|([^|]+)\|([^|]+)\|([^|]+)}}/g;
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Enterprisey/rc-thanks.js&action=raw&ctype=text/javascript');
  return wikitext.replace(regex, function(match, sefer, chapter, verse) {
importScript('באַניצער:עברי אנכי/rc-thanks.js');
     // Construct the Sefaria URL
importScript("באַניצער:גאון הירדן/הודעה למשתמש.js");
    const url = `https://www.sefaria.org/${sefer}.${chapter}.${verse}`;
importScript("באַניצער:צמא לדעת/CommentsInLocalTime.js");
    // Return the HTML link with Sefaria's logo
importScript('באַניצער:צמא לדעת/AM-PM.js');
    return `<a href="${url}" target="_blank"><img src="https://www.sefaria.org/static/img/sefaria_logo.png" alt="Sefaria" style="vertical-align: middle; width: 20px; height: 20px;"/> ${sefer} ${chapter}:${verse}</a>`;
mw.loader.using(['mediawiki.util', 'jquery'], function () {
  });
     $(document).ready(function () {
}
        // Define favicon URLs
        var sefariaFavicon = 'https://www.sefaria.org/static/icons/favicon.ico';
        var shituftaFavicon = 'https://shitufta.org.il/newGigLogo.svg';


// Example usage
        // Find all links that use the תנ"ך template (Shitufta links)
const wikitext = 'Some text {{תנ"ך|Bamidbar|3|4}} more text.';
        $('a[href*="shitufta.org.il"]').each(function () {
const convertedText = convertTanakhCitations(wikitext);
            var $link = $(this);
console.log(convertedText);
            var href = $link.attr('href');
 
            // Extract book and chapter from the Shitufta URL
            var match = href.match(/shitufta\.org\.il\/([^\/]+)\/([^\/]+)/);
            if (match) {
                var book = decodeURIComponent(match[1]);
                var chapter = decodeURIComponent(match[2]);
 
                // Construct Sefaria URL
                var sefariaUrl = 'https://www.sefaria.org/' + book + '.' + chapter;
 
                // Create the Shitufta icon link
                var shituftaIcon = $('<a>')
                    .attr('href', href)
                    .attr('target', '_blank')
                    .attr('title', 'Go to Shitufta')
                    .html('<img src="' + shituftaFavicon + '" alt="Shitufta" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">');
 
                // Create the Sefaria icon link
                var sefariaIcon = $('<a>')
                    .attr('href', sefariaUrl)
                    .attr('target', '_blank')
                    .attr('title', 'Go to Sefaria')
                    .html('<img src="' + sefariaFavicon + '" alt="Sefaria" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">');
 
                // Append icons **next to** the link instead of replacing it
                $link.after(shituftaIcon, sefariaIcon);
            }
        });
    });
});