Initial Commit
This commit is contained in:
59
source/static/script.js
Normal file
59
source/static/script.js
Normal file
@@ -0,0 +1,59 @@
|
||||
let token = "womwpomwp";
|
||||
let calendar_id = "wompwomp";
|
||||
let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
const client = google.accounts.oauth2.initTokenClient({
|
||||
client_id:
|
||||
"1000685713819-om0gq7bqr3e91f2rok224ooqgae6bojg.apps.googleusercontent.com",
|
||||
scope: "https://www.googleapis.com/auth/calendar",
|
||||
callback: (tokenResponse) => {
|
||||
if (tokenResponse && tokenResponse.access_token) {
|
||||
token = tokenResponse.access_token;
|
||||
fetch("/calendar/getCalendarId", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ token: token, timezone: timezone }),
|
||||
headers: { "Content-type": "application/json" },
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
calendar_id = json["calendar_id"];
|
||||
})
|
||||
.then(() => {
|
||||
send_request();
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function handle_form(event) {
|
||||
event.preventDefault();
|
||||
send_request();
|
||||
}
|
||||
|
||||
function send_request() {
|
||||
let input_value = document.forms["chatbox"]["msg-input"].value;
|
||||
|
||||
content_output = document.getElementById("content");
|
||||
|
||||
fetch("/calendar/execute", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: token,
|
||||
calendar_id: calendar_id,
|
||||
timezone: timezone,
|
||||
input: input_value,
|
||||
}),
|
||||
headers: { "Content-type": "application/json" },
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
if (json["output"] != "verify") {
|
||||
content_output.innerHTML += `>>> ${input_value}<br>>>> ${json["output"]}<br><br>`;
|
||||
document.forms["chatbox"]["msg-input"].value = "";
|
||||
} else {
|
||||
client.requestAccessToken();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.forms["chatbox"].addEventListener("submit", handle_form);
|
||||
Reference in New Issue
Block a user