Explorar o código

feat: add "get tab URL" block

Ahmad Kholid %!s(int64=3) %!d(string=hai) anos
pai
achega
c4baed537e

+ 31 - 0
src/background/workflowEngine/blocksHandler/handlerTabUrl.js

@@ -0,0 +1,31 @@
+import browser from 'webextension-polyfill';
+
+export async function logData({ id, data }) {
+  let urls = [];
+
+  if (data.type === 'active-tab') {
+    if (!this.activeTab.id) throw new Error('no-tab');
+
+    const tab = await browser.tabs.get(this.activeTab.id);
+    urls = tab.url || tab.pendingUrl || '';
+  } else {
+    const tabs = await browser.tabs.query({});
+    urls = tabs.map((tab) => tab.url);
+  }
+
+  console.log(urls, data);
+
+  if (data.assignVariable) {
+    this.setVariable(data.variableName, urls);
+  }
+  if (data.saveData) {
+    this.addDataToColumn(data.dataColumn, urls);
+  }
+
+  return {
+    data: urls,
+    nextBlockId: this.getBlockConnections(id),
+  };
+}
+
+export default logData;

+ 45 - 0
src/components/newtab/workflow/edit/EditTabURL.vue

@@ -0,0 +1,45 @@
+<template>
+  <div>
+    <ui-textarea
+      :model-value="data.description"
+      :placeholder="t('common.description')"
+      class="w-full"
+      @change="updateData({ description: $event })"
+    />
+    <ui-select
+      :model-value="data.type"
+      :label="t('workflow.blocks.tab-url.select')"
+      class="mt-4 w-full"
+      @change="updateData({ type: $event })"
+    >
+      <option v-for="type in types" :key="type" :value="type">
+        {{ t(`workflow.blocks.tab-url.types.${type}`) }}
+      </option>
+    </ui-select>
+    <insert-workflow-data :data="data" variables @update="updateData" />
+  </div>
+</template>
+<script setup>
+import { useI18n } from 'vue-i18n';
+import InsertWorkflowData from './InsertWorkflowData.vue';
+
+const props = defineProps({
+  data: {
+    type: Object,
+    default: () => ({}),
+  },
+});
+const emit = defineEmits(['update:data']);
+
+const types = ['active-tab', 'all'];
+const { t } = useI18n();
+
+function updateData(value) {
+  emit('update:data', { ...props.data, ...value });
+}
+</script>
+<style>
+.log-data .block-variable {
+  margin-top: 4px;
+}
+</style>