|
@@ -244,38 +244,37 @@ function messageListener({ data, source }) {
|
|
|
});
|
|
|
})();
|
|
|
|
|
|
-// Auto install only works on Chrome
|
|
|
-async function autoInstall() {
|
|
|
- const link = window.location.href;
|
|
|
- if (/.+\.automa\.json$/.test(link)) {
|
|
|
- const accept = window.confirm(
|
|
|
- 'Do you want to add this workflow into Automa?'
|
|
|
- );
|
|
|
- if (!accept) return;
|
|
|
- const workflow = JSON.parse(document.body.innerText);
|
|
|
-
|
|
|
- const { workflows: workflowsStorage } = await browser.storage.local.get(
|
|
|
- 'workflows'
|
|
|
- );
|
|
|
-
|
|
|
- const workflowId = nanoid();
|
|
|
- const workflowData = {
|
|
|
- ...workflow,
|
|
|
- id: workflowId,
|
|
|
- dataColumns: [],
|
|
|
- createdAt: Date.now(),
|
|
|
- table: workflow.table || workflow.dataColumns,
|
|
|
- };
|
|
|
-
|
|
|
- if (Array.isArray(workflowsStorage)) {
|
|
|
- workflowsStorage.push(workflowData);
|
|
|
- } else {
|
|
|
- workflowsStorage[workflowId] = workflowData;
|
|
|
- }
|
|
|
+window.addEventListener('DOMContentLoaded', async () => {
|
|
|
+ const link = window.location.pathname;
|
|
|
+ const isAutomaWorkflow = /.+\.automa\.json$/.test(link);
|
|
|
+ if (!isAutomaWorkflow) return;
|
|
|
+
|
|
|
+ const accept = window.confirm(
|
|
|
+ 'Do you want to add this workflow into Automa?'
|
|
|
+ );
|
|
|
+ if (!accept) return;
|
|
|
+ const workflow = JSON.parse(document.documentElement.innerText);
|
|
|
+
|
|
|
+ const { workflows: workflowsStorage } = await browser.storage.local.get(
|
|
|
+ 'workflows'
|
|
|
+ );
|
|
|
+
|
|
|
+ const workflowId = nanoid();
|
|
|
+ const workflowData = {
|
|
|
+ ...workflow,
|
|
|
+ id: workflowId,
|
|
|
+ dataColumns: [],
|
|
|
+ createdAt: Date.now(),
|
|
|
+ table: workflow.table || workflow.dataColumns,
|
|
|
+ };
|
|
|
+
|
|
|
+ if (Array.isArray(workflowsStorage)) {
|
|
|
+ workflowsStorage.push(workflowData);
|
|
|
+ } else {
|
|
|
+ workflowsStorage[workflowId] = workflowData;
|
|
|
+ }
|
|
|
|
|
|
- await browser.storage.local.set({ workflows: workflowsStorage });
|
|
|
+ await browser.storage.local.set({ workflows: workflowsStorage });
|
|
|
|
|
|
- alert('Workflow installed');
|
|
|
- }
|
|
|
-}
|
|
|
-autoInstall();
|
|
|
+ alert('Workflow installed');
|
|
|
+});
|