instagram = { getImageDetailInstagram: function () { // setInterval(function () { // $.ajax({ // type: "get", // url: "/instagram/getImageDetailInstagram", // dataType: "json", // headers: { // 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') // }, // success: function (msg) { // $(location).attr('href', msg.url); // }, // error: function (request, error) { // } // });//End ajax // }, 4000); }, downloadThum: function () { // setInterval(function () { // $.ajax({ // type: "get", // url: "/instagram/downloadThum", // dataType: "json", // headers: { // 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') // }, // success: function (msg) { // $(location).attr('href', msg.url); // }, // error: function (request, error) { // } // });//End ajax // }, 25000); }, /** * sau khi extention lay duoc du lieu cho vao input thi lay du lieu tu input gui vao trong database */ sendListThumeToDatabase: function () { setInterval(function () { value = $('#instagramList').val(); value = $.trim(value); if (value !== '') { $.ajax({ type: "post", url: "/instagram/saveThumeInstagram", dataType: "json", data: {'value': value}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (msg) { $('#instagramList').val(""); console.log(msg); $('#result').html('
Save: '+msg.save+'
Số lượng: '+msg.soLuong); }, error: function (request, error) { } });//End ajax } },1000); }, removeImagesInstagram:function(){ $(document).on('click', '.removeins', function() { // $('.removeAll').click(function(){ data = $(this).attr('data'); $.ajax({ type: "post", url: "/instagram/removeImagesInstagram", dataType: "json", data: {'id': data}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (msg) { console.log(msg); console.log(msg.id); $('.'+data).remove(); }, error: function (request, error) { } });//End ajax }); $(document).on('click', '.removeAll', function() { // $('.removeAll').click(function(){ data = $(this).attr('data'); $.ajax({ type: "post", url: "/instagram/removeImagesInstagram", dataType: "json", data: {'id': data}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (msg) { console.log(msg); console.log(msg.id); $('.'+data).remove(); }, error: function (request, error) { } });//End ajax }); $(document).on('click', '.removetik', function() { // $('.removeAll').click(function(){ data = $(this).attr('data'); $.ajax({ type: "post", url: "/tiktok/removeImagesTiktok", dataType: "json", data: {'id': data}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (msg) { console.log(msg); console.log(msg.id); $('.'+data).remove(); }, error: function (request, error) { } });//End ajax }); }, /* reload instagram */ reload:function(){ $('.reload').click(function(){ data = $(this).attr('data'); $.ajax({ type: "post", url: "/instagram/reload", dataType: "json", data: {'id': data}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (msg) { console.log(msg); console.log(msg.id); $('#'+msg.id).remove(); }, error: function (request, error) { } });//End ajax }); }, removeImagesTiktok:function(){ $('.removeAllTiktok').click(function(){ data = $(this).attr('data'); $.ajax({ type: "post", url: "/tiktok/removeImagesTiktok", dataType: "json", data: {'id': data}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (msg) { $('.'+data).remove(); }, error: function (request, error) { } });//End ajax }); }, getDuplicateAll:function(){ $('.getDupAll').click(function(){ dataId = $(this).attr('data'); $(this).text('Đang tải all'); let button = $(this); $.ajax({ type: "post", url: "/getDuplicateTikInsAll", dataType: "json", data: {'instagramId': dataId}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log(data); button.text('Đã tải xong'); string = ''; $.each(data, function(index, value){ console.log(value); item = "
"+index+"
"; item += "
"; $.each(value, function(index1, value1){ if(dataId != index1){ item += "
"+index1+""; if (value1['imagesDownload']) { item += " "+value1['imagesDownload'].length+"
"; $.each(value1['imagesDownload'], function(index2, value2){ item += ""; }); } if (value1['downloadImage']) { item += " "+value1['downloadImage'].length+"
"; $.each(value1['downloadImage'], function(index2, value2){ item += ""; }); } item += "
"; } }); item += "
"; item += "
"; string += item; }); $('#dup'+dataId).html(string); }, error: function (request, error) { } });//End ajax $.ajax({ type: "post", url: "/checkDuplicateHandmadevAll", dataType: "json", data: {'instagramId': dataId}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log(data); sameLink = ''; $.each(data['link'], function(index, value){ length = 0; if (value['imagestep'] && Array.isArray(value['imagestep'])) { length = value['imagestep'].length + 1; sameLink += '' + value['slug'] + ' '+length+'
'; sameLink += ''; $.each(value['imagestep'], function (key, valueImg) { sameLink += ''; }) sameLink += '
'; } }); $('#dupHandmadev'+dataId).html(sameLink); }, error: function (request, error) { } });//End ajax }); }, getDuplicate:function(){ $('.getDup').click(function(){ dataimage = $(this).attr('dataimage'); dataId = $(this).attr('data'); $.ajax({ type: "post", url: "/getDuplicateTikIns", dataType: "json", data: {'image': dataimage}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log(data); string = ''; $.each(data, function(index, value){ console.log(value); item = "
"+index+"
"; item += "
"; $.each(value, function(index1, value1){ if(dataId != index1){ item += "
"+index1+""; if (value1['imagesDownload']) { item += " "+value1['imagesDownload'].length+"
"; $.each(value1['imagesDownload'], function(index2, value2){ item += ""; }); } if (value1['downloadImage']) { item += " "+value1['downloadImage'].length+"
"; $.each(value1['downloadImage'], function(index2, value2){ item += ""; }); } item += "
"; } }); item += "
"; item += "
"; string += item; }); $('#dup'+dataId).html(string); }, error: function (request, error) { } });//End ajax $.ajax({ type: "post", url: "/checkDuplicateHandmadev", dataType: "json", data: {'image': dataimage}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log(data); sameLink = ''; $.each(data['link'], function(index, value){ length = 0; if (value['imagestep'] && Array.isArray(value['imagestep'])) { length = value['imagestep'].length + 1; sameLink += '' + value['slug'] + ' '+length+'
'; sameLink += ''; $.each(value['imagestep'], function (key, valueImg) { sameLink += ''; }) sameLink += '
'; } }); $('#dupHandmadev'+dataId).html(sameLink); }, error: function (request, error) { } });//End ajax }); }, getLang:function(){ $('.getLang').click(function(){ dataimage = $(this).attr('dataimage'); dataId = $(this).attr('data'); let divGetLanguage = $(this); divGetLanguage.text('Loading...'); $.ajax({ type: "post", url: "/getLanguage", dataType: "json", data: {'dataimage': dataimage,'dataId': dataId}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log(data); console.log(dataId); $('.lang'+dataId).html(data['result']); divGetLanguage.text('Lang'); }, error: function (request, error) { } });//End ajax }); }, saveLang:function(){ $('.langName').change(function(){ dataId = $(this).attr('data-id'); id = $(this).attr('id'); langName = $(this).val(); console.log(dataId); console.log(langName); $('#language'+dataId).val(langName) let labelText = $("label[for='" + id + "']").text(); $('.titleLang' + dataId).attr('datalang', labelText); $.ajax({ type: "post", url: "/instagram/saveLang", dataType: "json", data: {'dataId': dataId, 'langName': langName}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log(data); $('#datalang'+dataId).html(data['result']); }, error: function (request, error) { } });//End ajax }); }, //check trùng từng cái một cho tất cả các td getDuplicateSequential: function(){ const self = this; const tdElements = $('td'); let currentIndex = 0; function processNextTd() { if (currentIndex >= tdElements.length) { console.log('Đã xử lý xong tất cả td'); return; } const currentTd = $(tdElements[currentIndex]); const getDupElement = currentTd.find('.getDup:first'); if (getDupElement.length === 0) { currentIndex++; processNextTd(); return; } const dataimage = getDupElement.attr('dataimage'); const dataId = getDupElement.attr('data'); console.log(`Đang xử lý td ${currentIndex + 1}/${tdElements.length}, dataId: ${dataId}`); // Gọi ajax đầu tiên $.ajax({ type: "post", url: "/getDuplicateTikIns", dataType: "json", data: {'image': dataimage}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log('Ajax 1 completed for:', dataId); // Xử lý kết quả ajax 1 (code cũ của bạn) let string = ''; $.each(data, function(index, value){ let item = "
"+index+"
"; let className = (index == 'ins') ? 'instagramRemoveAll' : 'removeAll'; item += "
"; $.each(value, function(index1, value1){ if(dataId != index1){ item += "
"+index1+""; if (value1['imagesDownload']) { item += " "+value1['imagesDownload'].length+"
"; $.each(value1['imagesDownload'], function(index2, value2){ item += ""; }); } if (value1['downloadImage']) { item += " "+value1['downloadImage'].length+"
"; $.each(value1['downloadImage'], function(index2, value2){ item += ""; }); } item += "
"; } }); item += "
"; string += item; }); $('#dup'+dataId).html(string); // Gọi ajax thứ hai sau khi ajax đầu tiên hoàn thành $.ajax({ type: "post", url: "/checkDuplicateHandmadev", dataType: "json", data: {'image': dataimage}, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (data) { console.log('Ajax 2 completed for:', dataId); console.log(data['link']); // Xử lý kết quả ajax 2 (code cũ của bạn) let sameLink = ''; $.each(data['link'], function(index, value){ console.log(value); let length = 0; if (value['imagestep'] && Array.isArray(value['imagestep'])) { length = value['imagestep'].length + 1; sameLink += '' + value['slug'] + ' '+length+'
'; sameLink += ''; $.each(value['imagestep'], function (key, valueImg) { sameLink += ''; }) sameLink += '
'; }else if(value.imageintro['600']['url']){ // truong hop chi co anh intro sameLink += '' + value['slug'] + '
'; sameLink += ''; sameLink += '
'; } }); console.log(sameLink); $('#dupHandmadev'+dataId).html(sameLink); // Chuyển sang td tiếp theo sau khi hoàn thành cả 2 ajax currentIndex++; setTimeout(processNextTd, 50); // Delay 500ms trước khi xử lý td tiếp theo }, error: function (request, error) { console.error('Ajax 2 failed for:', dataId); currentIndex++; processNextTd(); } }); }, error: function (request, error) { console.error('Ajax 1 failed for:', dataId); currentIndex++; processNextTd(); } }); } // Bắt đầu xử lý từ td đầu tiên processNextTd(); }, gettitle:function(){ $('.gettitle').click(function(){ let button = $(this); button.addClass('loadingBackground'); // Bỏ hiệu ứng loading sau khi hoàn thành button.text('get title'); // Bỏ hiệu ứng loading sau khi hoàn thành let id = $(this).attr('data'); let dataImage = $(this).attr('dataImage'); let datalang = $(this).attr('datalang'); let categoryItem = $('input[name="categoryItem'+id+'"]:checked').val(); $.ajax({ type: "post", url: "/convertImageToText", dataType: "json", data: { image: dataImage, language: datalang, categoryItem: categoryItem, id: id, }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: (datas) => { if (datas.data && datas.data.vietnamese) { $('#vnTitle'+id).text(datas.data.vietnamese); instagram.showToast(datas.data.vietnamese,'success') }else{ $('#vnTitle'+id).text(datas.data.original); instagram.showToast(datas.data.original,'success') } $('#title'+id).val(datas.data.original); $('#uploadButton'+id).click(); }, error: function (response) { console.log(response) uptoOnline.showToast('Error: ' + response.responseJSON.message, 'error'); }, complete: () => { button.removeClass('loadingBackground'); // Bỏ hiệu ứng loading sau khi hoàn thành button.text('title'); // Bỏ hiệu ứng loading sau khi hoàn thành } });//End ajax }) }, maplang:function(lang){ let language = { 'ru':'rus', 'uk':'ukr', 'fr':'fr', 'en':'en', 'es':'es', 'por':'por', 'tr':'tr', 'rus':'rus', 'ira':'ira', 'vi':'vi', } if(language[lang]){ return language[lang] } return lang; }, upload:function(){ $('.upload').click(function(){ uploadButton = $(this) uploadButton.text('đang upload'); id = $(this).attr('data-id'); let content = $('#content'+id).text(); let title = $('#title'+id).val() let language = instagram.maplang($('#language'+id).val()) console.log(language); submitData = []; let data = {'name':'fullTitle','value':title}; submitData.push(data) data = {'name':'title','value':title}; submitData.push(data) data = {'name':'id','value':id}; submitData.push(data) data = {'name':'numberstep','value':1}; submitData.push(data) data = {'name':'time','value':1}; submitData.push(data) data = {'name':'board','value':'6099056be2e29076975b9352'}; submitData.push(data) categoryItem = $('input[name="categoryItem'+id+'"]:checked').val(); data = {'name':'category','value':categoryItem}; submitData.push(data) data = {'name':'language','value':language}; submitData.push(data) data = {'name':'price','value':1}; submitData.push(data) data = {'name':'nguon','value':'https://www.instagram.com'+$('#url'+id).val()}; submitData.push(data) //lay anh dau tien let firstImg = $("td.imglist"+id).first().find("img").first(); firstImg = firstImg.attr("src"); if (!firstImg) { alert('ko tim thay anh dau tien') return; } data = {'name':'fileimageintro','value':firstImg}; submitData.push(data) data = {'name':'intro','value':title}; submitData.push(data) content = $('.content'+id).html(); // Remove tags but keep their content content = content.replace(/]*>(.*?)<\/a>/gi, '$1'); data = {'name':'prepare','value':content}; submitData.push(data) key = 0; $("div.imageList"+id).each(function (){ if(key>0){ url = $(this).find("img").attr('src'); console.log(url) data = {'name':'imagestep[]','value':url}; submitData.push(data) data = {'name':'guide[]','value':title}; submitData.push(data) } key ++; }); console.log(submitData); $.ajax({ type: "post", url: "/savetip", dataType: "json", data: submitData, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: (msg) => { console.log(msg) if (msg[1].indexOf("/") != -1) { console.log(msg[1]); url = '' + 'http://handmadev.com' + msg[1]+''; console.log(url) $('#uploadData'+id).html(url) instagram.showToast('http://handmadev.com' + msg[1],'success',node = 1) } else { $('#saveStatus').html("" + msg[1] + ""); $('#submitcreatectip').html('Lưu hướng dẫn'); instagram.showToast(msg,'error') } uploadButton.text('đã up upload xong'); }, error: function (request, error) { console.error("Lỗi lưu:", error); instagram.showToast(error,'error') }, complete: function () { // Quan trọng: clear flag để tab khác có thể lưu localStorage.setItem("saving", "false"); } }); }) }, showToast:function(msg, type, node = 0) { let typeToast = { success: "linear-gradient(to right, #00b09b, #96c93d)", error: "red", warning: "yellow", }; if(node == 1){ let link = document.createElement("a"); link.href = msg; link.textContent = msg; link.target = "_blank"; // mở tab mới nếu muốn link.style.color = "#fff"; // chỉnh màu nếu cần Toastify({ node: link, // dùng node thay cho text duration: 10000, close: true, gravity: "top", position: "right", stopOnFocus: true, style: { background: typeToast[type], } }).showToast(); }else{ Toastify({ text: msg, duration: 10000, close: true, gravity: "top", // `top` or `bottom` position: "right", // `left`, `center` or `right` stopOnFocus: true, // Prevents dismissing of toast on hover style: { background: typeToast[type], }, onClick: function () { } // Callback after click }).showToast(); } }, }; $(function () { instagram.getImageDetailInstagram(); instagram.downloadThum(); instagram.sendListThumeToDatabase(); instagram.reload(); instagram.removeImagesInstagram(); instagram.removeImagesTiktok(); instagram.getDuplicate(); instagram.getDuplicateAll(); instagram.getLang(); instagram.saveLang(); instagram.getDuplicateSequential(); instagram.gettitle(); instagram.upload(); });