-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
41 lines (37 loc) · 1.08 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// function onExecuted(result) {
// console.log(`We executed in tab`);
// }
//
// function onError(error) {
// console.log(`Error: ${error}`);
// }
//
// const executing = browser.tabs.executeScript(
// tab.id;
// {
// file: "/main.js"
// });
// executing.then(onExecuted, onError);
// function getTabId() {
// const logCurrentTabData = (tabs) => { currentTab = tabs[0]; return currentTab.tabId()};
// var tabId = tabs.query({active:true, currentWindow: true}).then(logCurrentTabData);
// return tabId;
// }
window.onload = function() {
document.getElementById("add_button").addEventListener("click", scrape_init);
console.log("added listener");
}
async function getCurrentTabId() {
let queryOptions = {
active: true,
currentWindow: true
};
let [tab] = await chrome.tabs.query(queryOptions);
return tab.id;
}
async function scrape_init() {
await chrome.scripting.executeScript({
target: {tabId: (await getCurrentTabId())},
files: ["main.js"]
}).then(() => console.log("script injected"));
};