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

פון המכלול
קפיצה לניווט קפיצה לחיפוש
אין תקציר עריכה
צייכן: צוריקגעשטעלט
אין תקציר עריכה
צייכן: צוריקגעשטעלט
שורה 33: שורה 33:
             'במדבר': { english: 'Numbers', alHaTorah: 'Bemidbar' },
             'במדבר': { english: 'Numbers', alHaTorah: 'Bemidbar' },
             'דברים': { english: 'Deuteronomy', alHaTorah: 'Devarim' },
             'דברים': { english: 'Deuteronomy', alHaTorah: 'Devarim' },
            'יהושע': { english: 'Joshua', alHaTorah: 'Yehoshua' },
            'יהושע': { english: 'Joshua', alHaTorah: 'Yehoshua' },
             'שופטים': { english: 'Judges', alHaTorah: 'Shofetim' },
             'שופטים': { english: 'Judges', alHaTorah: 'Shofetim' },
             'שמואל א': { english: 'I_Samuel', alHaTorah: 'Shemuel_I' },
             'שמואל א': { english: 'I_Samuel', alHaTorah: 'Shemuel_I' },
שורה 69: שורה 69:
         };
         };


         // Iterate over each Tanakh citation link
         // Check if there are any .tanach-citation elements
         $('.tanach-citation').each(function () {
         $('.tanach-citation').each(function () {
             var $link = $(this);
             var $link = $(this);
            // Get the data attributes
             var sefer = $link.data('sefer');
             var sefer = $link.data('sefer');
             var perek = $link.data('perek');
             var perek = $link.data('perek');
             var pasuk = $link.data('pasuk');
             var pasuk = $link.data('pasuk');
            // Debugging check for missing data
            console.log('Sefer:', sefer, 'Perek:', perek, 'Pasuk:', pasuk);


             // Ensure the necessary data exists
             // Ensure the necessary data exists
             if (!sefer || !perek || !pasuk) return;
             if (!sefer || !perek || !pasuk) {
                console.log('Missing data attributes, skipping link.');
                return; // Skip if data is missing
            }


             // Map Hebrew book name to Sefaria's naming convention
             // Map Hebrew book name to Sefaria's naming convention
שורה 85: שורה 93:
                 var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(sefariaNames.english) + '.' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);
                 var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(sefariaNames.english) + '.' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);


                 // Map Hebrew book name to AlHaTorah's naming convention
                 // Construct AlHaTorah URL
                var alHaTorahNames = bookNameMapping[sefer];
                var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(sefariaNames.alHaTorah) +
                if (alHaTorahNames) {
                    '/' + encodeURIComponent(perek) +
                    // Construct AlHaTorah URL
                    '.' + encodeURIComponent(pasuk);
                    var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(alHaTorahNames.alHaTorah) +
                        '/' + encodeURIComponent(perek) +
                        '.' + encodeURIComponent(pasuk);


                    // Construct Wikisource URL (Hebrew names and numbers as-is)
                // Construct Wikisource URL
                    var wikiSourceUrl = 'https://he.wikisource.org/wiki/' +
                var wikiSourceUrl = 'https://he.wikisource.org/wiki/' +
                        'קטגוריה:' + encodeURIComponent(sefer + '_' + perek + '_' + pasuk);
                    'קטגוריה:' + encodeURIComponent(sefer + '_' + perek + '_' + pasuk);


                    // Create a button to toggle the visibility of the icons
                // Create a button to toggle the visibility of the icons
                    var button = $('<button>')
                var button = $('<button>')
                        .text('Show Sources')
                    .text('Show Sources')
                        .css({
                    .css({
                            'padding': '5px 10px',
                        'padding': '5px 10px',
                            'background': '#4CAF50',
                        'background': '#4CAF50',
                            'color': 'white',
                        'color': 'white',
                            'border': 'none',
                        'border': 'none',
                            'cursor': 'pointer',
                        'cursor': 'pointer',
                            'border-radius': '5px',
                        'border-radius': '5px',
                            'margin-top': '5px'
                        'margin-top': '5px'
                        });
                    });


                    // Create the icon container (hidden initially)
                // Create the icon container (hidden initially)
                    var iconContainer = $('<div>')
                var iconContainer = $('<div>')
                        .addClass('icon-container')
                    .addClass('icon-container')
                        .css('display', 'none')
                    .css('display', 'none')
                        .append(
                    .append(
                            $('<a>')
                        $('<a>')
                                .attr('href', sefariaUrl)
                            .attr('href', sefariaUrl)
                                .attr('target', '_blank')
                            .attr('target', '_blank')
                                .attr('title', 'עפן אין ספריא')
                            .attr('title', 'עפן אין ספריא')
                                .html('<img src="' + sefariaFavicon + '" alt="Sefaria" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">'),
                            .html('<img src="' + sefariaFavicon + '" alt="Sefaria" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">'),
                            $('<a>')
                        $('<a>')
                                .attr('href', alHaTorahUrl)
                            .attr('href', alHaTorahUrl)
                                .attr('target', '_blank')
                            .attr('target', '_blank')
                                .attr('title', 'עפן אין על התורה')
                            .attr('title', 'עפן אין על התורה')
                                .html('<img src="' + alHaTorahFavicon + '" alt="AlHaTorah" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">'),
                            .html('<img src="' + alHaTorahFavicon + '" alt="AlHaTorah" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">'),
                            $('<a>')
                        $('<a>')
                                .attr('href', wikiSourceUrl)
                            .attr('href', wikiSourceUrl)
                                .attr('target', '_blank')
                            .attr('target', '_blank')
                                .attr('title', 'עפן אין ויקיטקסט')
                            .attr('title', 'עפן אין ויקיטקסט')
                                .html('<img src="' + wikiSourceFavicon + '" alt="Wikisource" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">')
                            .html('<img src="' + wikiSourceFavicon + '" alt="Wikisource" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">')
                        );
                    );


                    // Add button and icon container after the link
                // Add button and icon container after the link
                    $link.after(button).after(iconContainer);
                $link.after(button).after(iconContainer);


                    // Toggle the visibility of the icons when the button is clicked
                // Toggle the visibility of the icons when the button is clicked
                    button.click(function () {
                button.click(function () {
                        iconContainer.toggle();
                    iconContainer.toggle();
                    });
                });
 
            } else {
                    // Optionally, show the icons on hover
                console.log('No matching data for sefer:', sefer);
                    $link.hover(
                        function () { iconContainer.show(); }, // Show icons on hover
                        function () { iconContainer.hide(); }  // Hide icons when not hovering
                    );
                }
             }
             }
         });
         });
     });
     });
});
});

רעוויזיע פון 07:08, 4 אפריל 2025

mw.loader.using(['mediawiki.util', 'jquery'], function () {
    $(document).ready(function () {
        // Define favicon URLs
        var sefariaFavicon = 'https://www.sefaria.org/static/icons/favicon.ico';
        var alHaTorahFavicon = 'https://mg.alhatorah.org/favicon.ico';
        var wikiSourceFavicon = 'https://he.wikisource.org/static/favicon/wikisource.ico';

        // Helper: Convert Hebrew numeral to integer
        function hebrewNumeralToInt(hebrew) {
            const gematria = {
                'א': 1, 'ב': 2, 'ג': 3, 'ד': 4, 'ה': 5,
                'ו': 6, 'ז': 7, 'ח': 8, 'ט': 9,
                'י': 10, 'כ': 20, 'ל': 30, 'מ': 40, 'נ': 50,
                'ס': 60, 'ע': 70, 'פ': 80, 'צ': 90,
                'ק': 100, 'ר': 200, 'ש': 300, 'ת': 400
            };

            // Remove gershayim/geresh
            hebrew = hebrew.replace(/["״׳']/g, '');

            let total = 0;
            for (const letter of hebrew) {
                total += gematria[letter] || 0;
            }
            return total;
        }

        // Define the mapping between Hebrew book names and their English and AlHaTorah equivalents
        const bookNameMapping = {
            'בראשית': { english: 'Genesis', alHaTorah: 'Bereshit' },
            'שמות': { english: 'Exodus', alHaTorah: 'Shemot' },
            'ויקרא': { english: 'Leviticus', alHaTorah: 'Vayikra' },
            'במדבר': { english: 'Numbers', alHaTorah: 'Bemidbar' },
            'דברים': { english: 'Deuteronomy', alHaTorah: 'Devarim' },
             'יהושע': { english: 'Joshua', alHaTorah: 'Yehoshua' },
            'שופטים': { english: 'Judges', alHaTorah: 'Shofetim' },
            'שמואל א': { english: 'I_Samuel', alHaTorah: 'Shemuel_I' },
            'שמואל ב': { english: 'II_Samuel', alHaTorah: 'Shemuel_II' },
            'מלכים א': { english: 'I_Kings', alHaTorah: 'Melakhim_I' },
            'מלכים ב': { english: 'II_Kings', alHaTorah: 'Melakhim_II' },
            'ישעיהו': { english: 'Isaiah', alHaTorah: 'Yeshayahu' },
            'ירמיהו': { english: 'Jeremiah', alHaTorah: 'Yirmeyahu' },
            'יחזקאל': { english: 'Ezekiel', alHaTorah: 'Yechezkel' },
            'הושע': { english: 'Hosea', alHaTorah: 'Hoshea' },
            'יואל': { english: 'Joel', alHaTorah: 'Yoel' },
            'עמוס': { english: 'Amos', alHaTorah: 'Amos' },
            'עובדיה': { english: 'Obadiah', alHaTorah: 'Ovadyah' },
            'יונה': { english: 'Jonah', alHaTorah: 'Yonah' },
            'מיכה': { english: 'Micah', alHaTorah: 'Mikhah' },
            'נחום': { english: 'Nahum', alHaTorah: 'Nachum' },
            'חבקוק': { english: 'Habakkuk', alHaTorah: 'Chavakkuk' },
            'צפניה': { english: 'Zephaniah', alHaTorah: 'Zephanyah' },
            'חגי': { english: 'Haggai', alHaTorah: 'Chaggai' },
            'זכריה': { english: 'Zechariah', alHaTorah: 'Zekharyah' },
            'מלאכי': { english: 'Malachi', alHaTorah: 'Malakhi' },
            'תהילים': { english: 'Psalms', alHaTorah: 'Tehillim' },
            'משלי': { english: 'Proverbs', alHaTorah: 'Mishlei' },
            'איוב': { english: 'Job', alHaTorah: 'Iyyov' },
            'שיר השירים': { english: 'Song_of_Songs', alHaTorah: 'Shir_HaShirim' },
            'רות': { english: 'Ruth', alHaTorah: 'Rut' },
            'איכה': { english: 'Lamentations', alHaTorah: 'Eikhah' },
            'קהלת': { english: 'Ecclesiastes', alHaTorah: 'Kohelet' },
            'אסתר': { english: 'Esther', alHaTorah: 'Esther' },
            'דניאל': { english: 'Daniel', alHaTorah: 'Daniel' },
            'עזרא': { english: 'Ezra', alHaTorah: 'Ezra' },
            'נחמיה': { english: 'Nehemiah', alHaTorah: 'Nechemyah' },
            'דברי הימים א': { english: 'I_Chronicles', alHaTorah: 'Divrei HaYamim_I' },
            'דברי הימים ב': { english: 'II_Chronicles', alHaTorah: 'Divrei HaYamim_II' }
        };

        // Check if there are any .tanach-citation elements
        $('.tanach-citation').each(function () {
            var $link = $(this);

            // Get the data attributes
            var sefer = $link.data('sefer');
            var perek = $link.data('perek');
            var pasuk = $link.data('pasuk');

            // Debugging check for missing data
            console.log('Sefer:', sefer, 'Perek:', perek, 'Pasuk:', pasuk);

            // Ensure the necessary data exists
            if (!sefer || !perek || !pasuk) {
                console.log('Missing data attributes, skipping link.');
                return; // Skip if data is missing
            }

            // Map Hebrew book name to Sefaria's naming convention
            var sefariaNames = bookNameMapping[sefer];
            if (sefariaNames) {
                // Construct Sefaria URL
                var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(sefariaNames.english) + '.' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);

                // Construct AlHaTorah URL
                var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(sefariaNames.alHaTorah) +
                    '/' + encodeURIComponent(perek) +
                    '.' + encodeURIComponent(pasuk);

                // Construct Wikisource URL
                var wikiSourceUrl = 'https://he.wikisource.org/wiki/' +
                    'קטגוריה:' + encodeURIComponent(sefer + '_' + perek + '_' + pasuk);

                // Create a button to toggle the visibility of the icons
                var button = $('<button>')
                    .text('Show Sources')
                    .css({
                        'padding': '5px 10px',
                        'background': '#4CAF50',
                        'color': 'white',
                        'border': 'none',
                        'cursor': 'pointer',
                        'border-radius': '5px',
                        'margin-top': '5px'
                    });

                // Create the icon container (hidden initially)
                var iconContainer = $('<div>')
                    .addClass('icon-container')
                    .css('display', 'none')
                    .append(
                        $('<a>')
                            .attr('href', sefariaUrl)
                            .attr('target', '_blank')
                            .attr('title', 'עפן אין ספריא')
                            .html('<img src="' + sefariaFavicon + '" alt="Sefaria" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">'),
                        $('<a>')
                            .attr('href', alHaTorahUrl)
                            .attr('target', '_blank')
                            .attr('title', 'עפן אין על התורה')
                            .html('<img src="' + alHaTorahFavicon + '" alt="AlHaTorah" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">'),
                        $('<a>')
                            .attr('href', wikiSourceUrl)
                            .attr('target', '_blank')
                            .attr('title', 'עפן אין ויקיטקסט')
                            .html('<img src="' + wikiSourceFavicon + '" alt="Wikisource" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">')
                    );

                // Add button and icon container after the link
                $link.after(button).after(iconContainer);

                // Toggle the visibility of the icons when the button is clicked
                button.click(function () {
                    iconContainer.toggle();
                });
            } else {
                console.log('No matching data for sefer:', sefer);
            }
        });
    });
});