Skip to content
/ Hits Public

General purpose hits counter (GitHub / Shields.io style) based on Cloudflare Workers & D1

License

Notifications You must be signed in to change notification settings

xykt/Hits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 (Shields.io) style SVG images, with quick deployment in just one minute

✨ Features

  • 🚀 Quick Deployment - Deploy in just one minute
  • ☁️ Cloud Hosting - No server maintenance required
  • 💰 Completely Free - Utilizes Cloudflare's free plan
  • 📊 Multi-Site Support - Supports multiple counters via different keywords
  • 🔒 Secure and Reliable - Powered by Cloudflare's global network
  • 🎨 Colorful Display - Supports customizable color SVG and JSON output

🛠 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

  • SVG Image
https://your.domain/keyword.svg?action=view&count_bg=%233DC8C0&title_bg=%23555555&title=Visits&edge_flat=false
Parameter Values Description 说明
action view / hit View only or hit & view 仅展示/点击并展示
count_bg %23{colorcode} Background color of count area 数字部分背景颜色
title_bg %23{colorcode} Background color of title area 标题部分背景颜色
title TitleToShow Text to display 展示标题
edge_flat true / false Sharp or rounded corners 尖角/圆角
Shields.io Presets Aliases Hits! Counter Example Shields.io Example
count_bg=brightgreen success brightgreen shields-brightgreen
count_bg=green green shields-green
count_bg=yellow yellow shields-yellow
count_bg=yellowgreen yellowgreen shields-yellowgreen
count_bg=orange important orange shields-orange
count_bg=red critical red shields-red
count_bg=blue informational blue shields-blue
count_bg=grey gray grey shields-grey
count_bg=lightgrey lightgray inactive lightgrey shields-lightgrey
Custom Black Gray Blue Green Purple Red
Red 1 2 3 4 5 6
Orange 7 8 9 10 11 12
Yellow 13 14 15 16 17 18
Green 19 20 21 22 23 24
Blue 25 26 27 28 29 30
Purple 31 32 33 34 35 36
Gray 37 38 39 40 41 42
  • JSON Result
Request Description 说明
https://your.domain/keyword?action=view View only 仅展示
https://your.domain/keyword?action=hit Hit & View 点击并展示

JSON Response

{
  "counter": "keyword",
  "action": "hit",
  "total": 1024,
  "daily": 32,
  "date": "2025-03-31",
  "timestamp": "2025-03-31T04:08:16.512Z"
}

Acknowledgements

Welcome to submit Pull Request or Issue!

About

General purpose hits counter (GitHub / Shields.io style) based on Cloudflare Workers & D1

Resources

License

Stars

Watchers

Forks