From 2d1e7e426e27d6e5bb8d983ff2ac2e5f84511904 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 18 Oct 2022 00:02:09 -0700 Subject: [PATCH] Write queue to local storage --- background.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/background.js b/background.js index 8c0e760..54e989d 100644 --- a/background.js +++ b/background.js @@ -1,7 +1,21 @@ const reData = new RegExp('^data:(.*?);base64,(.*)$'); async function handleClick(tab, e) { - const promiseImgURL = browser.tabs.captureTab(tab.id); + const imgURL = await browser.tabs.captureTab(tab.id); + const [_, imgType, imgBase64] = imgURL.match(reData); + const img = atob(imgBase64); + + const store = {}; + store[`create_${crypto.randomUUID()}`] = { + title: tab.title, + url: tab.url, + imgURL: imgURL, + }; + await browser.storage.local.set(store); + + if (!e.modifiers.includes('Command')) { + browser.tabs.remove([tab.id]); + } const cfg = await browser.storage.sync.get(); const req = { @@ -12,9 +26,8 @@ async function handleClick(tab, e) { notes: tab.url, }, }; - console.log('-->', req); - const promiseCreateResp = fetch( + const createResp = await fetch( 'https://app.asana.com/api/1.0/tasks', { method: 'POST', @@ -26,21 +39,8 @@ async function handleClick(tab, e) { body: JSON.stringify(req), }, ); - - const imgURL = await promiseImgURL; - const [_, imgType, imgBase64] = imgURL.match(reData); - const img = atob(imgBase64); - - // All tab info captured - if (!e.modifiers.includes('Command')) { - browser.tabs.remove([tab.id]); - } - - const createResp = await promiseCreateResp; const create = await createResp.json(); - console.log('<--', create); - const imgBytes = new Uint8Array(img.length); for (let i = 0; i < img.length; i++) { imgBytes[i] = img.charCodeAt(i);