mirror of
https://github.com/NetworkCats/rustyip.git
synced 2026-11-13 16:17:46 +00:00
fix: ensure city label is available for JS-rendered alt IP rows
When the primary IP lacks city data, the conditional <tr data-label="city"> row is absent from the DOM, so readLabels() cannot scrape the translated label. Embed translated labels as data-l-* attributes on the <table> element so they are always available regardless of which rows are rendered.
This commit is contained in:
@@ -238,6 +238,15 @@ function initAltIp(root, section) {
|
||||
|
||||
function readLabels() {
|
||||
const labels = {};
|
||||
const table = root.querySelector(".info-table");
|
||||
if (table) {
|
||||
for (const [attr, val] of Object.entries(table.dataset)) {
|
||||
if (attr.startsWith("l")) {
|
||||
const key = attr.slice(1).toLowerCase();
|
||||
if (key) labels[key] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const row of root.querySelectorAll(".info-table tbody tr")) {
|
||||
const key = row.getAttribute("data-label");
|
||||
const th = row.querySelector("th");
|
||||
|
||||
@@ -77,7 +77,8 @@
|
||||
<span class="ip-copied-tooltip" aria-live="polite" hidden>{{ "Copied"|t(locale) }}</span>
|
||||
</div>
|
||||
|
||||
<table class="info-table" aria-label="{{ "IP address information"|t(locale) }}">
|
||||
<table class="info-table" aria-label="{{ "IP address information"|t(locale) }}"
|
||||
data-l-asn="{{ "ASN"|t(locale) }}" data-l-org="{{ "Org"|t(locale) }}" data-l-country="{{ "Country"|t(locale) }}" data-l-city="{{ "City"|t(locale) }}">
|
||||
<tbody>
|
||||
{% if !asn.is_empty() %}
|
||||
<tr data-label="asn">
|
||||
|
||||
Reference in New Issue
Block a user