tianyun 1 ano atrás
pai
commit
67cf66f0a3
2 arquivos alterados com 42 adições e 18 exclusões
  1. 16 5
      simple-demo/js/util.js
  2. 26 13
      tmp.js

+ 16 - 5
simple-demo/js/util.js

@@ -424,15 +424,14 @@ async function convertToWebPAsync(base64Image) {
         const ctx = canvas.getContext('2d');
         ctx.drawImage(image, 0, 0);
 
-        const webpData = canvas.toDataURL('image/webp');
-        return webpData;
+        return canvas.toDataURL('image/webp');
     }
 }
 
 
 function closeWindow() {
     const userAgent = navigator.userAgent;
-    if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
+    if (userAgent.indexOf("Firefox") !== -1 || userAgent.indexOf("Chrome") !== -1) {
         window.location.href = "about:blank";
         window.close();
     } else {
@@ -446,8 +445,7 @@ function closeWindow() {
 function getTimeStamp() {
     const currentTimeStamp = Date.now();
     const targetTimeStamp = new Date('2024-01-01').getTime();
-    const difference = currentTimeStamp - targetTimeStamp;
-    return difference;
+    return currentTimeStamp - targetTimeStamp;
 }
 
 
@@ -504,6 +502,19 @@ function showTextOnTopRight(text) {
 function showBusyText() {
     showTextOnTopRight("同步中...");
 }
+
 function showDoneText() {
     showTextOnTopRight("✅");
 }
+
+
+// dispatchEventClick('.btn') 触发点击事件
+function dispatchEventClick(cssSelector) {
+    let dom = document.querySelector(cssSelector);
+    if (!dom) {
+        console.log('dom is null');
+        return;
+    }
+    const event = new Event('click');
+    dom.dispatchEvent(event);
+}

+ 26 - 13
tmp.js

@@ -1,15 +1,28 @@
-function sendSyncRequest(url, method, data) {
-    const xhr = new XMLHttpRequest();
-    xhr.open(method, url, false);
-
-    if (method === 'POST' || method === 'PUT') {
-        xhr.setRequestHeader('Content-Type', 'application/json');
-        xhr.send(JSON.stringify(data));
-    } else {
-        xhr.send();
+// 查找 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();
+        }
     }
+})
 
-    return JSON.parse(xhr.responseText);
-}
-let a = sendSyncRequest("https://httpbin.tianyunperfect.cn/post","POST", {"a": 1})
-console.log(a);
+
+function dispatchEventClick(cssSelector) {
+    let dom = document.querySelector(cssSelector);
+    if (!dom) {
+        console.log('dom is null');
+        return;
+    }
+    const event = new Event('click');
+    dom.dispatchEvent(event);
+}