|
249 | 249 | const anchorRect = anchor.getBoundingClientRect(); |
250 | 250 | const anchorHeight = anchor.offsetHeight; |
251 | 251 | console.log('[GMTOC] anchor:', anchor.tagName, anchor.className.substring(0, 60), 'h:', anchorHeight, 'top:', Math.round(anchorRect.top), 'hostTop:', Math.round(hostRect.top)); |
252 | | - // 防御:anchor 尚未完成布局时不写入异常值,等待后续 ResizeObserver 触发修正 |
| 252 | + // Defense: Don't write invalid values when anchor hasn't finished layout, let ResizeObserver fix it later |
253 | 253 | if (anchorHeight > 0) { |
254 | 254 | wrapperEl.style.top = (anchorRect.top - hostRect.top) + 'px'; |
255 | 255 | wrapperEl.style.height = anchorHeight + 'px'; |
|
342 | 342 | const stickyHeader = document.querySelector('#repos-sticky-header'); |
343 | 343 | if (stickyHeader) { |
344 | 344 | resizeObserver.observe(stickyHeader); |
345 | | - // 同时观察 sticky header 的直接子 div,确保高度变化时更新位置 |
| 345 | + // Also observe sticky header's direct child div to update position when height changes |
346 | 346 | const stickyDiv = stickyHeader.querySelector(':scope > div'); |
347 | 347 | if (stickyDiv) { |
348 | 348 | resizeObserver.observe(stickyDiv); |
349 | 349 | } |
350 | 350 | } |
351 | 351 | } |
352 | 352 |
|
353 | | - // 观察 #repos-sticky-header 元素出现(GitHub 可能延迟渲染该元素) |
| 353 | + // Watch for #repos-sticky-header element appearance (GitHub may render this element lazily) |
354 | 354 | if (!document.querySelector('#repos-sticky-header')) { |
355 | 355 | stickyHeaderObserver = new MutationObserver(() => { |
356 | 356 | const stickyHeader = document.querySelector('#repos-sticky-header'); |
|
498 | 498 |
|
499 | 499 | chrome.storage.sync.set({ [STORAGE_KEY_COLLAPSED]: settings.collapsed }); |
500 | 500 |
|
501 | | - // 等待 CSS 布局更新后重新计算位置(收起时宽度从全尺寸变为 32px) |
| 501 | + // Recalculate position after CSS layout update (width changes from full to 32px when collapsed) |
502 | 502 | requestAnimationFrame(() => positionSidebar()); |
503 | 503 | } |
504 | 504 |
|
|
694 | 694 | /* ------------------------------------------------------------------ */ |
695 | 695 | function update() { |
696 | 696 | console.log('[GMTOC] update() called'); |
697 | | - // 检测 stale DOM 引用:SPA 导航后旧 sidebar 已不在 DOM 中 |
| 697 | + // Detect stale DOM reference: old sidebar no longer in DOM after SPA navigation |
698 | 698 | if (sidebarEl && !sidebarEl.isConnected) { |
699 | 699 | removeSidebar(); |
700 | 700 | } |
|
829 | 829 | await loadSettings(); |
830 | 830 | update(); |
831 | 831 | setupNavigationListener(); |
832 | | - // 兜底:等待浏览器完成首次布局后再次校正 sidebar 位置 |
| 832 | + // Fallback: Wait for browser to complete initial layout then re-correct sidebar position |
833 | 833 | requestAnimationFrame(() => { |
834 | 834 | requestAnimationFrame(() => { |
835 | 835 | positionSidebar(); |
|
0 commit comments