Files
Mimante/Mimante/Examples/Pensofal Biostone Tegamino - Bidoo_files/buynow.js.download
T
Alby96 ee67bedc31 Aggiunta calcolo valore prodotto e miglioramenti UI
Implementato il calcolo del valore reale dei prodotti in asta,
includendo il prezzo "Compra Subito", spese di spedizione e
risparmio stimato. Aggiunta una nuova sezione "Info Prodotto"
nella UI per visualizzare i dettagli estratti e i calcoli.

- **AuctionMonitorControl.xaml**: Aggiunta sezione fissa per
  mostrare informazioni prodotto e calcolo valore.
- **AuctionMonitorControl.xaml.cs**: Gestiti eventi per il
  caricamento e aggiornamento delle informazioni prodotto.
- **MainWindow**: Integrati handler per il calcolo e refresh
  delle informazioni prodotto.
- **AuctionInfo.cs**: Aggiunte proprietà per gestire prezzo
  "Compra Subito", spese di spedizione e limiti di vincita.
- **ProductValueCalculator.cs**: Nuova utility per calcolare
  il valore del prodotto e parsare informazioni dall'HTML.
- **AuctionViewModel.cs**: Binding per visualizzare risparmio,
  costo totale e convenienza nella UI.
- **Documentazione**: Aggiornata con dettagli sull'algoritmo
  di calcolo e layout UI.

Fix:
- Risolto problema di encoding UTF-8 per emoji nella UI.
- Migliorato parsing HTML per prezzi e limiti di vincita.

TODO:
- Testare parsing su più aste e gestire edge cases.
- Implementare caricamento automatico delle informazioni.
2025-11-21 16:55:21 +01:00

141 lines
4.0 KiB
Plaintext

var BUYNOW_COUNTDOWN = null;
var BUYNOW_ERRORS = {
already_used: 'Hai usato l’opzione Compralo in quest’asta',
already_won: 'Hai vinto questa Asta.<br>Non puoi usare l&rsquo;opzione Compralo'
};
window.serverTime = () => {
//vado a prendere il valore dalla pagina, precedentemente messo in php
if($('.buynow-countdown-container .product-buynow-countdown').hasClass('time-server')){
return parseInt($('.time-server').attr('data-time-server')) != "NaN" ? parseInt($('.time-server').attr('data-time-server')) : null ;
}else{
return null;
}
}
function startBuynowCountdown(time) {
"use strict";
var element = $(".product-buynow-countdown[data-countdown]");
if('active' == element.attr("data-countdown-status")) {
return false;
}
if('undefined' != typeof time) {
element.attr('data-countdown', time);
}
var countdown = element.attr('data-countdown');
if(countdown && countdown.length > 0) {
BUYNOW_COUNTDOWN = setInterval(function() {
var countdown_value = SimpleCountdown(countdown);
element.text(countdown_value);
/*
Destroy interval
Hide countdown
*/
var timeServer = typeof window.serverTime() != null ? window.serverTime() : (new Date()).getTime() / 1000;
var isExpired = countdown <= parseInt(timeServer);
$(".buyitnow-status p > span.product-value").toggle(isExpired);
$("span.product-buynow-countdown").toggle(!isExpired);
if(isExpired) clearInterval(BUYNOW_COUNTDOWN);
}, 1000);
element.attr("data-countdown-status", "active");
}
}
function setStatusBuynowButton(status, error_type) {
"use strict";
var selector = ".buyitnow-button";
var element = $(selector);
var defaults = "button-default button-full buyitnow-button ripple-button";
var base = "buyitnow-button";
var specific = 'button-blue-gradient';
switch(status) {
default:
case 'enabled': {
bindBuynowTrigger(error_type);
break;
}
case 'engaged': {
$('body').find("[data-buynow-state='engaged']").fadeIn();
bindBuynowTrigger(error_type);
break;
}
case 'disabled': {
specific = "button-gray-flat";
element.off('click');
element.find("[data-buynow-state='engaged']").fadeOut('fast');
break;
}
case 'login': {
element.off('click').on('click', window.parent.showLogin);
break;
}
}
if("undefined"===typeof element[0]) return element;
var oldClass = element[0].className;
var newClass = [defaults, specific, [base, status].join('-')].join(' ');
if(oldClass != newClass) {
$("main.buyitnow").find(selector).each(function(k, item) {
$(item).removeClass();
$(item).addClass(newClass);
});
$(".auction-action-bid-mobile .buyitnow-button")
.toggleClass(specific,true);
}
return element;
}
function bindBuynowTrigger(error_type) {
"use strict";
var selector = ".buyitnow-button";
var element = $('body').find(selector);
element.each(function(k, elem) {
$(elem).off('click').on('click', function(e) {
e.preventDefault();
rippleButton($(elem), e);
if(!error_type) {
var url = "buy_your_product.php"+parseURL(window.location.href).search;
navigateDeepModalURL(url);
return false;
}
$(elem).popover({
html: true,
content: BUYNOW_ERRORS[error_type],
placement: isSmartphoneDevice() ? "top" : "bottom",
selector: selector,
container: "body"
}).on('shown.bs.popover', function() {
setTimeout(function() {
$(selector).popover('destroy');
}, 3000);
}).popover('show');
});
});
}
$(document).ready(function() {
"use strict";
$("body").find(".expenditure-value").each(function(k, item) {
var expenditure = $(item).text();
if(expenditure.length && parseInt(expenditure, 10) > 0) {
updateUserExpenditure(expenditure);
$('[data-buynow-state="engaged"]').fadeIn();
return false;
}
});
});