var pageTotal = 1; if ($(".pagination li:nth-last-child(2) a").html() !== undefined) { pageTotal = parseInt($(".pagination li:nth-last-child(2) a").html()); } var url = window.location.href + "?sayfa="; var i; function sleep(delay) { var start = new Date().getTime(); while (new Date().getTime() < start + delay); } function unfollow(productId) { return new Promise(function(resolve, reject) { $.ajax({ type: "POST", url: "https://dolap.com/product/unlike/" + productId, success: function(data) { resolve(data) }, error: function(err) { reject(err) } }); }); $.ajax({ }); } for (i = 1; i <= pageTotal; i++) { $.get( url + i, function(data) { var regex = /<\/i>/gm; var m; while ((m = regex.exec(data)) !== null) { if (m.index === regex.lastIndex) { regex.lastIndex++; } var productId = m[1]; unfollow(productId).then(function(data) { console.log('Takipten çıkıldı.'); sleep(1000); }).catch(function(err) { console.log('Takipten çıkılamadı.'); sleep(1000); }); } } ); sleep(2500); }