tmp.js 762 B

12345678910111213141516171819202122232425262728
  1. // 查找 aria-label="Edit" 的btn
  2. // 监控 键盘 事件,如果触发了e
  3. document.addEventListener('keydown', e => {
  4. // 如果按下了esc键
  5. if (e.key === 'e') {
  6. const btn = document.querySelector('button[aria-label="Edit"]')
  7. const dialog = document.querySelector('.dialog-wrapper.memo-editor-dialog.showup')
  8. // 如果btn存在,但是dialog不存在
  9. if (btn && !dialog) {
  10. // 点击btn
  11. btn.click();
  12. e.preventDefault();
  13. }
  14. }
  15. })
  16. function dispatchEventClick(cssSelector) {
  17. let dom = document.querySelector(cssSelector);
  18. if (!dom) {
  19. console.log('dom is null');
  20. return;
  21. }
  22. const event = new Event('click');
  23. dom.dispatchEvent(event);
  24. }