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

פון המכלול
קפיצה לניווט קפיצה לחיפוש
(test)
צייכן: צוריקגעשטעלט
ק (הגהה)
 
(23 מיטלסטע ווערסיעס פון 2 באַניצער נישט געוויזן.)
שורה 1: שורה 1:
mw.loader.using(['mediawiki.util', 'jquery'], function () {
mw.loader.using(['mediawiki.util', 'jquery'], function () {
     $(document).ready(function () {
     $(document).ready(function () {
         var sefariaFavicon = 'https://www.sefaria.org/static/icons/favicon.ico';
        // Define favicon URLs
         var sefariaFavicon = 'https://www.sefaria.org/static/icons/library/favicon.svg';
         var alHaTorahFavicon = 'https://mg.alhatorah.org/favicon.ico';
         var alHaTorahFavicon = 'https://mg.alhatorah.org/favicon.ico';
         var mainIcon = 'https://upload.wikimedia.org/wikipedia/commons/e/ec/External_link_icon.png'; // Main popup trigger icon
         var wikiSourceFavicon = 'https://he.wikisource.org/static/favicon/wikisource.ico';


         var bookNameMapping = {
         // Helper: Convert Hebrew numeral to integer
             'Genesis': 'Bereshit', 'Exodus': 'Shemot', 'Leviticus': 'Vayikra', 'Numbers': 'Bemidbar',
        function hebrewNumeralToInt(hebrew) {
            'Deuteronomy': 'Devarim', 'Joshua': 'Yehoshua', 'Judges': 'Shofetim', 'Samuel I': 'Shemuel I',
             const gematria = {
            'Samuel II': 'Shemuel II', 'Kings I': 'Melakhim I', 'Kings II': 'Melakhim II', 'Isaiah': 'Yeshayahu',
                'א': 1, 'ב': 2, 'ג': 3, 'ד': 4, 'ה': 5,
            'Jeremiah': 'Yirmeyahu', 'Ezekiel': 'Yechezkel', 'Hosea': 'Hoshea', 'Joel': 'Yoel', 'Amos': 'Amos',
                'ו': 6, 'ז': 7, 'ח': 8, 'ט': 9,
            'Obadiah': 'Ovadyah', 'Jonah': 'Yonah', 'Micah': 'Mikhah', 'Nahum': 'Nachum', 'Habakkuk': 'Chavakkuk',
                'י': 10, 'כ': 20, 'ל': 30, 'מ': 40, 'נ': 50,
            'Zephaniah': 'Zephanyah', 'Haggai': 'Chaggai', 'Zechariah': 'Zekharyah', 'Malachi': 'Malakhi',
                'ס': 60, 'ע': 70, 'פ': 80, 'צ': 90,
            'Psalms': 'Tehillim', 'Proverbs': 'Mishlei', 'Job': 'Iyyov', 'Song of Songs': 'Shir HaShirim',
                'ק': 100, 'ר': 200, 'ש': 300, 'ת': 400
             'Ruth': 'Rut', 'Lamentations': 'Eikhah', 'Ecclesiastes': 'Kohelet', 'Esther': 'Esther', 'Daniel': 'Daniel',
             };
            'Ezra': 'Ezra', 'Nehemiah': 'Nechemyah', 'Chronicles I': 'Divrei HaYamim I', 'Chronicles II': 'Divrei HaYamim II'
        };


        function createPopup(link, sefariaUrl, alHaTorahUrl) {
            // Remove gershayim/geresh
             var popup = $('<div class="custom-popup">')
             hebrew = hebrew.replace(/["״׳']/g, '');
                .css({
                    position: 'absolute', background: '#fff', border: '1px solid #ccc',
                    padding: '5px', 'border-radius': '5px', 'box-shadow': '0px 2px 5px rgba(0,0,0,0.2)',
                    display: 'none', 'z-index': 1000
                })
                .append(
                    $('<a>').attr({ href: sefariaUrl, target: '_blank', title: 'עפן אין ספריא' })
                        .html('<img src="' + sefariaFavicon + '" style="width:16px; height:16px; margin:3px;">'),
                    $('<a>').attr({ href: alHaTorahUrl, target: '_blank', title: 'עפן אין על התורה' })
                        .html('<img src="' + alHaTorahFavicon + '" style="width:16px; height:16px; margin:3px;">')
                );


             $('body').append(popup);
             let total = 0;
            for (const letter of hebrew) {
                total += gematria[letter] || 0;
            }
            return total;
        }


             return popup;
        // 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' }
         };


        // Iterate over each Tanakh citation link
         $('.tanach-citation').each(function () {
         $('.tanach-citation').each(function () {
             var $link = $(this);
             var $link = $(this);
             var sefer = $link.data('sefer');
             var sefer = $link.data('sefer');
             var perek = $link.data('perek');
             var perekRaw = $link.data('perek');
             var pasuk = $link.data('pasuk');
             var pasukRaw = $link.attr('data-pasuk');
 
            // Ensure the necessary data exists
            if (!sefer || !perekRaw) return;
 
            var seferNames = bookNameMapping[sefer];
            if (!seferNames) return;
 
            var perek = hebrewNumeralToInt(perekRaw);
            var pasuk = (pasukRaw && pasukRaw.trim() !== '') ? hebrewNumeralToInt(pasukRaw) : null;
 
            // Construct Sefaria URL
            var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(seferNames.english) + '.' + perek;
            if (pasuk !== null) {
                sefariaUrl += '.' + pasuk;
            }
 
            // Construct AlHaTorah URL
            var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(seferNames.alHaTorah) + '/' + perek;
            if (pasuk !== null) {
                alHaTorahUrl += '.' + pasuk;
            }


             if (!sefer || !perek || !pasuk) return;
            // Construct Wikisource URL
            var wikiSourceUrl = 'https://he.wikisource.org/wiki/' + encodeURIComponent(sefer + '_' + perekRaw);
             if (pasukRaw && pasukRaw.trim() !== '') {
                wikiSourceUrl += '_' + pasukRaw;
            }


             var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(sefer) + '.' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);
             // Create container span for the icons
             var alHaTorahSefer = bookNameMapping[sefer] || sefer;
             var $container = $('<span class="tanach-icons" style="white-space: nowrap; margin-right: 4px;"></span>');
            var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(alHaTorahSefer) +
                '/' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);


             var popup = createPopup($link, sefariaUrl, alHaTorahUrl);
            // Create and append the Sefaria icon
             var sefariaIcon = $('<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;">');
            $container.append(sefariaIcon);


             var mainIconLink = $('<a>')
            // Create and append the AlHaTorah icon
                 .attr('href', '#')
             var alHaTorahIcon = $('<a>')
                 .attr('title', 'View Links')
                 .attr('href', alHaTorahUrl)
                 .html('<img src="' + mainIcon + '" style="width:14px; height:14px; margin-left:3px;">')
                .attr('target', '_blank')
                .on('click', function (e) {
                 .attr('title', 'עפן אין על התורה')
                    e.preventDefault();
                 .html('<img src="' + alHaTorahFavicon + '" alt="AlHaTorah" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">');
                    var offset = $(this).offset();
            $container.append(alHaTorahIcon);
                    popup.css({ top: offset.top + 20, left: offset.left }).toggle();
                });


             $link.after(mainIconLink);
             // Create and append the Wikisource icon
            var wikiSourceIcon = $('<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;">');
            $container.append(wikiSourceIcon);


             $(document).on('click', function (e) {
            // Insert the container before the original link
                if (!popup.is(e.target) && popup.has(e.target).length === 0 && !mainIconLink.is(e.target)) {
             $link.before($container);
                    popup.hide();
                }
            });
         });
         });
     });
     });
});
});

יעצטיגע רעוויזיע זינט 16:25, 21 יאנואר 2026

mw.loader.using(['mediawiki.util', 'jquery'], function () {
    $(document).ready(function () {
        // Define favicon URLs
        var sefariaFavicon = 'https://www.sefaria.org/static/icons/library/favicon.svg';
        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' }
        };

        // Iterate over each Tanakh citation link
        $('.tanach-citation').each(function () {
            var $link = $(this);
            var sefer = $link.data('sefer');
            var perekRaw = $link.data('perek');
            var pasukRaw = $link.attr('data-pasuk');

            // Ensure the necessary data exists
            if (!sefer || !perekRaw) return;

            var seferNames = bookNameMapping[sefer];
            if (!seferNames) return;

            var perek = hebrewNumeralToInt(perekRaw);
            var pasuk = (pasukRaw && pasukRaw.trim() !== '') ? hebrewNumeralToInt(pasukRaw) : null;

            // Construct Sefaria URL
            var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(seferNames.english) + '.' + perek;
            if (pasuk !== null) {
                sefariaUrl += '.' + pasuk;
            }

            // Construct AlHaTorah URL
            var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(seferNames.alHaTorah) + '/' + perek;
            if (pasuk !== null) {
                alHaTorahUrl += '.' + pasuk;
            }

            // Construct Wikisource URL
            var wikiSourceUrl = 'https://he.wikisource.org/wiki/' + encodeURIComponent(sefer + '_' + perekRaw);
            if (pasukRaw && pasukRaw.trim() !== '') {
                wikiSourceUrl += '_' + pasukRaw;
            }

            // Create container span for the icons
            var $container = $('<span class="tanach-icons" style="white-space: nowrap; margin-right: 4px;"></span>');

            // Create and append the Sefaria icon
            var sefariaIcon = $('<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;">');
            $container.append(sefariaIcon);

            // Create and append the AlHaTorah icon
            var alHaTorahIcon = $('<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;">');
            $container.append(alHaTorahIcon);

            // Create and append the Wikisource icon
            var wikiSourceIcon = $('<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;">');
            $container.append(wikiSourceIcon);

            // Insert the container before the original link
            $link.before($container);
        });
    });
});