Write queue to local storage
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user