2022-05-05 05:16:17 +08:00
|
|
|
window.triggerEvent = function triggerEvent (target, event, process) {
|
2018-10-25 01:07:40 +08:00
|
|
|
const e = document.createEvent('HTMLEvents')
|
2016-05-27 01:54:37 +08:00
|
|
|
e.initEvent(event, true, true)
|
2018-12-20 08:26:58 +08:00
|
|
|
if (event === 'click') {
|
2022-05-02 04:37:05 +08:00
|
|
|
// @ts-expect-error Button is readonly
|
|
|
|
(e as MouseEvent).button = 0
|
2018-12-20 08:26:58 +08:00
|
|
|
}
|
2016-05-27 01:54:37 +08:00
|
|
|
if (process) process(e)
|
|
|
|
target.dispatchEvent(e)
|
|
|
|
}
|