Switch to async function
This commit is contained in:
@@ -1,48 +1,43 @@
|
|||||||
function handleClick() {
|
async function handleClick() {
|
||||||
browser.tabs.query({currentWindow: true, active: true}).then(handleTabs);
|
const tabs = await browser.tabs.query({currentWindow: true, active: true});
|
||||||
}
|
|
||||||
|
|
||||||
function handleTabs(tabs) {
|
|
||||||
if (tabs.length != 1) {
|
if (tabs.length != 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const tab = tabs[0];
|
||||||
|
|
||||||
handleTab(tabs[0]);
|
const cfg = await browser.storage.sync.get();
|
||||||
}
|
|
||||||
|
|
||||||
function handleTab(tab) {
|
|
||||||
console.log(tab.title, tab.url);
|
|
||||||
const req = {
|
const req = {
|
||||||
data: {
|
data: {
|
||||||
workspace: browser.storage.sync.get('workspace'),
|
workspace: cfg['workspace'],
|
||||||
assignee: browser.storage.sync.get('assignee'),
|
assignee: cfg['assignee'],
|
||||||
name: tab.title,
|
name: tab.title,
|
||||||
notes: tab.url,
|
notes: tab.url,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('-->', req);
|
console.log('-->', req);
|
||||||
|
|
||||||
console.log(browser.tabs);
|
const promiseImg = browser.tabs.captureTab(tab.id);
|
||||||
browser.tabs.captureTab(tab.id).then(img => console.log(img));
|
|
||||||
|
|
||||||
fetch(
|
const promiseCreateResp = fetch(
|
||||||
'https://app.asana.com/api/1.0/tasks',
|
'https://app.asana.com/api/1.0/tasks',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${browser.storage.sync.get('token')}`,
|
'Authorization': `Bearer ${cfg['token']}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(req),
|
body: JSON.stringify(req),
|
||||||
},
|
},
|
||||||
).then(resp => {
|
);
|
||||||
console.log('<--', resp);
|
|
||||||
resp.json().then(js => console.log('<--', js));
|
|
||||||
|
|
||||||
browser.tabs.remove([tab.id]);
|
const img = await promiseImg;
|
||||||
});
|
const createResp = await promiseCreateResp;
|
||||||
|
const create = await createResp.json();
|
||||||
|
|
||||||
|
console.log('<--', create);
|
||||||
|
|
||||||
|
browser.tabs.remove([tab.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.browserAction.onClicked.addListener(handleClick);
|
browser.browserAction.onClicked.addListener(handleClick);
|
||||||
|
|||||||
Reference in New Issue
Block a user