| @@ -503,6 +503,7 @@ watch(() => route.data, () => { |
| 503 | 503 | void tryOpenAnchoredContent() |
| 504 | 504 | rewriteAnchorLinksDeferred() |
| 505 | 505 | nextTick(setupOutlineFollow) |
| 506 | nextTick(setupManualCopyButtons) |
| 506 | 507 | }, { flush: 'post' }) |
| 507 | 508 | watch(() => route.query, () => { |
| 508 | 509 | void tryOpenAnchoredContent() |
| @@ -655,9 +656,75 @@ function initTitleOnly() { |
| 655 | 656 | }) |
| 656 | 657 | } |
| 657 | 658 | |
| 659 | function initCopyButtonsInRoot(root: ParentNode) { |
| 660 | root.querySelectorAll<HTMLTableElement>('table').forEach(table => { |
| 661 | const headers = table.querySelectorAll<HTMLTableCellElement>('thead th') |
| 662 | let manualColIndex = -1 |
| 663 | headers.forEach((th, i) => { |
| 664 | if (th.textContent?.trim() === 'Manual') manualColIndex = i |
| 665 | }) |
| 666 | if (manualColIndex === -1) return |
| 667 | |
| 668 | table.querySelectorAll<HTMLTableRowElement>('tbody tr').forEach(row => { |
| 669 | const cell = row.querySelectorAll('td')[manualColIndex] |
| 670 | if (!cell || cell.querySelector('.manual-copy-btn')) return |
| 671 | |
| 672 | const link = cell.querySelector<HTMLAnchorElement>('a[href]') |
| 673 | if (!link) return |
| 674 | const url = link.getAttribute('href')! |
| 675 | |
| 676 | const btn = document.createElement('button') |
| 677 | btn.className = 'manual-copy-btn' |
| 678 | btn.title = 'Copy URL' |
| 679 | const icon = document.createElement('span') |
| 680 | icon.className = 'i-lucide:copy' |
| 681 | btn.appendChild(icon) |
| 682 | |
| 683 | btn.addEventListener('click', async (e) => { |
| 684 | e.preventDefault() |
| 685 | try { |
| 686 | await navigator.clipboard.writeText(url) |
| 687 | icon.className = 'i-lucide:check' |
| 688 | btn.classList.add('copied') |
| 689 | setTimeout(() => { |
| 690 | icon.className = 'i-lucide:copy' |
| 691 | btn.classList.remove('copied') |
| 692 | }, 2000) |
| 693 | } catch {} |
| 694 | }) |
| 695 | |
| 696 | cell.classList.add('has-manual-copy') |
| 697 | cell.appendChild(btn) |
| 698 | }) |
| 699 | }) |
| 700 | } |
| 701 | |
| 702 | let copyButtonObserver: MutationObserver | null = null |
| 703 | |
| 704 | function setupManualCopyButtons() { |
| 705 | initCopyButtonsInRoot(document) |
| 706 | |
| 707 | copyButtonObserver?.disconnect() |
| 708 | copyButtonObserver = new MutationObserver((mutations) => { |
| 709 | for (const mutation of mutations) { |
| 710 | for (const node of mutation.addedNodes) { |
| 711 | if (!(node instanceof HTMLElement)) continue |
| 712 | if (node.classList.contains('plugin-tabs--content')) { |
| 713 | initCopyButtonsInRoot(node) |
| 714 | } else { |
| 715 | node.querySelectorAll<HTMLElement>('.plugin-tabs--content').forEach( |
| 716 | panel => initCopyButtonsInRoot(panel) |
| 717 | ) |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | }) |
| 722 | copyButtonObserver.observe(document.body, { childList: true, subtree: true }) |
| 723 | } |
| 724 | |
| 658 | 725 | watch( |
| 659 | 726 | () => route.path, |
| 660 | | () => nextTick(() => initTitleOnly()), |
| 727 | () => nextTick(() => { initTitleOnly(); setupManualCopyButtons() }), |
| 661 | 728 | { flush: 'post' } |
| 662 | 729 | ) |
| 663 | 730 | |
| @@ -665,6 +732,7 @@ onMounted(() => { |
| 665 | 732 | if (import.meta.env.SSR) return |
| 666 | 733 | |
| 667 | 734 | initTitleOnly() |
| 735 | nextTick(setupManualCopyButtons) |
| 668 | 736 | |
| 669 | 737 | // Icon tooltip: fixed-position popup appended to <body> to escape table overflow clipping |
| 670 | 738 | const tooltipEl = document.createElement('div') |
| @@ -867,6 +935,7 @@ onMounted(() => { |
| 867 | 935 | |
| 868 | 936 | onUnmounted(() => { |
| 869 | 937 | outlineFollowObserver?.disconnect() |
| 938 | copyButtonObserver?.disconnect() |
| 870 | 939 | cancelAnimationFrame(outlineFollowRaf) |
| 871 | 940 | takodachiDisable.value && takodachiDisable.value() |
| 872 | 941 | }) |