ulvis.paste.net

Paste Search Dynamic
Recent pastes
TODO
  1. // TODO: Support multiple languages/currency
  2. //       Apply same logic to results page (AJAX call?)
  3. //       Tooltip with price details: add rows for each fee
  4. //       Format the price with number_format() like function
  5.  
  6. // i18n
  7. var keywords_stay = ["séjour", "voyage", "total", "stay"];
  8. var keywords_night = ["nuit", "jour", "night", "day"];
  9.  
  10. var stay_rgx = new RegExp('( ' + keywords_stay.join('| ') + ')', 'ig');
  11. var night_rgx = new RegExp('( ' + keywords_night.join('| ') + ')', 'ig');
  12.  
  13. var prices = $('.bui-price-display__value');
  14.  
  15. prices.each(function() {
  16.     var percentages = [];
  17.     var dollars_per_stay = [];
  18.     var dollars_per_night= [];
  19.  
  20.     $(this).closest('tr').find('.hprt-table-cell-roomtype').length
  21.  
  22.     if($(this).closest('tr').find('.hprt-table-cell-roomtype').length == 0) {
  23.         var prevtr = $(this).closest('tr').prev('tr');
  24.        
  25.         while(prevtr.find('.hprt-table-cell-roomtype').length == 0) {
  26.             prevtr = prevtr.prev('tr');
  27.         }
  28.        
  29.         var nights = parseInt(prevtr.find('.hprt-table-cell-roomtype .hptr-taxinfo-title').text().match(/\d/));
  30.         var taxinfo = prevtr.find('.hprt-table-cell-roomtype .hptr-taxinfo-details:last-child').html();
  31.        
  32.          prevtr.find('.hprt-table-cell-roomtype .hptr-taxinfo-details:last-child').css('color', 'red');
  33.     } else {
  34.         var nights = parseInt($(this).closest('tr').find('.hprt-table-cell-roomtype .hptr-taxinfo-title').text().match(/\d/));
  35.         var taxinfo = $(this).closest('tr').find('.hprt-table-cell-roomtype .hptr-taxinfo-details:last-child').html();
  36.        
  37.         $(this).closest('tr').find('.hprt-table-cell-roomtype .hptr-taxinfo-details:last-child').css('color', 'red');
  38.     }
  39.  
  40.     var fees = taxinfo.replace(/<([^>]+?)([^>]*?)>(.*?)<\/\1>/ig, "").split("\n").join("").split(',');
  41.  
  42.     fees.forEach(function(fee) {
  43.         var trimmed = fee.trim();
  44.         var value = parseFloat(trimmed.split(' ')[0]);
  45.        
  46.         if(trimmed.indexOf('%') !== -1) {
  47.             percentages.push(value);
  48.            
  49.         } else if(trimmed.indexOf('$') !== -1) {
  50.            
  51.             if(trimmed.match(stay_rgx) !== null) {
  52.                 dollars_per_stay.push(value);
  53.                
  54.             } else if(trimmed.match(night_rgx) !== null) {
  55.                 dollars_per_night.push(value);
  56.                
  57.             }
  58.         }
  59.     });
  60.  
  61.     var bs_price = parseFloat($(this).text().split(',').join('.').match(/\d+( \d+|)(\.\d+|)/g)[0].split(' ').join(''));
  62.     var nobs_price = bs_price;
  63.  
  64.     dollars_per_stay.forEach(function(d) {
  65.         nobs_price += d;
  66.     });
  67.    
  68.     dollars_per_night.forEach(function(d) {
  69.         nobs_price += nights * d;
  70.     });
  71.    
  72.     percentages.forEach(function(p) {
  73.         nobs_price *= 1 + p / 100;
  74.     });
  75.  
  76.     $(this).html('<div style="margin-top: 10px; margin-bottom: 10px; color: red; background-color: #efefef; font-size: 19px; border: 1px solid red;\
  77.                              border-radius: 5px; border-style: dashed; text-align: left; padding: 5px; padding-bottom: 3px;">\
  78.                      \
  79.                      <span style="font-size: 12px; font-variant: small-caps; color: black; position: relative; top: -5px;">\
  80.                          [NoBS]\
  81.                      </span> ' + $('input[name=selected_currency]').val() + ' ' + Math.ceil(nobs_price) +
  82.                  '</div>');
  83. });
  84.  
  85. $('.hprt-table-cheapest-block-banner-wrapper, .urgency_message_red').hide();
Parsed in 0.023 seconds