Files
jackson-calendar/source/static/script.js
2025-12-01 10:11:40 -08:00

60 lines
1.7 KiB
JavaScript

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);