משתמש:מהדורה קמא/בדיקת עוגנים.js: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
מהדורה קמא (שיחה | תרומות) (ניסוי) |
מהדורה קמא (שיחה | תרומות) אין תקציר עריכה |
||
שורה 19: | שורה 19: | ||
var content = textArea.val(); | var content = textArea.val(); | ||
var anchorRegex = /\{\{ | var anchorRegex = /\{\{עוגן1\|([^}]+)\}\}/gi; | ||
var anchors = {}; | var anchors = {}; | ||
// אסוף את כל ההופעות של {{עוגן1|}} ואת הערך שלהן | |||
var match; | var match; | ||
while ((match = anchorRegex.exec(content)) !== null) { | while ((match = anchorRegex.exec(content)) !== null) { | ||
var key = match[ | var key = match[1].toLowerCase().trim(); | ||
if (!anchors[key]) { | if (!anchors[key]) { | ||
anchors[key] = []; | anchors[key] = []; | ||
} | } | ||
// שמירת מיקום | // שמירת מיקום ההופעה | ||
anchors[key].push( | anchors[key].push(match.index); | ||
} | } | ||
$.each(anchors, function (key, positions) { | $.each(anchors, function (key, positions) { | ||
if (positions.length > 1) { | if (positions.length > 1) { | ||
// אם יש יותר מהופעה אחת של אותו ערך | |||
var counter = 1; | var counter = 1; | ||
positins.forEach(function (pos) { | |||
// החלפה של כל הופעה כפולה בתבנית {{עוגן|}} | |||
content = content. | content = content.substring(0, pos) + '{{עוגן|' + key + counter + '|' + key + '}}' + content.substring(pos + match[0].length); | ||
counter++; | counter++; | ||
}); | }); | ||
שורה 43: | שורה 45: | ||
}); | }); | ||
textArea.val(content); | // מעדכן את תיבת הטקסט עם השינויים | ||
textArea.val(content); | |||
alert('הוחלפו עוגנים כפולים בהצלחה'); | alert('הוחלפו עוגנים כפולים בהצלחה'); | ||
}); | }); | ||
}); | }); | ||
}); | }); |
גרסה מ־20:14, 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\|([^}]+)\}\}/gi;
var anchors = {};
// אסוף את כל ההופעות של {{עוגן1|}} ואת הערך שלהן
var match;
while ((match = anchorRegex.exec(content)) !== null) {
var key = match[1].toLowerCase().trim();
if (!anchors[key]) {
anchors[key] = [];
}
// שמירת מיקום ההופעה
anchors[key].push(match.index);
}
$.each(anchors, function (key, positions) {
if (positions.length > 1) {
// אם יש יותר מהופעה אחת של אותו ערך
var counter = 1;
positins.forEach(function (pos) {
// החלפה של כל הופעה כפולה בתבנית {{עוגן|}}
content = content.substring(0, pos) + '{{עוגן|' + key + counter + '|' + key + '}}' + content.substring(pos + match[0].length);
counter++;
});
}
});
// מעדכן את תיבת הטקסט עם השינויים
textArea.val(content);
alert('הוחלפו עוגנים כפולים בהצלחה');
});
});
});