var convertImageToText = { convert: function () { $('.DetectText').click(function () { language = document.querySelector('input[name="language"]:checked').value; Item = $(this); Item.css({background: 'blue'}); imageUrl = $(this).attr('data'); index = $(this).attr('index'); imageUrl = 'http://groupfacebook.com/' + imageUrl; // Thay đổi đường dẫn ảnh của bạn tại đây // Sử dụng Fetch API để tải ảnh fetch(imageUrl) .then(response => response.blob()) .then(blob => { const image = new Image(); image.src = URL.createObjectURL(blob); image.onload = function () { // Nhận dạng chữ sử dụng Tesseract.js Tesseract.recognize( image, language, //'eng', // Ngôn ngữ nhận dạng (ở đây là tiếng Anh) { logger: function (info) { $('#uploadDraft').text(JSON.stringify(info)); } } // Cấu hình ).then(({data: {text}}) => { // Hiển thị kết quả Item.css({background: 'yellow'}); text = text.replace('"', "'"); $('#guide' + (index)).val(text); $('#uploadDraft').text(text); $('#resultConvertImageToText').val(text); convertImageToText.copytext() }); }; }) .catch(error => { console.error('Error fetching image:', error); }); }) }, copytext: function () { $('#resultConvertImageToText').select(); document.execCommand('copy'); } }; $(function () { convertImageToText.convert(); })