12345678910111213141516171819202122232425262728 |
- // 查找 aria-label="Edit" 的btn
- // 监控 键盘 事件,如果触发了e
- document.addEventListener('keydown', e => {
- // 如果按下了esc键
- if (e.key === 'e') {
- const btn = document.querySelector('button[aria-label="Edit"]')
- const dialog = document.querySelector('.dialog-wrapper.memo-editor-dialog.showup')
- // 如果btn存在,但是dialog不存在
- if (btn && !dialog) {
- // 点击btn
- btn.click();
- e.preventDefault();
- }
- }
- })
- function dispatchEventClick(cssSelector) {
- let dom = document.querySelector(cssSelector);
- if (!dom) {
- console.log('dom is null');
- return;
- }
- const event = new Event('click');
- dom.dispatchEvent(event);
- }
|