Skip to content

fatfingererr/kimi-quota-logger

Repository files navigation

Kimi Code Quota Logger

Kimi Code Quota Logger

A Chrome extension that logs quota usage from the Kimi Code console page.

Demo

Demo

Overview

This extension monitors the Kimi Code console page and automatically records quota usage data every minute. The collected data can be exported as CSV for further analysis.

Features

  • Automatically detects when Kimi Code console page is open
  • Refreshes page and captures quota data every minute
  • Records weekly usage percentage and reset countdown
  • Records rate limit percentage and reset countdown
  • Supports English, Simplified Chinese, and Traditional Chinese interfaces
  • Exports data as CSV for external analysis
  • Dynamic toolbar icon shows:
    • Green dot (top-right): Recording is active
    • Red badge (bottom-right): Number of logged entries

Project Structure

kimi-quota-logger/
├── manifest.json          # Extension configuration (Manifest V3)
├── background.js          # Service worker for alarms and message handling
├── content.js             # Content script for DOM scraping
├── offscreen.html         # Offscreen document for canvas rendering
├── offscreen.js           # Dynamic icon generation
├── popup/
│   ├── popup.html         # Popup UI
│   ├── popup.css          # Popup styles
│   └── popup.js           # Popup logic
├── icons/
│   ├── icon16.png         # 16x16 icon
│   ├── icon48.png         # 48x48 icon
│   └── icon128.png        # 128x128 icon
├── assets/
│   └── kimi-quota-logger-demo.gif
├── tools/
│   ├── generate-icons.html    # Browser-based icon generator
│   └── generate-icons.ps1     # PowerShell icon generator
├── LICENSE
└── README.md

Installation

  1. Clone or download this repository:

    git clone https://github.com/fatfingererr/kimi-quota-logger.git
  2. Open Chrome and navigate to chrome://extensions/

  3. Enable Developer mode (toggle in top right corner)

  4. Click Load unpacked

  5. Select the kimi-quota-logger folder

Usage

  1. Log in to your Kimi Code account

  2. Open the console page: https://www.kimi.com/code/console

  3. The extension starts recording automatically after 1 minute

  4. Check the toolbar icon for status:

    • Green dot: Recording is active
    • Red number: Count of logged entries
  5. Click the extension icon to:

    • View current status
    • See the latest captured data
    • Download all logs as CSV
    • Clear stored logs

How It Works

  1. When the console page is detected, the extension sets up a 1-minute interval alarm

  2. On each alarm trigger:

    • The console page is refreshed
    • Waits 5 seconds for page load
    • Captures quota data from the DOM
  3. Captured data is stored in chrome.storage.local

  4. The toolbar icon updates dynamically to show recording status and log count

Captured Data

Field Type Description
timestamp string ISO 8601 UTC timestamp
localTime string Local time (Asia/Taipei timezone)
weeklyUsagePercent number Weekly quota usage percentage (0-100)
weeklyResetCountdown string Time until weekly reset (e.g., "119h")
weeklyResetHours number Hours until weekly quota resets
rateLimitPercent number Rate limit usage percentage (0-100)
rateLimitResetCountdown string Time until rate limit resets (e.g., "1h")
rateLimitResetMinutes number Minutes until rate limit resets

CSV Export

The exported CSV file:

  • Uses UTF-8 encoding with BOM (Excel compatible)
  • Filename format: kimi-quota-logs-YYYY-MM-DD.csv
  • Contains all captured data fields

Debugging

Service Worker Logs

  1. Go to chrome://extensions/
  2. Find "Kimi Code Quota Logger"
  3. Click Service Worker link
  4. View logs in the DevTools window

Content Script Logs

  1. Open the Kimi Code console page
  2. Press F12 to open DevTools
  3. Go to Console tab
  4. Filter by [Kimi Quota Logger]

Development

Regenerate Icons

Using browser:

  1. Open tools/generate-icons.html in Chrome
  2. Click download buttons for each size
  3. Replace files in icons/ folder

Using PowerShell:

powershell -ExecutionPolicy Bypass -File tools/generate-icons.ps1

Permissions Used

Permission Purpose
alarms Schedule periodic quota capture
storage Store captured log data
tabs Detect and refresh console page
downloads Export CSV files
offscreen Generate dynamic icons with canvas

Storage

Data is stored in chrome.storage.local:

  • Default limit: 10 MB
  • Approximately 200 bytes per log entry
  • ~50,000 entries capacity (~35 days of continuous logging)

Use Clear Logs button after exporting to free up storage.

License

MIT License

About

Logs Kimi Code per-minute quota from the web UI and builds a local history for personal consumption analysis.

Topics

Resources

License

Stars

Watchers

Forks

Contributors