var ListPage = {
maxTries: 20,
interval: 0,
xhrRequests: [],
update: function(url, count, callback){
var fingerprint = "&t=" + (new Date().getTime());
var reqcount = "&req_count=" + count;
this.loader("on");
var self = this;
var req = new XMLHttpRequest();
req.open("GET", url + fingerprint + reqcount, true);
ListPage.xhrRequests.push(req);
req.onreadystatechange = function() {
if (req.readyState === 4 && (req.status === 200 || req.status === 202)) {
eval(req.responseText);
self.loader("off");
if (req.status === 200 || req.status !== 202 ) callback(req.status);
if (req.status === 202) {
if (count < self.maxTries) {
setTimeout(function(){ListPage.update(url, ++count, callback)}, self.interval);
self.interval += 100;
} else {
callback(req.status);
}
}
}
};
req.send(null);
},
loader: function(status) {
var spinnerD = document.querySelector('.spinnersD');
var spinnerM = document.querySelector('.spinnersM');
if (spinnerD && spinnerM) {
if (status === "on") {
spinnerD.className = "spinnersD shownow";
spinnerM.className = "spinnersM shownow";
} else {
// hide
spinnerD.className = "spinnersD";
spinnerM.className = "spinnersM";
}
}
},
ajax: function(url, callback) {
this.update(url, 1, callback);
}
};
ListPage.ajax("https://www.skyscanner.it/trip/hotels/hotel_list_page?action=nearby&clean_path=tangeri-marocco%2Fhotel%2Framada-encore-tangier&controller=topics&country_code=¤t_user_id=&filters%5BClass%5D%5B%5D=Hotel&id=5000003835655&klass_name=Hotel&list_type=hotels&nearby=true&order=asc&path=tangeri-marocco%2Fhotel%2Framada-encore-tangier%2Fnei-dintorni-hotel&place=5000003835655&place_type=Hotel&place_type=hotel®ion=2000000016243&sort=best_value", function(status){
if (status === 200) {
HotelRates.ajax();
}
});
var HotelRates = {
hotels: "hotel_ids%5B%5D=5000003835655&hotel_ids%5B%5D=5000005911377&hotel_ids%5B%5D=5000000112592&hotel_ids%5B%5D=5000000087122&hotel_ids%5B%5D=5000000108229&hotel_ids%5B%5D=5000000101282&hotel_ids%5B%5D=5000000232575&hotel_ids%5B%5D=5000000258767&hotel_ids%5B%5D=5000000002712&hotel_ids%5B%5D=5000003695464&hotel_ids%5B%5D=5000001244892&hotel_ids%5B%5D=5000000282612&hotel_ids%5B%5D=5000001240086&hotel_ids%5B%5D=5000000397386&hotel_ids%5B%5D=5000000202171&hotel_ids%5B%5D=5000003934280&hotel_ids%5B%5D=5000001244143&hotel_ids%5B%5D=5000000370796&hotel_ids%5B%5D=5000000147481&hotel_ids%5B%5D=5000003962069&hotel_ids%5B%5D=5000000698598&hotel_ids%5B%5D=5000000698599&hotel_ids%5B%5D=5000000068640&hotel_ids%5B%5D=5000000698597&hotel_ids%5B%5D=5000000184925&hotel_ids%5B%5D=5000000321027&hotel_ids%5B%5D=5000000086757&hotel_ids%5B%5D=5000000432170&hotel_ids%5B%5D=5000000195474&hotel_ids%5B%5D=5000000025076",
ajaxCalls: function(tryIndex) {
if (this.hotels) {
ListPage.update("https://www.skyscanner.it/trip/hotels/hotel_rates_list?bookable_only=&country_code=¤t_user_id=&locale=it®ion=2000000016243" + "&" + this.hotels, tryIndex, function(){
var placeholder = document.querySelectorAll('.metasearch_featured .placeholder');
for (var i = 0; i < placeholder.length; i++) {
placeholder[i].style.display='none';
}
});
}
},
ajax: function() {
this.ajaxCalls(1);
},
singleAjax: function() {
this.ajaxCalls(ListPage.maxTries);
}
};