Hackatime Analyzer Helper

Easily open Hackatime Analyzer with data from leaderboard users

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Hackatime Analyzer Helper
// @namespace    http://tampermonkey.net/
// @version      2025-06-20
// @description  Easily open Hackatime Analyzer with data from leaderboard users
// @author       ShyMike
// @match        https://hackatime.hackclub.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
    "use strict";

    const periodMap = {
        "daily": "today",
        "last_7_days": "last_7_days",
    };
    let selectedPeriod = "today";

    function addAnalyzeButtons() {
        const rowsContainer = document.querySelector('.divide-y.divide-gray-800');
        const rows = rowsContainer.children;

        const urlParams = new URLSearchParams(window.location.search);
        const periodType = urlParams.get('period_type');

        if (periodType === "weekly") {
            return;
        }

        if (periodType && periodMap[periodType]) {
            selectedPeriod = periodMap[periodType];
        } else {
            selectedPeriod = "today";
        }

        Array.from(rows).forEach((row) => {
            if (row.querySelector(".check-btn")) return;

            const link = row.querySelector("a");
            if (!link) return;

            const userId = link.href.split("=").pop();
            if (!userId) return;

            const checkBtn = document.createElement("button");
            checkBtn.textContent = "Check";
            checkBtn.className = "check-btn";
            checkBtn.style.marginLeft = "0.5em";
            checkBtn.style.padding = "0.2rem";
            checkBtn.style.fontSize = "0.7rem";
            checkBtn.addEventListener("click", () => {
                window.open(
                    `https://hackatime-analyzer.pages.dev/?id=${userId}&period=${selectedPeriod}`,
                    "_blank"
                );
            });

            row.appendChild(checkBtn);
        });
    }

    function checkAndAddButtons() {
        if (location.pathname.includes("/leaderboards")) {
            addAnalyzeButtons();
        }
    }

    document.addEventListener("turbo:load", function () {
        checkAndAddButtons();
    });

    document.addEventListener("DOMContentLoaded", function () {
        checkAndAddButtons();
    });

    checkAndAddButtons();
})();