Put the selected chain in the page address
- Opening ?chain=testnet or ?chain=testnet4 selects that list, so it can be shared as a link; an unknown value falls back to Bitcoin. - The chain buttons update the address and Back/Forward follow it. - Bitcoin stays the default and keeps the plain address.
This commit is contained in:
29
index.html
29
index.html
@@ -510,6 +510,20 @@ function getChain() {
|
||||
return btn ? btn.dataset.c : 'bitcoin';
|
||||
}
|
||||
|
||||
// The selected chain lives in the address (?chain=testnet4), so a chain's list
|
||||
// can be shared as a link. Bitcoin is the default and keeps the plain address.
|
||||
function setChain(chain) {
|
||||
const buttons = [...document.querySelectorAll('#chainSeg button')];
|
||||
const target = buttons.find(b => b.dataset.c === chain && b.style.display !== 'none');
|
||||
if (!target) return false;
|
||||
buttons.forEach(b => b.setAttribute('aria-pressed', b === target ? 'true' : 'false'));
|
||||
return true;
|
||||
}
|
||||
|
||||
function chainFromUrl() {
|
||||
return new URLSearchParams(window.location.search).get('chain') || 'bitcoin';
|
||||
}
|
||||
|
||||
function getFiltered() {
|
||||
return allServers
|
||||
.filter(d => (d.url + " " + (d.info||"")).toLowerCase().includes(q.toLowerCase()));
|
||||
@@ -609,8 +623,18 @@ document.getElementById('filter').addEventListener('input', e => {
|
||||
document.getElementById('chainSeg').addEventListener('click', e => {
|
||||
const b = e.target.closest('button');
|
||||
if (!b) return;
|
||||
[...e.currentTarget.children].forEach(x => x.setAttribute('aria-pressed', 'false'));
|
||||
b.setAttribute('aria-pressed', 'true');
|
||||
setChain(b.dataset.c);
|
||||
const url = new URL(window.location.href);
|
||||
if (b.dataset.c === 'bitcoin') url.searchParams.delete('chain');
|
||||
else url.searchParams.set('chain', b.dataset.c);
|
||||
history.pushState(null, '', url);
|
||||
fetchData();
|
||||
fetchMinAmount();
|
||||
});
|
||||
|
||||
// Browser Back/Forward: follow the address, an unknown chain falls back to Bitcoin.
|
||||
window.addEventListener('popstate', () => {
|
||||
if (!setChain(chainFromUrl())) setChain('bitcoin');
|
||||
fetchData();
|
||||
fetchMinAmount();
|
||||
});
|
||||
@@ -760,6 +784,7 @@ document.getElementById('url').addEventListener('keydown', e => {
|
||||
});
|
||||
|
||||
(async function init() {
|
||||
setChain(chainFromUrl());
|
||||
await Promise.all([fetchData(), fetchMinAmount()]);
|
||||
const blob = new Blob([JSON.stringify(allServers, null, 2)], { type: 'application/json' });
|
||||
document.getElementById('download').href = URL.createObjectURL(blob);
|
||||
|
||||
Reference in New Issue
Block a user