Ahmad Kholid 1 year ago
parent
commit
4f28146451

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "automa",
-  "version": "1.28.5",
+  "version": "1.28.6",
   "description": "An extension for automating your browser by connecting blocks",
   "repository": {
     "type": "git",

+ 22 - 1
src/components/newtab/workflow/edit/EditAttributeValue.vue

@@ -1,7 +1,17 @@
 <template>
   <edit-interaction-base v-bind="{ data }" @change="updateData">
     <hr />
-    <edit-autocomplete>
+    <ui-select
+      :label="t('common.action')"
+      :model-value="data.action || 'get'"
+      class="mt-2 w-full"
+      @change="updateData({ action: $event })"
+    >
+      <option v-for="action in ['get', 'set']" :key="action" :value="action">
+        {{ t(`workflow.blocks.attribute-value.forms.action.${action}`) }}
+      </option>
+    </ui-select>
+    <edit-autocomplete class="mt-2">
       <ui-input
         :model-value="data.attributeName"
         :label="t('workflow.blocks.attribute-value.forms.name')"
@@ -11,7 +21,18 @@
         @change="updateData({ attributeName: $event })"
       />
     </edit-autocomplete>
+    <edit-autocomplete v-if="data.action === 'set'" class="mt-2">
+      <ui-input
+        :model-value="data.attributeValue"
+        :label="t('workflow.blocks.attribute-value.forms.value')"
+        autocomplete="off"
+        placeholder="value"
+        class="w-full"
+        @change="updateData({ attributeValue: $event })"
+      />
+    </edit-autocomplete>
     <insert-workflow-data
+      v-else
       :data="data"
       extra-row
       variables

+ 8 - 3
src/content/blocksHandler/handlerAttributeValue.js

@@ -1,9 +1,9 @@
 import handleSelector from '../handleSelector';
 
-function attributeValue(block) {
+function handleAttributeValue(block) {
   return new Promise((resolve, reject) => {
     let result = [];
-    const { attributeName, multiple } = block.data;
+    const { attributeName, multiple, attributeValue, action } = block.data;
     const isCheckboxOrRadio = (element) => {
       if (element.tagName !== 'INPUT') return false;
 
@@ -12,6 +12,11 @@ function attributeValue(block) {
 
     handleSelector(block, {
       onSelected(element) {
+        if (action === 'set') {
+          element.setAttribute(attributeName, attributeValue);
+          return;
+        }
+
         let value = element.getAttribute(attributeName);
 
         if (attributeName === 'checked' && isCheckboxOrRadio(element)) {
@@ -33,4 +38,4 @@ function attributeValue(block) {
   });
 }
 
-export default attributeValue;
+export default handleAttributeValue;

+ 5 - 0
src/locales/en/blocks.json

@@ -586,6 +586,11 @@
           "name": "Attribute name",
           "checkbox": "Insert to table",
           "column": "Select column",
+          "value": "Attribute value",
+          "action": {
+            "get": "Get attribute value",
+            "set": "Set attribute value"
+          },
           "extraRow": {
             "checkbox": "Add extra row",
             "placeholder": "Value",

+ 39 - 11
src/utils/shared.js

@@ -241,7 +241,7 @@ export const tasks = {
     outputs: 1,
     maxConnection: 1,
     allowedInputs: true,
-    refDataKeys: ['fileName', 'selector'],
+    refDataKeys: ['fileName', 'selector', 'variableName'],
     autocomplete: ['variableName'],
     data: {
       description: '',
@@ -332,7 +332,13 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['selector', 'prefixText', 'suffixText', 'extraRowValue'],
+    refDataKeys: [
+      'selector',
+      'variableName',
+      'prefixText',
+      'suffixText',
+      'extraRowValue',
+    ],
     autocomplete: ['variableName'],
     data: {
       disableBlock: false,
@@ -368,7 +374,7 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['name'],
+    refDataKeys: ['name', 'variableName'],
     data: {
       disableBlock: false,
       name: '',
@@ -445,7 +451,13 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['selector', 'attributeName', 'extraRowValue'],
+    refDataKeys: [
+      'selector',
+      'variableName',
+      'attributeName',
+      'extraRowValue',
+      'attributeValue',
+    ],
     autocomplete: ['variableName'],
     data: {
       disableBlock: false,
@@ -456,11 +468,13 @@ export const tasks = {
       selector: '',
       markEl: false,
       multiple: false,
+      attributeValue: '',
       attributeName: '',
       assignVariable: false,
       variableName: '',
       dataColumn: '',
       saveData: true,
+      action: 'get',
       addExtraRow: false,
       extraRowValue: '',
       extraRowDataColumn: '',
@@ -477,7 +491,13 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['selector', 'value', 'optionPosition', 'delay'],
+    refDataKeys: [
+      'selector',
+      'variableName',
+      'value',
+      'optionPosition',
+      'delay',
+    ],
     autocomplete: ['variableName'],
     data: {
       disableBlock: false,
@@ -577,7 +597,7 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['customData', 'range', 'spreadsheetId'],
+    refDataKeys: ['customData', 'range', 'spreadsheetId', 'variableName'],
     autocomplete: ['refKey'],
     data: {
       disableBlock: false,
@@ -609,7 +629,13 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['customData', 'range', 'spreadsheetId', 'sheetName'],
+    refDataKeys: [
+      'customData',
+      'range',
+      'spreadsheetId',
+      'sheetName',
+      'variableName',
+    ],
     autocomplete: ['refKey'],
     data: {
       disableBlock: false,
@@ -705,7 +731,7 @@ export const tasks = {
     outputs: 2,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['body', 'url'],
+    refDataKeys: ['body', 'url', 'variableName'],
     autocomplete: ['variableName'],
     data: {
       disableBlock: false,
@@ -879,7 +905,7 @@ export const tasks = {
     allowedInputs: true,
     maxConnection: 1,
     autocomplete: ['variableName'],
-    refDataKeys: ['dataToCopy'],
+    refDataKeys: ['dataToCopy', 'variableName'],
     data: {
       disableBlock: false,
       description: '',
@@ -984,7 +1010,7 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['selector', 'url', 'filename'],
+    refDataKeys: ['selector', 'url', 'filename', 'variableName'],
     data: {
       disableBlock: false,
       description: '',
@@ -1058,7 +1084,7 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['filename', 'downloadId'],
+    refDataKeys: ['filename', 'downloadId', 'variableName'],
     autocomplete: ['variableName'],
     data: {
       disableBlock: false,
@@ -1178,6 +1204,7 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
+    refDataKeys: ['variableName'],
     data: {
       disableBlock: false,
       description: '',
@@ -1344,6 +1371,7 @@ export const tasks = {
       'url',
       'value',
       'jsonCode',
+      'variableName',
     ],
     data: {
       disableBlock: false,

+ 1 - 1
src/workflowEngine/utils/testConditions.js

@@ -95,7 +95,7 @@ export default async function (conditionsArr, workflowData) {
         newRefData[keyword] = workflowData.refData[keyword];
       });
 
-      if (workflowData.isMV2) {
+      if (workflowData.isMV2 && data.context !== 'background') {
         conditionValue = await workflowData.sendMessage({
           type: 'condition-builder',
           data: {