diff --git a/static/js/api.js b/static/js/api.js index d80e460..a4a7259 100644 --- a/static/js/api.js +++ b/static/js/api.js @@ -261,132 +261,4 @@ window.requestLiveSync = async function() { } }; -window.scanMarket = async function() { - if (!window.clientOnline) return alert('Το script είναι offline.'); - const town = window.getSelectedTown(); - if (!town) return alert('Select a town first.'); - try { - const res = await fetch('/dashboard/commands', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - town_id: town.town_id, - town_name: town.town_name, - type: 'scan_market', - payload: {}, - player_id: window.PLAYER_ID - }) - }); - const data = await res.json(); - if (data.ok) { - document.getElementById('market-offers-content').innerHTML = '⏳ Αναζήτηση σε εξέλιξη... Περιμένετε!'; - window.fetchLog(); - - // Auto fetch market data every 2 seconds for the next 15 seconds - let attempts = 0; - const interval = setInterval(() => { - window.fetchMarketData(); - attempts++; - if (attempts > 7) clearInterval(interval); - }, 2000); - } else { - alert('Error: ' + JSON.stringify(data)); - } - } catch (e) { - alert('Failed to send scan_market command: ' + e); - } -}; - -window.acceptMarketOffer = async function(offer_id, amount) { - if (!window.clientOnline) return alert('Το script είναι offline.'); - const town = window.getSelectedTown(); - if (!town) return alert('Select a town first.'); - - try { - const res = await fetch('/dashboard/commands', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - town_id: town.town_id, - town_name: town.town_name, - type: 'accept_market_offer', - payload: { offer_id: parseInt(offer_id), amount: parseInt(amount) }, - player_id: window.PLAYER_ID - }) - }); - const data = await res.json(); - if (data.ok) { - window.fetchLog(); - alert(`Εστάλη εντολή αποδοχής για την προσφορά #${offer_id}!`); - // Update local UI immediately so user doesn't double click - document.getElementById(`offer-btn-${offer_id}`).disabled = true; - document.getElementById(`offer-btn-${offer_id}`).innerText = '⏳'; - } else { - alert('Error: ' + JSON.stringify(data)); - } - } catch (e) { - alert('Failed to send accept_market_offer command: ' + e); - } -}; - -window.lastMarketUpdate = null; -window.fetchMarketData = async function() { - try { - const res = await fetch('/dashboard/market-data?player_id=' + window.PLAYER_ID); - const data = await res.json(); - if (!data || !data.data || !data.data.offers) return; - - // Only re-render if the timestamp has changed - if (window.lastMarketUpdate === data.updated_at) return; - window.lastMarketUpdate = data.updated_at; - - const offers = data.data.offers; - if (offers.length === 0) { - document.getElementById('market-offers-content').innerHTML = 'Καμία διαθέσιμη προσφορά.'; - return; - } - - let html = ` - - - - - - - - `; - - for (const off of offers) { - const ratio = (off.demand / off.offer).toFixed(2); - // Map resources to emoji - const offerEmoji = off.offer_type === 'wood' ? '🪵' : off.offer_type === 'stone' ? '🪨' : '🪙'; - const demandEmoji = off.demand_type === 'wood' ? '🪵' : off.demand_type === 'stone' ? '🪨' : '🪙'; - - let seconds = off.delivery_time; - let h = Math.floor(seconds / 3600); - let m = Math.floor((seconds % 3600) / 60); - let timeStr = `${h}h ${m}m`; - - html += ` - - - - - - - `; - } - html += '
ΠαίκτηςΠροσφέρειΖητάειΛόγοςΔιάρκεια
${off.player_name || 'NPC'}${off.offer} ${offerEmoji}${off.demand} ${demandEmoji}1 : ${ratio}${timeStr} - -
'; - - // Add timestamp note - let d = new Date(data.updated_at + "Z"); // SQLite UTC - html += `
Τελευταία ανανέωση: ${d.toLocaleTimeString()}
`; - - document.getElementById('market-offers-content').innerHTML = html; - } catch (e) { - console.error('Failed to fetch market data:', e); - } -}; diff --git a/templates/dashboard.html b/templates/dashboard.html index 6a0422d..9517fe1 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -205,17 +205,6 @@ -
-
- -
- Χωρητικότητα: 0 - -
-
-
-
Πατήστε "Αναζήτηση" για να φορτώσετε τη λίστα.
-