-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (85 loc) Β· 4.43 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenCounterAPI localhost Test</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin: 40px; }
.badge { color: white; padding: 5px 10px; border-radius: 8px; font-weight: bold; display: inline-block; margin: 5px; }
.red { background: linear-gradient(45deg, rgba(255, 78, 80, 0.8), rgba(249, 212, 35, 0.8)); }
.blue { background: linear-gradient(45deg, rgba(54, 209, 220, 0.8), rgba(91, 134, 229, 0.8)); }
.green { background: linear-gradient(45deg, rgba(17, 153, 142, 0.8), rgba(56, 239, 125, 0.8)); }
.yellow { background: linear-gradient(45deg, rgba(255, 165, 0.8), rgba(255, 215, 0.8)); }
.purple { background: linear-gradient(45deg, rgba(138, 43, 226, 0.8), rgba(75, 0, 130, 0.8)); }
table { width: 60%; margin: 20px auto; border-collapse: collapse; }
th, td { border: 1px solid #ccc; padding: 8px; }
th { background: #f4f4f4; }
pre { background: #eee; padding: 10px; border-radius: 5px; text-align: left; }
</style>
</head>
<body>
<h2>π OpenCounterAPI localhost Test Page</h2>
<p>This page tests the API by sending a request and displaying the statistical data.</p>
<p>Use this API, which is always available.</p>
<p><strong>https://api.learntogoogle.de/api/counter</strong></p>
<div>
<span id="now" class="badge red">Now: Loading...</span>
<span id="today" class="badge blue">Today: Loading...</span>
<span id="week" class="badge green">Week: Loading...</span>
<span id="month" class="badge yellow">Month: Loading...</span>
<span id="user_uniq" class="badge purple">Unique Users: Loading...</span>
</div>
<table>
<tr><th>Statistic</th><th>Value</th></tr>
<tr><td>Total Visits</td><td id="totalVisits">Loading...</td></tr>
<tr><td>Unique Users</td><td id="uniqueUsers">Loading...</td></tr>
<tr><td>Now</td><td id="table_now">Loading...</td></tr>
<tr><td>Today</td><td id="table_today">Loading...</td></tr>
<tr><td>This Week</td><td id="table_week">Loading...</td></tr>
<tr><td>This Month</td><td id="table_month">Loading...</td></tr>
</table>
<h3>π cURL POST Request Example:</h3>
<pre>
curl -X POST "https://api.learntogoogle.de/api/counter" \
-H "Content-Type: application/json" \
-d '{"page_name": "api_test_page_learntogoogle.de"}'
</pre>
<h3>π Raw Data:</h3>
<pre id="rawData">Loading...</pre>
<script>
async function fetchStats() {
const pageName = "github_test_page";
const response = await fetch("https://api.learntogoogle.de/api/counter", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ page_name: pageName })
});
if (!response.ok) {
document.getElementById("rawData").innerText = "Error loading data!";
return;
}
const data = await response.json();
console.log("API Response:", data);
const now = data.date_stats?.now?.[0] || 0;
const today = data.date_stats?.today?.[0] || 0;
const week = data.date_stats?.week?.[0] || 0;
const month = data.date_stats?.month?.[0] || 0;
const userUniq = data.user_uniq || 0;
document.getElementById("now").innerText = `Now: ${now}`;
document.getElementById("today").innerText = `Today: ${today}`;
document.getElementById("week").innerText = `Week: ${week}`;
document.getElementById("month").innerText = `Month: ${month}`;
document.getElementById("user_uniq").innerText = `Unique Users: ${userUniq}`;
document.getElementById("totalVisits").innerText = data.user_count_sum;
document.getElementById("uniqueUsers").innerText = userUniq;
document.getElementById("table_now").innerText = now;
document.getElementById("table_today").innerText = today;
document.getElementById("table_week").innerText = week;
document.getElementById("table_month").innerText = month;
document.getElementById("rawData").innerText = JSON.stringify(data, null, 2);
}
fetchStats();
</script>
</body>
</html>