Add Sefaria Link to Wikisource

Adds a link to Sefaria on Hebrew Wikisource pages

  1. // ==UserScript==
  2. // @name Add Sefaria Link to Wikisource
  3. // @namespace http://torahchats.com/
  4. // @version 1.1
  5. // @description Adds a link to Sefaria on Hebrew Wikisource pages
  6. // @author Binjomin Szanto-Varnagy
  7. // @license MIT
  8. // @match https://he.wikisource.org/wiki/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Dictionary mapping Hebrew book names to Sefaria's English book names
  16. const bookNameMap = {
  17. "בראשית": "Genesis",
  18. "שמות": "Exodus",
  19. "ויקרא": "Leviticus",
  20. "במדבר": "Numbers",
  21. "דברים": "Deuteronomy",
  22. "יהושע": "Joshua",
  23. "שופטים": "Judges",
  24. "שמואל א": "I_Samuel",
  25. "שמואל ב": "II_Samuel",
  26. "מלכים א": "I_Kings",
  27. "מלכים ב": "II_Kings",
  28. "ישעיהו": "Isaiah",
  29. "ירמיהו": "Jeremiah",
  30. "יחזקאל": "Ezekiel",
  31. "הושע": "Hosea",
  32. "יואל": "Joel",
  33. "עמוס": "Amos",
  34. "עובדיה": "Obadiah",
  35. "יונה": "Jonah",
  36. "מיכה": "Micah",
  37. "נחום": "Nahum",
  38. "חבקוק": "Habakkuk",
  39. "צפניה": "Zephaniah",
  40. "חגי": "Haggai",
  41. "זכריה": "Zechariah",
  42. "מלאכי": "Malachi",
  43. "תהלים": "Psalms",
  44. "משלי": "Proverbs",
  45. "איוב": "Job",
  46. "שיר השירים": "Song_of_Songs",
  47. "רות": "Ruth",
  48. "איכה": "Lamentations",
  49. "קהלת": "Ecclesiastes",
  50. "אסתר": "Esther",
  51. "דניאל": "Daniel",
  52. "עזרא": "Ezra",
  53. "נחמיה": "Nehemiah",
  54. "דברי הימים א": "I_Chronicles",
  55. "דברי הימים ב": "II_Chronicles"
  56. };
  57.  
  58. // Step 1: Extract the reference from the URL
  59. const url = decodeURI(window.location.href);
  60. const regex = /קטגוריה:([^_]+)_([^_]+)_([^_]+)/;
  61. const match = url.match(regex);
  62.  
  63. if (match) {
  64. const hebrewBook = match[1].replace(/_/g, " "); // Get Hebrew book name
  65. const chapter = hebrewToNumber(match[2]); // Get chapter number
  66. const verse = hebrewToNumber(match[3]); // Get verse number
  67.  
  68. // Step 2: Translate the Hebrew book name to English using the dictionary
  69. const englishBook = bookNameMap[hebrewBook];
  70. if (englishBook) {
  71. // Step 3: Create the Sefaria URL
  72. const sefariaUrl = `https://www.sefaria.org/${englishBook}.${chapter}.${verse}?lang=bi`;
  73.  
  74. // Step 4: Inject the link to Sefaria at the top of the Wikisource page
  75. const sefariaLink = document.createElement('a');
  76. sefariaLink.href = sefariaUrl;
  77. sefariaLink.innerText = "View this chapter on Sefaria";
  78. sefariaLink.style.display = 'block';
  79. sefariaLink.style.margin = '10px';
  80. sefariaLink.style.fontWeight = 'bold';
  81. sefariaLink.style.color = 'blue';
  82.  
  83. // Step 5: Append the link to the top of the body
  84. document.body.prepend(sefariaLink);
  85. }
  86. }
  87. })();
  88.  
  89. function hebrewToNumber(hebrew) {
  90. // Special cases for 15 (טו) and 16 (טז)
  91. if (hebrew === "טו") return 15;
  92. if (hebrew === "טז") return 16;
  93.  
  94. // Map of Hebrew letters to their corresponding numeric values
  95. const gematriaMap = {
  96. 'א': 1, 'ב': 2, 'ג': 3, 'ד': 4, 'ה': 5, 'ו': 6, 'ז': 7, 'ח': 8, 'ט': 9,
  97. 'י': 10, 'כ': 20, 'ל': 30, 'מ': 40, 'נ': 50, 'ס': 60, 'ע': 70, 'פ': 80, 'צ': 90,
  98. 'ק': 100, 'ר': 200, 'ש': 300, 'ת': 400
  99. };
  100.  
  101. // Convert the Hebrew string into a number
  102. let number = 0;
  103. for (let i = 0; i < hebrew.length; i++) {
  104. const letter = hebrew[i];
  105. if (gematriaMap[letter]) {
  106. number += gematriaMap[letter];
  107. } else {
  108. console.warn(`Unknown Hebrew letter: ${letter}`);
  109. }
  110. }
  111. return number;
  112. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址