The info bubble in the warehouse and the Lumishop now shows only what an Aion 2 database says
about the item: name in the grade colour, grade, slot, type, binding, item level and required
level, description, base stats, item info (sockets, max stack, sell price, effect when used) and
the highest enchant. Stock, price, last movement and the gear-catalogue match are gone.
- includes/item_db.php finds the item on aion2hub by its name (/database?q=..., exact name, else
the bound variant), reads the item page and caches both: the values in item_db, the name -> item
id mapping in item_db_names (schema 51, also in sql/schema.sql). Data is fetched on the first
hover only, refreshed after 30 days; names not found are searched again after 7 days.
- At most 20 aion2hub pages per minute for the whole site (rate_limits, bucket aion2hub), only
names that exist in the warehouse or the shop, fetched via gear_source_fetch() like the gear
planner. aion2hub allows these pages in robots.txt, only /api/ is disallowed.
- item_info.php answers the bubble (JSON: ok, missing, busy, error), assets/js/item-tooltip.js
shows "Lade Spieldaten ..." until then and keeps the result for the page. Placeholders aion2hub
leaves unresolved in descriptions ({abe:...}) are shown as "...".
- Shop offers linked to a warehouse item are looked up under the warehouse name.
- includes/item_tooltip.php removed; patch notes and README updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
5.2 KiB
JavaScript
135 lines
5.2 KiB
JavaScript
/**
|
||
* Info-Blase zu Gegenstaenden (Lagerhaus, Lumishop): Karten mit data-item-tip="<Name>" zeigen beim
|
||
* Draufzeigen mit der Maus bzw. beim Ansteuern mit der Tastatur die Spieldaten des Gegenstands von
|
||
* aion2hub (item_info.php, dort zwischengespeichert). Die Blase steht neben der Karte - rechts, sonst
|
||
* links, sonst darunter - und immer ganz im Fenster. Auf Touch-Geraeten nicht: dort ist Tippen schon
|
||
* "oeffnen" bzw. "beantragen".
|
||
*/
|
||
(function () {
|
||
'use strict';
|
||
|
||
var tip = null;
|
||
var current = null;
|
||
var cache = {}; // Name -> {html} (fertig), {pending: true} oder {retryAt: Zeitpunkt}
|
||
|
||
function hide() {
|
||
if (tip) tip.hidden = true;
|
||
current = null;
|
||
}
|
||
|
||
function place(card) {
|
||
var box = card.getBoundingClientRect();
|
||
var gap = 10;
|
||
var margin = 8;
|
||
var viewWidth = document.documentElement.clientWidth;
|
||
var viewHeight = window.innerHeight;
|
||
if (box.bottom < 0 || box.top > viewHeight) {
|
||
hide();
|
||
return;
|
||
}
|
||
tip.style.left = '0px';
|
||
tip.style.top = '0px';
|
||
var width = tip.offsetWidth;
|
||
var height = tip.offsetHeight;
|
||
var left;
|
||
var top = box.top;
|
||
if (box.right + gap + width <= viewWidth - margin) {
|
||
left = box.right + gap;
|
||
} else if (box.left - gap - width >= margin) {
|
||
left = box.left - gap - width;
|
||
} else {
|
||
left = box.left + box.width / 2 - width / 2;
|
||
top = box.bottom + gap;
|
||
if (top + height > viewHeight - margin) top = box.top - gap - height;
|
||
}
|
||
tip.style.left = Math.round(Math.min(Math.max(margin, left), viewWidth - width - margin)) + 'px';
|
||
tip.style.top = Math.round(Math.min(Math.max(margin, top), viewHeight - height - margin)) + 'px';
|
||
}
|
||
|
||
function render(card, html) {
|
||
if (!tip) {
|
||
tip = document.createElement('div');
|
||
tip.className = 'item-tip';
|
||
tip.setAttribute('role', 'tooltip');
|
||
document.body.appendChild(tip);
|
||
}
|
||
current = card;
|
||
tip.innerHTML = html;
|
||
tip.hidden = false;
|
||
place(card);
|
||
}
|
||
|
||
function note(text) {
|
||
var el = document.createElement('div');
|
||
el.className = 'item-tip-note';
|
||
el.textContent = text;
|
||
return el.outerHTML;
|
||
}
|
||
|
||
function load(name) {
|
||
cache[name] = { pending: true };
|
||
fetch('/item_info.php?name=' + encodeURIComponent(name), { credentials: 'same-origin', headers: { 'Accept': 'application/json' } })
|
||
.then(function (response) { return response.json(); })
|
||
.then(function (data) {
|
||
if (data.status === 'success' && data.state === 'ok') {
|
||
cache[name] = { html: data.html };
|
||
} else if (data.status === 'success' && data.state === 'missing') {
|
||
cache[name] = { html: note('Zu „' + name + '“ gibt es bei aion2hub keine Daten.') };
|
||
} else {
|
||
// Tempolimit oder Fehler: gleich noch einmal versuchen
|
||
cache[name] = {
|
||
retryAt: Date.now() + 5000,
|
||
html: note(data.state === 'busy'
|
||
? 'Gerade werden viele Gegenstände abgerufen – gleich noch einmal zeigen.'
|
||
: 'Die Spieldaten sind gerade nicht erreichbar.')
|
||
};
|
||
}
|
||
})
|
||
.catch(function () {
|
||
cache[name] = { retryAt: Date.now() + 5000, html: note('Die Spieldaten sind gerade nicht erreichbar.') };
|
||
})
|
||
.then(function () {
|
||
if (current && current.getAttribute('data-item-tip') === name) render(current, cache[name].html);
|
||
});
|
||
}
|
||
|
||
function show(card) {
|
||
var name = card.getAttribute('data-item-tip');
|
||
if (!name) {
|
||
hide();
|
||
return;
|
||
}
|
||
var entry = cache[name];
|
||
if (!entry || (entry.retryAt && Date.now() > entry.retryAt)) {
|
||
load(name);
|
||
entry = cache[name];
|
||
}
|
||
render(card, entry.html || note('Lade Spieldaten …'));
|
||
}
|
||
|
||
document.addEventListener('pointerover', function (event) {
|
||
if (event.pointerType !== 'mouse') return;
|
||
var card = event.target.closest('[data-item-tip]');
|
||
if (card === current) return;
|
||
if (card && !card.hidden) show(card);
|
||
else hide();
|
||
});
|
||
document.documentElement.addEventListener('mouseleave', hide);
|
||
document.addEventListener('focusin', function (event) {
|
||
var card = event.target.closest('[data-item-tip]');
|
||
if (card) show(card);
|
||
else hide();
|
||
});
|
||
document.addEventListener('keydown', function (event) {
|
||
if (event.key === 'Escape') hide();
|
||
});
|
||
// Beim Scrollen mitwandern; verschwindet die Karte aus dem Bild, verschwindet auch die Blase
|
||
window.addEventListener('scroll', function () {
|
||
if (current) place(current);
|
||
}, true);
|
||
window.addEventListener('resize', hide);
|
||
// Dialoge (Einlagern, Beantragen ...) gehen vor
|
||
document.addEventListener('click', function (event) {
|
||
if (event.target.closest('[data-open-modal], .shop-buy')) hide();
|
||
});
|
||
})();
|