Guest User

iphone_6s_check_disponibility

a guest
Oct 6th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var models = {
  2.                 'MKQJ2QL/A' : 'iPhone 6s 16GB Gris espacial , 749,00 €',
  3.                 'MKQN2QL/A' : 'iPhone 6s 64GB Gris espacial , 859,00 €',
  4.                 'MKQT2QL/A' : 'iPhone 6s 128GB Gris espacial , 969,00 €',
  5.                 'MKQL2QL/A' : 'iPhone 6s 16GB Oro , 749,00 €',
  6.                 'MKQQ2QL/A' : 'iPhone 6s 64GB Oro , 859,00 €',
  7.                 'MKQV2QL/A' : 'iPhone 6s 128GB Oro , 969,00 €',
  8.                 'MKQM2QL/A' : 'iPhone 6s 16GB Oro rosa , 749,00 €',
  9.                 'MKQR2QL/A' : 'iPhone 6s 64GB Oro rosa , 859,00 €',
  10.                 'MKQW2QL/A' : 'iPhone 6s 128GB Oro rosa , 969,00 €',
  11.                 'MKQK2QL/A' : 'iPhone 6s 16GB Plata , 749,00 €',
  12.                 'MKQP2QL/A' : 'iPhone 6s 64GB Plata , 859,00 €',
  13.                 'MKQU2QL/A' : 'iPhone 6s 128GB Plata , 969,00 €',
  14.    
  15.                 'MKU12QL/A' : 'iPhone 6s Plus 16GB Gris espacial , 859,00 €',
  16.                 'MKU62QL/A' : 'iPhone 6s Plus 64GB Gris espacial , 969,00 €',
  17.                 'MKUD2QL/A' : 'iPhone 6s Plus 128GB Gris espacial , 1.079,00 €',
  18.                 'MKU32QL/A' : 'iPhone 6s Plus 16GB Oro , 859,00 €',
  19.                 'MKU82QL/A' : 'iPhone 6s Plus 64GB Oro , 969,00 €',
  20.                 'MKUF2QL/A' : 'iPhone 6s Plus 128GB Oro , 1.079,00 €',
  21.                 'MKU52QL/A' : 'iPhone 6s Plus 16GB Oro rosa , 859,00 €',
  22.                 'MKU92QL/A' : 'iPhone 6s Plus 64GB Oro rosa , 969,00 €',
  23.                 'MKUG2QL/A' : 'iPhone 6s Plus 128GB Oro rosa , 1.079,00 €',
  24.                 'MKU22QL/A' : 'iPhone 6s Plus 16GB Plata , 859,00 €',
  25.                 'MKU72QL/A' : 'iPhone 6s Plus 64GB Plata , 969,00 €',
  26.                 'MKUE2QL/A' : 'iPhone 6s Plus 128GB Plata , 1.079,00 €'
  27.             };
  28.            
  29.             var looper = null;
  30.             var alertme = '';
  31.             function updateInfo(){
  32.                 $.get( "https://reserve.cdn-apple.com/ES/es_ES/reserve/iPhone/stores.json", function( data ) {
  33.                    
  34.                     var stores = {};
  35.                     data.stores.forEach(function(store) {
  36.                         stores[store.storeNumber] = store;
  37.                     });
  38.                    
  39.                     var html = '';
  40.                     $.get( "https://reserve.cdn-apple.com/ES/es_ES/reserve/iPhone/availability.json", function( data ) {
  41.                        
  42.                         html += '<div><input type="radio" id="radiodisp_disp" name="radiodisp" value="disp" checked> Disponible<br><input type="radio" id="radiodisp_nodisp" name="radiodisp" value="nodisp"> No Disponible<br><input type="radio" id="radiodisp_todo" name="radiodisp" value="todo"> Todo</div><div style="font-size: 12px;">';
  43.                         for (var store in data) {
  44.                             if (data.hasOwnProperty(store) && stores.hasOwnProperty(store)) {
  45.                                 html += '<div style="float: left; margin-top: 10px; margin-right: 25px;"><div style="font-weight:bold; font-size: 16px;">'+stores[store].storeName+' - '+stores[store].storeCity+'</div><div style="font-weight:bold;">Horas de reserva a partir de las: <span style="color: #D00;">'+data[store].timeSlot.es_ES.timeslotTime+'h</span> (por contrato: <span style="color: #D00;">'+data[store].timeSlot.es_ES.contractTimeslotTime+'h</span>)</div>';
  46.                                
  47.                                 for (var model in data[store]) {
  48.                                     if (data[store].hasOwnProperty(model) && models.hasOwnProperty(model)) {
  49.                                         if( data[store][model] == 'ALL' ){
  50.                                             html += '<div style="padding-left: 25px;" class="disp"><input type="radio" id="alertme_'+store+'_'+model+'" name="alertme" value="'+store+'_'+model+'" model="'+model+'" store="'+store+'" model_r="'+models[model]+'" store_r="'+stores[store].storeName+' - '+stores[store].storeCity+'" '+( (alertme == 'alertme_'+store+'_'+model) ? 'checked':'' )+'> <span style="font-weight: bold; color: #0F0;" model="'+model+'" store="'+store+'">DISPONIBLE</span> - '+models[model]+'</div>';
  51.                                         }
  52.                                         if( data[store][model] == 'NONE' ){
  53.                                             html += '<div style="padding-left: 25px; display: none;" class="nodisp"><input type="radio" id="alertme_'+store+'_'+model+'" name="alertme" value="'+store+'_'+model+'" model="'+model+'" store="'+store+'" model_r="'+models[model]+'" store_r="'+stores[store].storeName+' - '+stores[store].storeCity+'" '+( (alertme == 'alertme_'+store+'_'+model) ? 'checked':'' )+'> <span style="font-weight: bold; color: #F00;" model="'+model+'" store="'+store+'">NO DISPONIBLE</span> - '+models[model]+'</div>';
  54.                                         }
  55.                                     }
  56.                                 }
  57.                                 html += '</div>';
  58.                             }
  59.                         }
  60.                         html += '</div><div style="clear:both;"></div>';
  61.                        
  62.                         $("#sectionHero .section-content").html('<div>'+html+'</div>');
  63.                        
  64.                         //EXTRAS:
  65.                         $('input[name="radiodisp"][type="radio"]').change(function(){
  66.                             if( $(this).val() == 'disp' ){
  67.                                 $(".disp").show();
  68.                                 $(".nodisp").hide();
  69.                             }else if( $(this).val() == 'nodisp' ){
  70.                                 $(".disp").hide();
  71.                                 $(".nodisp").show();
  72.                             }else{
  73.                                 $(".disp").show();
  74.                                 $(".nodisp").show();
  75.                             }
  76.                         });
  77.                         $('input[name="alertme"][type="radio"]').change(function(){
  78.                             alertme = $(this).prop("id");
  79.                         });
  80.                        
  81.                         //CONTROLLING ALERTME:
  82.                         var id_escapado = "#"+alertme.replace( /(:|\.|\[|\]|,|\/)/g, "\\$1" );
  83.                         var alerted = false;
  84.                         if( alertme && $(id_escapado).parent("div").is('.disp') ){
  85.                             var audioAlert = new Audio('https://sfxcontent.s3.amazonaws.com/soundfx/Submarine-Klaxon.mp3');
  86.                             audioAlert.oncanplaythrough = function() {
  87.                                 clearInterval(looper);
  88.                                
  89.                                 this.currentTime = 0;
  90.                                 this.loop = true;
  91.                                 this.play();
  92.                                
  93.                                 if(!alerted){
  94.                                     alerted = true;
  95.                                    
  96.                                     var md = $(id_escapado).attr("model_r");
  97.                                     var st = $(id_escapado).attr("store_r");
  98.                                     $(window).scrollTop(0);
  99.                                     $("#sectionHero .section-content").html("<div style='background: #D00; padding: 25px; color: #FFF; border-radius: 10px; box-shadow: 0px 10px 12px rgba(0,0,0,.3); text-shadow: 1px 1px rgba(0,0,0,.5);'>El teléfono modelo:<br><br><span style='padding-left: 25px; font-weight:bold; font-size: 25px;'>"+md+"</span><br><br>Se encuentra disponible para su reserva en estos instantes en la store de:<br><br><span style='padding-left: 25px; font-weight:bold; font-size: 25px;'>"+st+"</span></div>");
  100.                                     alert( "El teléfono modelo:\n\n    "+md+"\n\nSe encuentra disponible para su reserva en estos instantes en la store de:\n\n    "+st );
  101.                                 }
  102.                             };
  103.                         }
  104.                        
  105.                     }, "json" );
  106.                    
  107.                 }, "json" );
  108.             }
  109.            
  110.             updateInfo();
  111.             looper = setInterval(updateInfo, 30000); //cada medio minuto.
Advertisement
Add Comment
Please, Sign In to add comment