-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
98 lines (89 loc) · 2.78 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// //test for github traffic github api
// const repoName = 'AIProf'; // repository name
// //env variable for github access token
// //const accessToken = GH_ACCESS_TOKEN; GitHub access token
// const apiUrl = `https://api.github.com/repos/MeetYourAI/${repoName}/traffic/views`;
// // GitHub API headers with your access token
// const headers = {
// Accept: 'application/vnd.github.v3+json',
// Authorization:'Basic ' + btoa('MeetYourAI' + ':' + accessToken),
// };
// // Fetch traffic data from GitHub API
// fetch(apiUrl, { headers })
// .then((response) => response.json())
// .then((data) => {
// const dates = data.views.map((entry) => new Date(entry.timestamp).getDate() + " / " + (new Date(entry.timestamp).getMonth() + 1) + " / " + new Date(entry.timestamp).getFullYear());
// const counts = data.views.map((entry) => entry.count);
// // Create a chart
// const ctx = document.getElementById('trafficChart').getContext('2d');
// new Chart(ctx, {
// type: 'line',
// data: {
// labels: dates,
// datasets: [
// {
// label: 'Daily Visitors/Views',
// data: counts,
// fill: false,
// borderColor: 'rgba(75, 192, 192, 1)',
// borderWidth: 2,
// },
// ],
// },
// options: {
// scales: {
// x: {
// title: {
// display: true,
// text: 'Dates'
// },
// },
// y: {
// title: {
// display: true,
// text: 'Counts'
// },
// },
// },
// },
// });
// })
// .catch((error) => {
// console.error('Failed to fetch data:', error);
// });
// for contact form post
var form = document.getElementById("contact-us-form");
let submitButton = document.getElementById("submit-btn");
async function handleSubmit(event) {
event.preventDefault();
var status = document.getElementById("contactStatus");
var data = new FormData(event.target);
fetch(event.target.action, {
method: form.method,
body: data,
headers: {
'Accept': 'application/json',
'Access-Control-Allow-Origin': '*',
}
}).then(response => {
if (response.ok) {
document.getElementById("successMessage").style.display = "block";
document.getElementById("errorMessage").style.display = "none";
document.getElementById("contact-us-form").reset();
} else {
response.json().then(data => {
if (Object.hasOwn(data, 'errors')) {
document.getElementById("errorMessage").innerHTML = data["errors"].map(error => error["message"]).join(", ")
} else {
document.getElementById("successMessage").style.display = "none";
document.getElementById("errorMessage").style.display = "block";
}
})
}
}).catch(error => {
console.error("Error:", error);
document.getElementById("successMessage").style.display = "none";
document.getElementById("errorMessage").style.display = "block";
});
}
form.addEventListener(submitButton, handleSubmit);