Spaces:
Paused
Paused
Your Name
Fix router FOUC rule permanently hiding all pages; add DOM/computed-style route validators
4fc5db8 | const fs = require('fs'); | |
| const html = fs.readFileSync('hermes_overlay/tools/templates/hermes_futures_desk_luxury.html', 'utf8'); | |
| const script = html.match(/<script>([\s\S]*?)<\/script>/)[1]; | |
| // Extract just the router bits we need, with a fake `window`/`history`/`document`. | |
| const ROUTER_PAGES_MATCH = script.match(/const ROUTER_PAGES=(\[[^\]]*\]);/)[1]; | |
| const ROUTER_LEGACY_MATCH = script.match(/const ROUTER_LEGACY_MAP=(\{[^}]*\});/)[1]; | |
| const resolveFnMatch = script.match(/function resolvePageFromHash\(\)\{[\s\S]*?\}\n/)[0]; | |
| let hash = ''; | |
| const window_ = { location: { get hash(){return hash}, set hash(v){hash=v} } }; | |
| const fn = new Function('window', ROUTER_PAGES_MATCH.startsWith('[') ? | |
| `const ROUTER_PAGES=${ROUTER_PAGES_MATCH}; const ROUTER_LEGACY_MAP=${ROUTER_LEGACY_MATCH}; ${resolveFnMatch}; return resolvePageFromHash;` : ''); | |
| const resolvePageFromHash = fn(window_); | |
| const cases = [ | |
| ['#market','market'], ['#trade-plan','trade-plan'], ['#signals','signals'], | |
| ['#advisory','advisory'], ['#account','account'], ['#diagnostics','diagnostics'], | |
| ['#activity','activity'], ['#data-sources','data-sources'], | |
| ['#activityCard','activity'], ['#marketCard','market'], ['#planCard','trade-plan'], | |
| ['#signalsCard','signals'], ['#advisoryCard','advisory'], ['#accountCard','account'], | |
| ['#insightsCard','diagnostics'], ['#sourcesCard','data-sources'], | |
| ['', 'market'], ['#nonsense','market'] | |
| ]; | |
| let ok = true; | |
| for (const [h, expected] of cases) { | |
| window_.location.hash = h; | |
| const got = resolvePageFromHash(); | |
| const pass = got === expected; | |
| if (!pass) ok = false; | |
| console.log((pass?'OK ':'FAIL'), JSON.stringify(h), '->', got, pass?'':' expected '+expected); | |
| } | |
| console.log(ok ? 'ALL_ROUTES_OK' : 'ROUTE_FAILURES'); | |