Intelligence, Advanced Charting & Trading Platform
risk/chartnova-atomic-outbox-2026-10-22
diagnostics/chartnova-blank-screen-2026-10-15
diagnostics/chartnova-stage2-v27-preview-2026-10-15
docs/chartnova-stage1-reconcile-manifest-2026-10-15
feature/chartnova-ios-widget
feature/chartnova-light-catalog-lazy-series-2026-10-15
feature/chartnova-market-terminal
feature/chartnova-multimarket-chart-ws-foundation
feature/chartnova-neon-direct-history
feature/chartnova-neon-history
feature/paper-trading-risk-controls-2026-10-14
fix/alpha-vantage-live-payload
fix/chartnova-progressive-loading-2026-10-15
fix/live-proof-runner-cwd-2026-10-14
foundation/phase-0
foundation/postgres-core
main
ops/chartnova-emergency-rollback-2026-10-15
phase-1/candle-builder
phase-1/data-proof-artifact
phase-1/data-proof-metrics
phase-1/data-proof-report
phase-1/external-gates-state
phase-1/gold-api-fallback
phase-1/ingestion-pipeline
phase-1/live-proof-runner
phase-1/market-calendar
phase-1/market-domain
phase-1/neon-live-proof
phase-1/persistence-contract
phase-1/postgres-ci
phase-1/provider-adapters
phase-1/provider-recovery
phase-1/quality-propagation
phase-1/spike-detection
phase-1/xau-provider-adapter
risk/chartnova-alert-runtime-atomic-2026-10-22
risk/chartnova-atomic-outbox-2026-10-22
risk/chartnova-seven-track-safety-2026-10-21
safety/p0-triage-2026-10-13
| 1 | /** |
| 2 | * Reversible and fail-closed patch of the deployed ChartNova HTML bootstrap. |
| 3 | * Leaves provider APIs, cached values, bindings and market data untouched. |
| 4 | */ |
| 5 | const beforeMarkets=' renderMarkets();renderTechnical();renderSelected();\n}\nasync function refresh(){'; |
| 6 | const afterMarkets=[ |
| 7 | ' // Render only the visible view; do not repeatedly build hidden 58-card grids.', |
| 8 | ' if(!el("markets").hidden)renderMarkets();', |
| 9 | ' if(!el("technical").hidden)renderTechnical();', |
| 10 | ' if(!el("dashboard").hidden)renderSelected();', |
| 11 | ' if(!el("widget").hidden)renderWidget();', |
| 12 | '}', |
| 13 | 'async function refresh(){' |
| 14 | ].join('\n'); |
| 15 | const beforeRefresh=[ |
| 16 | 'async function refresh(){', |
| 17 | ' el("status").textContent="در حال دریافت دادههای ذخیرهشده...";', |
| 18 | ' await Promise.allSettled([loadDomestic(),loadGold(),loadMarkets()]);', |
| 19 | ' renderSelected();renderMarkets();renderTechnical();', |
| 20 | ' const age=Date.parse(marketState.receivedAt||"");', |
| 21 | ' el("status").textContent=marketState.loaded?(Number.isFinite(age)&&Date.now()-age<=45*60000?"داده بازار بهروز · بررسی هر ۱۵ دقیقه":"آخرین داده ذخیرهشده · غیرلحظهای"):"در انتظار داده نمادها · قیمتهای موجود";', |
| 22 | '}' |
| 23 | ].join('\n'); |
| 24 | const afterRefresh=[ |
| 25 | 'let chartnovaRefreshInFlight=null;', |
| 26 | 'function refresh(){', |
| 27 | ' if(chartnovaRefreshInFlight)return chartnovaRefreshInFlight;', |
| 28 | ' const status=el("status");', |
| 29 | ' status.textContent="در حال دریافت قیمتهای اصلی...";', |
| 30 | ' const onPrimaryLoaded=()=>{', |
| 31 | ' if(!el("dashboard").hidden)renderSelected();', |
| 32 | ' if(!marketState.loaded)status.textContent="قیمتهای اصلی بررسی شدند · در حال دریافت نمادها...";', |
| 33 | ' };', |
| 34 | ' chartnovaRefreshInFlight=Promise.allSettled([', |
| 35 | ' loadDomestic().finally(onPrimaryLoaded),', |
| 36 | ' loadGold().finally(onPrimaryLoaded),', |
| 37 | ' loadMarkets()', |
| 38 | ' ]).then(()=>{', |
| 39 | ' const age=Date.parse(marketState.receivedAt||"");', |
| 40 | ' status.textContent=marketState.loaded?(Number.isFinite(age)&&Date.now()-age<=45*60000?', |
| 41 | ' "داده بازار بهروز · بررسی هر ۱۵ دقیقه":"آخرین داده ذخیرهشده · غیرلحظهای"):', |
| 42 | ' "داده قیمت بررسی شد · نمادها در دسترس نیستند";', |
| 43 | ' }).finally(()=>{chartnovaRefreshInFlight=null});', |
| 44 | ' return chartnovaRefreshInFlight;', |
| 45 | '}' |
| 46 | ].join('\n'); |
| 47 | |
| 48 | function replaceExactlyOnce(value,oldPart,newPart,label){ |
| 49 | const count=value.split(oldPart).length-1; |
| 50 | if(count!==1)throw new Error(label+' expected once, got '+count); |
| 51 | return value.replace(oldPart,newPart); |
| 52 | } |
| 53 | export function optimizeChartNovaWorker(worker){ |
| 54 | if(typeof worker!=='string'||worker.length<10000)throw new Error('Unexpected Worker size'); |
| 55 | const anchor='return new Response("<!doctype html>'; |
| 56 | const start=worker.indexOf(anchor); |
| 57 | const end=worker.indexOf('",{headers:{"content-type":"text/html; charset=utf-8"',start); |
| 58 | if(start<0||end<0)throw new Error('Expected production HTML literal not found'); |
| 59 | const literalStart=start+'return new Response('.length; |
| 60 | const htmlLiteral=worker.slice(literalStart,end+1); |
| 61 | let html;try{html=JSON.parse(htmlLiteral)}catch{throw new Error('HTML literal is not valid JSON string')} |
| 62 | const first=html.indexOf('<script>'),last=html.indexOf('</script>',first); |
| 63 | if(first<0||last<0||html.indexOf('<script>',first+1)!==-1)throw new Error('Unexpected inline script count'); |
| 64 | const js=html.slice(first+8,last); |
| 65 | let updated=replaceExactlyOnce(js,beforeMarkets,afterMarkets,'lazy view'); |
| 66 | updated=replaceExactlyOnce(updated,beforeRefresh,afterRefresh,'progressive refresh'); |
| 67 | const newHTML=html.slice(0,first+8)+updated+html.slice(last); |
| 68 | if(newHTML.replace(updated,js)!==html)throw new Error('Unexpected HTML mutation'); |
| 69 | const result=worker.slice(0,literalStart)+JSON.stringify(newHTML)+worker.slice(end+1); |
| 70 | if(result===worker)throw new Error('No source update'); |
| 71 | return {source:result,oldHTML:html,newHTML,oldJS:js,newJS:updated}; |
| 72 | } |