-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (44 loc) · 1.55 KB
/
index.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
42
43
44
45
46
47
48
49
50
// get the token from URL parameters and send it to notion to get an auth token
// then send that token to the extension
const authorize_notion = async () => {
const url = new URL(window.location.href);
const searchParams = new URLSearchParams(url.searchParams);
const temp_auth_code = searchParams.get("code");
const req_body = {
code: temp_auth_code,
};
if (temp_auth_code != undefined) {
try {
const response = await fetch(
"https://arxivtonotion.herokuapp.com/auth",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(req_body),
}
);
const notion_auth_data = await response.json();
send_to_extension(notion_auth_data);
$("#auth-successful").show();
} catch (err) {
console.log(err);
$("#auth-unsuccessful").show();
}
} else {
$("#auth-unsuccessful").show();
console.log("error in url parameters");
}
};
const send_to_extension = (data) => {
const extension_id = "bgkglfpmfopkikgchgdmkppjebbhincc";
chrome.runtime.sendMessage(extension_id, data, (response) => {
if (response != "auth data set successfully") {
throw Error("Invalid response from chrome-extension: ", response);
}
});
};
document.addEventListener("DOMContentLoaded", async () => {
await authorize_notion();
});