Giter Site home page Giter Site logo

mikejerred / view-counter-badge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aveek-saha/view-counter-badge

0.0 0.0 0.0 43 KB

๐Ÿ“ˆ A badge to count the number of visitors to your page

Home Page: https://view-counter.aveek.workers.dev

License: MIT License

JavaScript 100.00%

view-counter-badge's Introduction

View Counter Badge

View counter badge

Count how many visitors any page gets. A simple solution to add a view counter badge to your readme files or web page.

Usage

The view counter badge is meant to be deployed individually for each profile/user. Click the button and then follow the steps below to deploy your own view counter in no time!

Deploy to Cloudflare Workers

Set your app name

In wrangler.toml and change the name property - this will be the subdomain that your app is published on.

Your Cloudflare workers domain will be of the format {your-worker-domain}.workers.dev. When you publish an app on a Worker, it will be published on a subdomain corresponding to your app name - {worker-name}.{your-worker-domain}.workers.dev by default.

Create a KV

Create a new namespace for your KV, it's important that you name it ViewCounter. Then edit your wrangler.toml and change the kv_namespaces property with the id. It should look something like this.

kv_namespaces = [
  {binding = "ViewCounter", id = "{your-kv-id}"}
]

Get your Account ID and create a new API Token

To get your account ID:

To create a new API Token:

  • Go to https://dash.cloudflare.com/profile/api-tokens > Create Token
  • Give your token a name (i.e. Github Actions)
  • Choose start with template
  • Select the "Edit Cloudflare Workers" template
  • Account Resources > Include > {your account}
  • Zone Resources > Include > All zones from account > {your account}

Once done, navigate to your GitHub repository > Settings > Secrets and add the following secrets:

- Name: CF_API_TOKEN
- Value: your-api-token

- Name: CF_ACCOUNT_ID
- Value: your-account-id

Now if you push a new commit into master and you'll find your view counter deployed at {worker-name}.{your-worker-domain}.workers.dev

Add counter to README

<img
    src="https://<Your-cloudflare-deployment>.workers.dev"
    alt="View counter badge"
/>

OR

![View counter badge](https://<Your-cloudflare-deployment>.workers.dev)

Customization

You can pass arguments to customize your view counter. The badge is created using badgen so all the options supported by badgen except for icon and iconWidth can be used.

Parameter Default Allowed values Example
label Views Any string label=Visitors
labelColor 555 RGB values or valid color names labelColor=black
color blue RGB values or valid color names color=green
style flat flat or classic style=classic
scale 1 Any integer scale=2

Valid color names are:

blue, cyan, green, yellow, orange, red, pink, purple, grey, black

Example of a counter with parameters:

https://<Your cloudflare deployment>.workers.dev?style=classic&labelColor=black&color=green

view-counter-badge's People

Contributors

aveek-saha avatar mikejerred avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.