משתמש:מהדורה קמא/בדיקת עוגנים.js: הבדלים בין גרסאות בדף

קפיצה לניווט קפיצה לחיפוש
ניסוי
(M)
(ניסוי)
שורה 34: שורה 34:
       $.each(anchors, function (key, positions) {
       $.each(anchors, function (key, positions) {
         if (positions.length > 1) {
         if (positions.length > 1) {
           var offset = 0; // משתנה לשינוי נקודת ההתחלה בהתאם להחלפות שבוצעו
           var counter = 1;
           positions.forEach(function (pos, i) {
           positions.forEach(function (pos, i) {
             var replacement = `{{עוגן|${key}${i + 1}|${key}}}`;
             var replacement = `{{עוגן|${key}${counter}|${key}}}`;
            var startIndex = pos.index + offset; // התחלה מהמיקום המתוקן
             content = content.slice(0, pos.index) + replacement + content.slice(pos.index + pos.length);
             content = content.slice(0, startIndex) + replacement + content.slice(startIndex + pos.length);
             counter++;
             offset += replacement.length - pos.length; // מתקן את ההיסט להחלפות הבאות
           });
           });
          textArea.val(content); // מעדכן את התוכן בתיבת הטקסט
         }
         }
       });
       });


       if ($.isEmptyObject(anchors)) {
       textArea.val(content); // מעדכן את התוכן בתיבת הטקסט
        alert('אין עוגנים כפולים');
       alert('הוחלפו עוגנים כפולים בהצלחה');
       } else {
        alert('הוחלפו עוגנים כפולים בהצלחה');
      }
     });
     });
   });
   });
});
});

תפריט ניווט