[go: nahoru, domu]

انتقل إلى المحتوى

مستخدم:أنون/NumberCopy.js

من ويكيبيديا، الموسوعة الحرة

ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

document.addEventListener('copy', function(event) {
    // Get the selected text
    var selection = window.getSelection().toString();

    // Create a map of Eastern Arabic numerals to Western Arabic numerals
    var easternArabicNumerals = ['١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩', '٠'];
    var westernArabicNumerals = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];

    // Replace Eastern Arabic numerals with Western Arabic numerals
    var convertedText = selection.split('').map(function(char) {
        var index = easternArabicNumerals.indexOf(char);
        return index === -1 ? char : westernArabicNumerals[index];
    }).join('');

    // Create a temporary textarea to hold the converted text
    var tempTextArea = document.createElement('textarea');
    tempTextArea.value = convertedText;
    document.body.appendChild(tempTextArea);
    tempTextArea.select();
    
    // Replace the clipboard content with the converted text
    event.clipboardData.setData('text/plain', tempTextArea.value);
    event.preventDefault();
    
    // Remove the temporary textarea
    document.body.removeChild(tempTextArea);
});