Ahmad Kholid 1 سال پیش
والد
کامیت
e15f3810e4

+ 2 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "automa",
-  "version": "1.28.22",
+  "version": "1.28.23",
   "description": "An extension for automating your browser by connecting blocks",
   "repository": {
     "type": "git",
@@ -65,6 +65,7 @@
     "dexie": "^3.2.3",
     "html2canvas": "^1.4.1",
     "idb": "^7.0.2",
+    "js-base64": "^3.7.5",
     "json5": "^2.2.3",
     "jsonpath": "^1.1.1",
     "jspdf": "^2.5.1",

+ 1 - 1
src/background/BackgroundEventsListeners.js

@@ -44,7 +44,7 @@ async function handleScheduleBackup() {
       payload.storageVariables = JSON.stringify(variables);
     }
 
-    const base64 = btoa(JSON.stringify(payload));
+    const base64 = btoa(encodeURIComponent(JSON.stringify(payload)));
     const filename = `${
       localBackupSettings.folderName ? `${localBackupSettings.folderName}/` : ''
     }${dayjs().format('DD-MMM-YYYY--HH-mm')}.json`;

+ 8 - 0
src/components/newtab/workflow/edit/EditPressKey.vue

@@ -75,6 +75,14 @@
       placeholder="keys"
       @change="updateData({ keysToPress: $event })"
     />
+    <ui-input
+      :model-value="Math.min(data.pressTime || 0, 0)"
+      :label="t('workflow.blocks.press-key.press-time')"
+      type="number"
+      class="w-full mt-2"
+      :placeholder="t('common.millisecond')"
+      @change="updateData({ pressTime: +$event })"
+    />
   </div>
 </template>
 <script setup>

+ 23 - 8
src/content/blocksHandler/handlerPressKey.js

@@ -1,4 +1,4 @@
-import { isXPath, objectHasKey } from '@/utils/helper';
+import { isXPath, objectHasKey, sleep } from '@/utils/helper';
 import { sendMessage } from '@/utils/message';
 import { keyDefinitions } from '@/utils/USKeyboardLayout';
 import { queryElements } from '../handleSelector';
@@ -11,7 +11,7 @@ const modifierKeys = [
   { name: 'Control', id: 2 },
 ];
 
-function pressKeyWithJs(element, keys) {
+async function pressKeyWithJs({ element, keys, pressTime }) {
   const details = {
     key: '',
     code: '',
@@ -24,8 +24,8 @@ function pressKeyWithJs(element, keys) {
     cancelable: true,
   };
 
-  ['keydown', 'keyup'].forEach((event) => {
-    keys.forEach((key) => {
+  for (const event of ['keydown', 'keyup']) {
+    for (const key of keys) {
       const isLetter = /^[a-zA-Z]$/.test(key);
 
       const isModKey = modifierKeys.some(({ name }) => name === key);
@@ -84,10 +84,17 @@ function pressKeyWithJs(element, keys) {
           element[contentKey] += '\r\n';
         }
       }
-    });
-  });
+
+      if (event === 'keyDown' && pressTime > 0) await sleep(pressTime);
+    }
+  }
 }
-async function pressKeyWithCommand(_, keys, activeTabId, actionType) {
+async function pressKeyWithCommand({
+  keys,
+  pressTime,
+  actionType,
+  activeTabId,
+}) {
   const commands = [];
   const events =
     actionType === 'multiple-keys' ? ['keyDown'] : ['keyDown', 'keyUp'];
@@ -130,6 +137,8 @@ async function pressKeyWithCommand(_, keys, activeTabId, actionType) {
 
         commands.push(command.params, secondEvent);
       }
+
+      if (event === 'keyDown' && pressTime > 0) await sleep(pressTime);
     }
   }
 
@@ -160,7 +169,13 @@ async function pressKey({ data, debugMode, activeTabId }) {
       : data.keysToPress.split('');
   const pressKeyFunction = debugMode ? pressKeyWithCommand : pressKeyWithJs;
 
-  await pressKeyFunction(element, keys, activeTabId, data.action);
+  await pressKeyFunction({
+    keys,
+    element,
+    activeTabId,
+    actionType: data.action,
+    pressTime: Number.isNaN(+data.pressTime) ? 0 : +data.pressTime,
+  });
 
   return '';
 }

+ 2 - 1
src/locales/en/blocks.json

@@ -206,7 +206,8 @@
         "actions": {
           "press-key": "Press a key",
           "multiple-keys": "Press multiple keys"
-        }
+        },
+        "press-time": "Press time (milliseconds)"
       },
       "save-assets": {
         "name": "Save assets",

+ 2 - 1
src/locales/en/common.json

@@ -47,7 +47,8 @@
     "password": "Password",
     "category": "Category",
     "optional": "Optional",
-    "0disable": "0 to disable"
+    "0disable": "0 to disable",
+    "millisecond": "millisecond | milliseconds"
   },
   "message": {
     "noBlock": "No block",

+ 1 - 1
src/manifest.firefox.json

@@ -8,7 +8,7 @@
   },
   "background": {
     "scripts": ["background.bundle.js"],
-    "persistent": false
+    "persistent": true
   },
   "browser_action": {
     "default_popup": "popup.html",

+ 1 - 1
src/newtab/pages/settings/SettingsBackup.vue

@@ -416,7 +416,7 @@ async function restoreWorkflows() {
     };
 
     reader.onload = ({ target }) => {
-      const payload = parseJSON(target.result, null);
+      const payload = parseJSON(window.decodeURIComponent(target.result), null);
       if (!payload) return;
 
       const storageTables = parseJSON(payload.storageTables, null);

+ 1 - 0
src/utils/shared.js

@@ -1052,6 +1052,7 @@ export const tasks = {
       disableBlock: false,
       keys: '',
       selector: '',
+      pressTime: 0,
       description: '',
       keysToPress: '',
       action: 'press-key',

+ 1 - 3
src/workflowEngine/WorkflowEngine.js

@@ -308,9 +308,7 @@ class WorkflowEngine {
 
   addRefDataSnapshot(key) {
     this.refDataSnapshotsKeys[key].index += 1;
-    this.refDataSnapshotsKeys[
-      key
-    ].key = `##${key}${this.refDataSnapshotsKeys[key].index}`;
+    this.refDataSnapshotsKeys[key].key = key;
 
     const keyName = this.refDataSnapshotsKeys[key].key;
     this.refDataSnapshots[keyName] = cloneDeep(this.referenceData[key]);

+ 1 - 1
src/workflowEngine/blocksHandler/handlerDelay.js

@@ -1,7 +1,7 @@
 function delay(block) {
   return new Promise((resolve) => {
     const delayTime = +block.data.time || 500;
-
+    console.log(delayTime, 'huh', block);
     setTimeout(() => {
       resolve({
         data: '',

+ 3 - 2
src/workflowEngine/blocksHandler/handlerJavascriptCode.js

@@ -225,8 +225,6 @@ export async function javascriptCode({ outputs, data, ...block }, { refData }) {
 
       if (inputNextBlockId) {
         let customNextBlockId = this.getBlockConnections(inputNextBlockId);
-        if (!customNextBlockId)
-          throw new Error(`Can't find block with "${inputNextBlockId}" id`);
 
         const nextBlock = this.engine.blocks[inputNextBlockId];
         if (!customNextBlockId && nextBlock) {
@@ -239,6 +237,9 @@ export async function javascriptCode({ outputs, data, ...block }, { refData }) {
           ];
         }
 
+        if (!customNextBlockId)
+          throw new Error(`Can't find block with "${inputNextBlockId}" id`);
+
         nextBlockId = customNextBlockId;
       }
     } else {

+ 5 - 0
yarn.lock

@@ -4714,6 +4714,11 @@ jiti@^1.18.2:
   resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.19.3.tgz#ef554f76465b3c2b222dc077834a71f0d4a37569"
   integrity sha512-5eEbBDQT/jF1xg6l36P+mWGGoH9Spuy0PCdSr2dtWRDGC6ph/w9ZCL4lmESW8f8F7MwT3XKescfP0wnZWAKL9w==
 
+js-base64@^3.7.5:
+  version "3.7.5"
+  resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.5.tgz#21e24cf6b886f76d6f5f165bfcd69cc55b9e3fca"
+  integrity sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==
+
 js-tokens@^4.0.0:
   version "4.0.0"
   resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"