Skip to content

基于Cloudflare Workers的通用访问计数器xykt/Hits

Published:

原文链接


Hits! - General purpose hits counter based on Cloudflare Workers (中文说明

license

Hits! A completely free, serverless, lightweight access counter system based on Cloudflare Workers and D1 SQL Database, supporting JSON and GitHub-style SVG images, with quick deployment in just one minute

✨ Features

🛠 Quick Deployment Guide

1. Create D1 Database

Go to the Cloudflare Dashboard, navigate to Storage & Databases > D1 SQL Database > Create, name it hits, and run the following SQL to create the table in Console

CREATE TABLE counters ( name TEXT PRIMARY KEY, count INTEGER DEFAULT 0 );

2. Create Workers

Navigate to Workers & Pages > Create application > Create Worker, name it hits. Copy the hit.js code into the Worker editor. Modify line 7 to change the domain to your counter’s domain, and set the keywords in line 8. Each counter corresponds to a keyword. For subsequent counters, simply add new keywords for them.

3. Configure Bindings

In the Worker Settings > Bindings > Add > D1 Database, enter the variable name as HITS, and select the hits database. In Domains & Routes - Add - Custom domain, add your newly configured counter domain.

4. How to Use

https://your.domain/keyword.svg?action=view&count_bg=%233DC8C0&title_bg=%23555555&title=Visits&edge_flat=false
ParameterValuesDescription说明
actionview / hitView only or hit & view仅展示/点击并展示
count_bg%23{colorcode}Background color of count area数字部分背景颜色
title_bg%23{colorcode}Background color of title area标题部分背景颜色
titleTitleToShowText to display展示标题
edge_flattrue / falseSharp or rounded corners尖角/圆角
StylesBlackGrayBlueGreenPurpleRed
Red123456
Orange789101112
Yellow131415161718
Green192021222324
Blue252627282930
Purple313233343536
Gray373839404142
RequestDescription说明
https://your.domain/keyword?action=viewView only仅展示
https://your.domain/keyword?action=hitHit & View点击并展示

JSON Response

{
  "counter": "keyword",
  "action": "hit",
  "total": 1024,
  "daily": 64,
  "date": "2025-03-25",
  "timestamp": "2025-03-25T09:50:53.096Z"
}

Acknowledgements

Welcome to submit Pull Request or Issue!


Previous Post
Sanic: 快速构建和运行高效的Web应用程序
Next Post
Spark-TTS:一个高效的基于LLM的文本转语音模型推理代码