chris265100 commited on
Commit
fe42d9d
·
1 Parent(s): 02f41c7

Connect persistent download request counter to existing TERN website

Browse files
README.md CHANGED
@@ -24,5 +24,10 @@ The website does not execute SQL or provide online EX evaluation. Email
24
  submissions are forwarded through FormSubmit for organizer review. Local file
25
  validation only checks the prediction format.
26
 
 
 
 
 
 
27
  This is a buildless HTML/CSS/JavaScript Space; no Python server, database server,
28
  Docker image, GPU, or package installation is needed to serve the website.
 
24
  submissions are forwarded through FormSubmit for organizer review. Local file
25
  validation only checks the prediction format.
26
 
27
+ Download request statistics are supplied by an API with persistent storage.
28
+ The count covers requests through the tracked website button, excludes HEAD
29
+ and prefetch requests, and does not measure completed file transfers or unique
30
+ people. Historical downloads and direct archive links are not included.
31
+
32
  This is a buildless HTML/CSS/JavaScript Space; no Python server, database server,
33
  Docker image, GPU, or package installation is needed to serve the website.
assets/download-counter-config.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ // Public counter API URL only; no account credentials.
2
+ window.TERN_DOWNLOAD_COUNTER_CONFIG = Object.freeze({
3
+ "enabled": true,
4
+ "apiBase": "https://tern-download-counter.tern-download-counter.workers.dev"
5
+ });
assets/download-counter.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (() => {
2
+ "use strict";
3
+ const config = window.TERN_DOWNLOAD_COUNTER_CONFIG;
4
+ const value = document.querySelector("[data-download-count]");
5
+ const note = document.querySelector(".download-count-note");
6
+ const trigger = document.querySelector(".download-count-trigger");
7
+ const download = document.querySelector("a.button-download");
8
+ if (!value || !note || !trigger || !download || !config || config.enabled !== true) return;
9
+ let base;
10
+ try {
11
+ base = new URL(config.apiBase);
12
+ if (base.protocol !== "https:" || base.username || base.password || base.search || base.hash) return;
13
+ base.pathname = "/";
14
+ } catch (_) { return; }
15
+
16
+ const original = download.getAttribute("href");
17
+ let pending = null, lastRead = 0;
18
+ async function refresh() {
19
+ if (pending || Date.now() - lastRead < 5000) return pending;
20
+ pending = (async () => {
21
+ const controller = new AbortController();
22
+ const timeout = setTimeout(() => controller.abort(), 5000);
23
+ try {
24
+ const response = await fetch(new URL("api/downloads", base).href,
25
+ { signal: controller.signal, credentials: "omit", cache: "no-store" });
26
+ if (!response.ok) throw new Error("statistics_unavailable");
27
+ const data = await response.json();
28
+ if (!Number.isSafeInteger(data.downloads) || data.downloads < 0) throw new Error("invalid_count");
29
+ const began = new Date(data.counting_started_at);
30
+ if (!Number.isFinite(began.getTime())) throw new Error("invalid_start_date");
31
+ value.textContent = new Intl.NumberFormat("en-US").format(data.downloads);
32
+ note.textContent = "Since " + began.toLocaleDateString("en-US", {
33
+ timeZone: "Asia/Shanghai", year: "numeric", month: "short", day: "numeric"
34
+ });
35
+ download.href = new URL("download", base).href;
36
+ lastRead = Date.now();
37
+ } catch (_) {
38
+ value.textContent = "—";
39
+ note.textContent = "Statistics temporarily unavailable";
40
+ download.setAttribute("href", original);
41
+ } finally { clearTimeout(timeout); pending = null; }
42
+ })();
43
+ return pending;
44
+ }
45
+ trigger.addEventListener("pointerenter", refresh);
46
+ trigger.addEventListener("focus", refresh);
47
+ refresh();
48
+ })();
index.html CHANGED
@@ -11,6 +11,8 @@
11
  <script defer src="assets/submission-config.js"></script>
12
  <script defer src="assets/email-submission.js"></script>
13
  <script defer src="assets/app.js"></script>
 
 
14
  </head>
15
  <body data-page="home">
16
  <a class="skip-link" href="#main">Skip to content</a>
@@ -50,7 +52,7 @@
50
  <span class="download-status" id="dataset-download-status">ZIP · 526 MB</span>
51
  <span class="download-count-hint">
52
  <button type="button" class="download-count-trigger" aria-label="Download statistics" aria-describedby="dataset-download-count"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="8.5"/><path d="M12 11v5M12 7.5h.01"/></svg></button>
53
- <span class="download-count-tooltip" id="dataset-download-count" role="tooltip"><span>Total downloads</span><strong data-download-count>—</strong><span class="download-count-note">Count not available yet</span></span>
54
  </span>
55
  </span>
56
  </div>
 
11
  <script defer src="assets/submission-config.js"></script>
12
  <script defer src="assets/email-submission.js"></script>
13
  <script defer src="assets/app.js"></script>
14
+ <script defer src="assets/download-counter-config.js?v=20261117-1"></script>
15
+ <script defer src="assets/download-counter.js?v=20261117-1"></script>
16
  </head>
17
  <body data-page="home">
18
  <a class="skip-link" href="#main">Skip to content</a>
 
52
  <span class="download-status" id="dataset-download-status">ZIP · 526 MB</span>
53
  <span class="download-count-hint">
54
  <button type="button" class="download-count-trigger" aria-label="Download statistics" aria-describedby="dataset-download-count"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="8.5"/><path d="M12 11v5M12 7.5h.01"/></svg></button>
55
+ <span class="download-count-tooltip" id="dataset-download-count" role="tooltip"><span>Download requests</span><strong data-download-count>—</strong><span class="download-count-note">Count not available yet</span></span>
56
  </span>
57
  </span>
58
  </div>
manifest.json CHANGED
@@ -28,11 +28,26 @@
28
  "bytes": 53,
29
  "sha256": "681f23cee4c3bf590cd02218ddf0820d9a8f7233f030cf4ba2e4c9dedeecc779"
30
  },
 
 
 
 
 
31
  {
32
  "path": "assets/app.js",
33
  "bytes": 23517,
34
  "sha256": "c0fb4710174953beb909102fda0700497fb3867eeae9f06d28afefc6618dd416"
35
  },
 
 
 
 
 
 
 
 
 
 
36
  {
37
  "path": "assets/email-submission.js",
38
  "bytes": 4622,
@@ -80,19 +95,14 @@
80
  },
81
  {
82
  "path": "index.html",
83
- "bytes": 19482,
84
- "sha256": "49e6ae7e887b61c0245779c374a83f2dfbcff94653f0d6836ffba86869ea4cdf"
85
  },
86
  {
87
  "path": "leaderboard.html",
88
  "bytes": 428,
89
  "sha256": "28531197b0811ecd2e33c7052f6c5b9be9e59fafb98c258e2de2f4f673feaaa0"
90
  },
91
- {
92
- "path": "README.md",
93
- "bytes": 1151,
94
- "sha256": "20bdd82c5ad58fe2a73b97e47fd1e3320a813b6d056bcfc99cb8f4d4e7be6d0e"
95
- },
96
  {
97
  "path": "submit.html",
98
  "bytes": 408,
@@ -113,5 +123,13 @@
113
  "bytes": 651,
114
  "sha256": "e0d1d02fc91b32faba2f4a669ac3ddd049c9bac8d1cebf253f330296aecefb51"
115
  }
116
- ]
 
 
 
 
 
 
 
 
117
  }
 
28
  "bytes": 53,
29
  "sha256": "681f23cee4c3bf590cd02218ddf0820d9a8f7233f030cf4ba2e4c9dedeecc779"
30
  },
31
+ {
32
+ "path": "README.md",
33
+ "bytes": 1460,
34
+ "sha256": "a62bf229595614b7e5f8050014eb01a9be70b676c895239603616913390406aa"
35
+ },
36
  {
37
  "path": "assets/app.js",
38
  "bytes": 23517,
39
  "sha256": "c0fb4710174953beb909102fda0700497fb3867eeae9f06d28afefc6618dd416"
40
  },
41
+ {
42
+ "path": "assets/download-counter-config.js",
43
+ "bytes": 217,
44
+ "sha256": "023d02e74bd9eb8a6dae39e857610a9f028e6b0c81b39596e0aabad53217e2e2"
45
+ },
46
+ {
47
+ "path": "assets/download-counter.js",
48
+ "bytes": 2224,
49
+ "sha256": "20f06a38f89897ec5584ce5178dfb73ab5de49e5043b8920ff67ab63500fbde9"
50
+ },
51
  {
52
  "path": "assets/email-submission.js",
53
  "bytes": 4622,
 
95
  },
96
  {
97
  "path": "index.html",
98
+ "bytes": 19637,
99
+ "sha256": "79608e20ed94e701144dc9b5f21d05eaf7c1bc2fee59bb4992446f35fae532dd"
100
  },
101
  {
102
  "path": "leaderboard.html",
103
  "bytes": 428,
104
  "sha256": "28531197b0811ecd2e33c7052f6c5b9be9e59fafb98c258e2de2f4f673feaaa0"
105
  },
 
 
 
 
 
106
  {
107
  "path": "submit.html",
108
  "bytes": 408,
 
123
  "bytes": 651,
124
  "sha256": "e0d1d02fc91b32faba2f4a669ac3ddd049c9bac8d1cebf253f330296aecefb51"
125
  }
126
+ ],
127
+ "download_statistics": {
128
+ "enabled": true,
129
+ "api_base": "https://tern-download-counter.tern-download-counter.workers.dev",
130
+ "metric": "download_requests",
131
+ "counting_started_at": "2026-11-17T10:47:25.727Z",
132
+ "historical_downloads_included": false,
133
+ "completed_transfers_measured": false
134
+ }
135
  }