משתמש:מהדורה קמא/בדיקת עוגנים.js: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
מהדורה קמא (שיחה | תרומות) (M) |
מהדורה קמא (שיחה | תרומות) (ניסוי) |
||
שורה 34: | שורה 34: | ||
$.each(anchors, function (key, positions) { | $.each(anchors, function (key, positions) { | ||
if (positions.length > 1) { | if (positions.length > 1) { | ||
var | var counter = 1; | ||
positions.forEach(function (pos, i) { | positions.forEach(function (pos, i) { | ||
var replacement = `{{עוגן|${key}${ | var replacement = `{{עוגן|${key}${counter}|${key}}}`; | ||
content = content.slice(0, pos.index) + replacement + content.slice(pos.index + pos.length); | |||
content = content.slice(0, | counter++; | ||
}); | }); | ||
} | } | ||
}); | }); | ||
textArea.val(content); // מעדכן את התוכן בתיבת הטקסט | |||
alert('הוחלפו עוגנים כפולים בהצלחה'); | |||
}); | }); | ||
}); | }); | ||
}); | }); |
גרסה מ־19:44, 30 באפריל 2024
// סקריפט לאיתור ותיקון עוגנים כפולים במדיה ויקי
mw.loader.using(['jquery.client'], function () {
$(function () {
// יצירת הכפתור
var button = $('<button type="button">בדוק ותקן עוגנים כפולים</button>');
button.css({
marginTop: '10px',
padding: '5px 10px',
fontSize: '1rem',
cursor: 'pointer'
});
// הוספת הכפתור לדף
$('#editform').prepend(button);
// פעולה שתתבצע עם לחיצה על הכפתור
button.click(function () {
var textArea = $('#wpTextbox1');
var content = textArea.val();
var anchorRegex = /\{\{(עוגן1?|anchor1?)\|([^}]+)\}/gi;
var anchors = {};
var match;
while ((match = anchorRegex.exec(content)) !== null) {
var key = match[2].toLowerCase(); // מנרמל את הערכים להשוואה
if (!anchors[key]) {
anchors[key] = [];
}
// שמירת מיקום ואורך המופע
anchors[key].push({ index: match.index, length: match[0].length });
}
$.each(anchors, function (key, positions) {
if (positions.length > 1) {
var counter = 1;
positions.forEach(function (pos, i) {
var replacement = `{{עוגן|${key}${counter}|${key}}}`;
content = content.slice(0, pos.index) + replacement + content.slice(pos.index + pos.length);
counter++;
});
}
});
textArea.val(content); // מעדכן את התוכן בתיבת הטקסט
alert('הוחלפו עוגנים כפולים בהצלחה');
});
});
});