| 98 | } |
| 99 | |
| 100 | function getFilenames(menuItem: HTMLElement): {original: string; new: string} { |
| 101 | // Legacy view: get filenames from the data-path and Link--primary elements |
| 102 | if (menuItem.tagName === 'BUTTON') { |
| 103 | const [originalFileName, newFileName = originalFileName] = $( |
| 104 | '.Link--primary', |
| 105 | closestElement('[data-path]', menuItem), |
| 106 | ) |
| 107 | .textContent |
| 108 | .split(' → '); |
| 109 | |
| 110 | return {original: originalFileName, new: newFileName}; |
| 111 | } |
| 112 | |
| 113 | // New React view: get filenames from the file header |
| 114 | const fileNameElement = $('[class^="DiffFileHeader-module__file-name"]', focusedFileContainer); |
| 115 | const span = $optional('span:not(.sr-only)', fileNameElement); |
| 116 | const [originalFileName, newFileName = originalFileName] = (span ?? fileNameElement) |
| 117 | .textContent.split(' ').map(text => text.replaceAll('\u{200E}', '')); |
| 118 | |
| 119 | return {original: originalFileName, new: newFileName}; |
| 120 | } |
| 121 | |
| 122 | async function handleClick(event: DelegateEvent<MouseEvent, HTMLButtonElement>): Promise<void> { |
| 123 | const menuItem = event.delegateTarget; |