feat: init

This commit is contained in:
Simon
2025-09-29 16:33:15 +08:00
parent e8041e0582
commit 847620b5e8
98 changed files with 20166 additions and 0 deletions

20
src/patches/antd.ts Normal file
View File

@@ -0,0 +1,20 @@
import type { PageAgent } from '@/PageAgent'
const clearFunctions = [] as (() => void)[]
/**
* antd 的 select 是 div 包 input 的结构,所有信息都在 input 标签上,
* 但是 input 不可见,也不会出现在清洗后的树里,因此这里把他提上来
*/
function fixAntdSelect() {
const selects = [...document.querySelectorAll('input[role="combobox"]')]
// for (const select of selects) {}
}
export function patchAntd(pageAgent: PageAgent) {
pageAgent.addEventListener('beforeUpdate', fixAntdSelect)
pageAgent.addEventListener('afterUpdate', () => {
for (const fn of clearFunctions) fn()
clearFunctions.length = 0
})
}

16
src/patches/react.ts Normal file
View File

@@ -0,0 +1,16 @@
import type { PageAgent } from '@/PageAgent'
// Find common React root elements and add data-page-agent-not-interactive attribute
export function patchReact(pageAgent: PageAgent) {
const reactRootElements = document.querySelectorAll(
'[data-reactroot], [data-reactid], [data-react-checksum], #root, #app, [id^="root-"], [id^="app-"], #adex-wrapper, #adex-root'
)
for (const element of reactRootElements) {
element.setAttribute('data-page-agent-not-interactive', 'true')
}
}
/**
* @todo (Heavy, might have false negatives) Interaction detection, if element width/height equals body offsetWidth/Height, consider it root element and non-interactive (React often attaches many events to root elements, causing false positives)
*/