ページの画像でアクセスカウント表示 Web API。
YouCountはCloudflare Workersで動作するサーバーレス Web API。domainquery parameterでdomainを指定すると、累積访问数をカウントして返す。
こちらのアセットの利用を推奨。
https://{your-worker-url}/?domain={domain}
| parameter | 型 | 説明 |
|---|---|---|
domain |
string | カウント対象 domain。必須。 |
200
Content-Type: text/plain
Access-Control-Allow-Origin: *
123
no domain error(400)curl "https://your-worker.example.com/?domain=example.com"
# Output: 1
curl "https://your-worker.example.com/?domain=example.com"
# Output: 2
wrangler.toml)Request (/domain=example.com)
↓
Worker fetch()
↓
KV get(domain) → current count取得
↓
count += 1
↓
KV put(domain, new count)
↓
Response (new count) + CORS header
npm install -D wrangler
# Wrangler login
wrangler login
# Deploy
wrangler deploy
wrangler.toml:
name = "you-count"
main = "src/index.js"
compatibility_date = "2026-06-04"
kv_namespaces = [
{ binding = "COUNTER", id = "87fb802679de44d189a404558a539e94" }
]
COUNTER: KV namespace binding。domain毎のアクセスカウント管理。<!-- カウンター画像として埋め込み -->
<img src="https://your-worker.example.com/?domain=mysite.com" alt="access counter" />
async function getAccessCount() {
const response = await fetch('https://your-worker.example.com/?domain=mysite.com');
const count = await response.text();
console.log('Access count:', count);
}
Apache License 2.0 - See LICENSE