YouCount

ページの画像でアクセスカウント表示 Web API。

概要

YouCountはCloudflare Workersで動作するサーバーレス Web API。domainquery parameterでdomainを指定すると、累積访问数をカウントして返す。 こちらのアセットの利用を推奨。

特徴

使用方法

API Endpoint

https://{your-worker-url}/?domain={domain}

Parameters

parameter 説明
domain string カウント対象 domain。必須。

Response

200
Content-Type: text/plain
Access-Control-Allow-Origin: *

123

Example

curl "https://your-worker.example.com/?domain=example.com"
# Output: 1

curl "https://your-worker.example.com/?domain=example.com"
# Output: 2

Architecture

Stack

Data Flow

Request (/domain=example.com)
    ↓
Worker fetch()
    ↓
KV get(domain) → current count取得
    ↓
count += 1
    ↓
KV put(domain, new count)
    ↓
Response (new count) + CORS header

Setup

前提

npm install -D wrangler

Deployment

# Wrangler login
wrangler login

# Deploy
wrangler deploy

Configuration

wrangler.toml:

name = "you-count"
main = "src/index.js"
compatibility_date = "2026-06-04"

kv_namespaces = [
  { binding = "COUNTER", id = "87fb802679de44d189a404558a539e94" }
]

使用例

HTML Image Tag

<!-- カウンター画像として埋め込み -->
<img src="https://your-worker.example.com/?domain=mysite.com" alt="access counter" />

JavaScript

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

License

Apache License 2.0 - See LICENSE

Repository

ams-www/YouCount