לדלג לתוכן

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

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית
מ רובין בוט העביר את הדף משתמש:רובין בוט/הערות שוליים.js לשם משתמש:רובין בוט/ניסוי.js בלי להשאיר הפניה
אין תקציר עריכה
 
(4 גרסאות ביניים של אותו משתמש אינן מוצגות)
שורה 1: שורה 1:
console.log('סקריפט הערות שוליים נטען');
var sidebar = document.createElement('div');
if (
sidebar.id = 'hebrewDateSidebar';
mw.config.get('wgNamespaceNumber') === 0 &&
sidebar.style.cssText = `
($.inArray(mw.config.get('wgAction'), ["edit", "submit"]) + 1)
  position: fixed;
) {
  top: 100px;
$('#wpSave, #btnCheckTool, #wpPreview').on('click', function (e) {
  right: 10px;
var text = $('#wpTextbox1').val();
  width: 150px;
var hiddenSectionInput = $("form#editform>[name=wpSection]");
  background-color: #FFF3E0;
if (
  border: 1px solid #FFA726;
mw.util.getParamValue('section') || // עריכת פסקה בלבד
  padding: 10px;
hiddenSectionInput.length === 0 || // לא ניתן לדעת אם זו פסקה
  font-size: 90%;
hiddenSectionInput.val() || // אכן פסקה
  z-index: 1000;
mw.user.options.get('gadget-wikied') || // בעיה ידועה עם Wikied
`;
/\{\{מיון/.test(text) // תבניות העלולות להכיל <ref> בעצמן
document.body.appendChild(sidebar);
)
return;


var hasRef = /<ref\b|\{\{\s*(msg:|הכללה:|subst::)?\s*(template:|תבנית:)?\s*הערה\s*\|/i.test(text);
function convertHebrewDate(hebrewDate, callback) {
var hasReferences = /<references[^<]*\/>|\{\{\s*(template:|תבנית:)?\s*(הערות[ _]שוליים|reflist)\s*[\}\|]/i.test(text);
    const months = {
 
        'תשרי':1,'חשוון':2,'כסלו':3,'טבת':4,
if (hasRef === hasReferences)
        'שבט':5,'אדר':6,'אדר ב׳':7,'ניסן':8,
return;
        'אייר':9,'סיון':10,'תמוז':11,'אב':12,'אלול':13
 
    };
var warning, doInsert = false;
    const match = hebrewDate.match(/\[\[([^\]]+)\]\]\s*\[\[([^\]]+)\]\]/);
if (hasRef && !hasReferences) {
    if (!match) return;
warning =
    let day = parseInt(match[1].replace(/[^\d]/g,''));
"הדף מכיל הערות שוליים אך חסרה תבנית {{הערות שוליים}}.\n\nהאם תרצו שאוסיף את התבנית אוטומטית לפני הקטגוריות?";
    let month = months[match[2].trim()];
doInsert = true;
    let year = match[2].includes('תש') ? parseInt('5' + match[2].replace(/[^\d]/g,'')) : parseInt(match[2].replace(/[^\d]/g,''));
} else {
    fetch(`https://www.hebcal.com/converter?cfg=json&hy=${year}&hm=${month}&hd=${day}&h2g=1`)
warning = "בדף יש תבנית {{הערות שוליים}} אך לא נמצאו הערות שוליים (ref).";
        .then(resp => resp.json())
}
        .then(data => {
            callback(data.gy + '-' + data.gm + '-' + data.gd);
        });
}


if (this.id === "wpSave") {
convertHebrewDate('[[י"ח חשוון]] [[תשל"א]]', function(gregDate) {
if (!confirm(warning + (doInsert ? "\n\n(ניתן לשנות את המיקום לאחר מכן.)" : ""))) {
    sidebar.textContent = 'תאריך לועזי: ' + gregDate;
e.preventDefault();
});
return;
}
if (doInsert) {
var newText = text;
var footnotes = "\n\n{{הערות שוליים}}";
// לפני הקטגוריות
var catRegex = /\n(\[\[קטגוריה:[^\]]+\]\])/i;
var navRegex = /\n({{תבניות ניווט[^}]*}})/i;
if (catRegex.test(newText)) {
newText = newText.replace(catRegex, footnotes + "\n$1");
} else if (navRegex.test(newText)) {
newText = newText.replace(navRegex, footnotes + "\n$1");
} else {
newText += footnotes;
}
$('#wpTextbox1').val(newText);
}
} else {
alert(warning);
}
});
}

גרסה אחרונה מ־14:01, 5 בספטמבר 2025

var sidebar = document.createElement('div');
sidebar.id = 'hebrewDateSidebar';
sidebar.style.cssText = `
  position: fixed;
  top: 100px;
  right: 10px;
  width: 150px;
  background-color: #FFF3E0;
  border: 1px solid #FFA726;
  padding: 10px;
  font-size: 90%;
  z-index: 1000;
`;
document.body.appendChild(sidebar);

function convertHebrewDate(hebrewDate, callback) {
    const months = {
        'תשרי':1,'חשוון':2,'כסלו':3,'טבת':4,
        'שבט':5,'אדר':6,'אדר ב׳':7,'ניסן':8,
        'אייר':9,'סיון':10,'תמוז':11,'אב':12,'אלול':13
    };
    const match = hebrewDate.match(/\[\[([^\]]+)\]\]\s*\[\[([^\]]+)\]\]/);
    if (!match) return;
    let day = parseInt(match[1].replace(/[^\d]/g,''));
    let month = months[match[2].trim()];
    let year = match[2].includes('תש') ? parseInt('5' + match[2].replace(/[^\d]/g,'')) : parseInt(match[2].replace(/[^\d]/g,''));
    fetch(`https://www.hebcal.com/converter?cfg=json&hy=${year}&hm=${month}&hd=${day}&h2g=1`)
        .then(resp => resp.json())
        .then(data => {
            callback(data.gy + '-' + data.gm + '-' + data.gd);
        });
}

convertHebrewDate('[[י"ח חשוון]] [[תשל"א]]', function(gregDate) {
    sidebar.textContent = 'תאריך לועזי: ' + gregDate;
});