2022-10-17 09:58:11 -07:00
|
|
|
async function handleClick() {
|
|
|
|
|
const tabs = await browser.tabs.query({currentWindow: true, active: true});
|
2022-10-13 11:09:24 -07:00
|
|
|
if (tabs.length != 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-17 09:58:11 -07:00
|
|
|
const tab = tabs[0];
|
2022-10-13 11:09:24 -07:00
|
|
|
|
2022-10-17 09:58:11 -07:00
|
|
|
const cfg = await browser.storage.sync.get();
|
2022-10-13 11:09:24 -07:00
|
|
|
const req = {
|
|
|
|
|
data: {
|
2022-10-17 09:58:11 -07:00
|
|
|
workspace: cfg['workspace'],
|
|
|
|
|
assignee: cfg['assignee'],
|
2022-10-13 11:09:24 -07:00
|
|
|
name: tab.title,
|
|
|
|
|
notes: tab.url,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
console.log('-->', req);
|
|
|
|
|
|
2022-10-17 09:58:11 -07:00
|
|
|
const promiseImg = browser.tabs.captureTab(tab.id);
|
2022-10-13 11:09:24 -07:00
|
|
|
|
2022-10-17 09:58:11 -07:00
|
|
|
const promiseCreateResp = fetch(
|
2022-10-13 11:09:24 -07:00
|
|
|
'https://app.asana.com/api/1.0/tasks',
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
2022-10-17 09:58:11 -07:00
|
|
|
'Authorization': `Bearer ${cfg['token']}`,
|
2022-10-13 11:09:24 -07:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(req),
|
|
|
|
|
},
|
2022-10-17 09:58:11 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const img = await promiseImg;
|
|
|
|
|
const createResp = await promiseCreateResp;
|
|
|
|
|
const create = await createResp.json();
|
|
|
|
|
|
|
|
|
|
console.log('<--', create);
|
|
|
|
|
|
|
|
|
|
browser.tabs.remove([tab.id]);
|
2022-10-13 11:09:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
browser.browserAction.onClicked.addListener(handleClick);
|