Link Click Tracker

クリック済みリンクを記録し、視覚的に分かるように表示

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Link Click Tracker
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  クリック済みリンクを記録し、視覚的に分かるように表示
// @author       Your Name
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // ハッシュ値を計算する関数 (SHA-256 + 先頭8文字)
    async function computeHash(link) {
        const encoder = new TextEncoder();
        const data = encoder.encode(link);
        const hashBuffer = await crypto.subtle.digest("SHA-256", data);
        const hashArray = Array.from(new Uint8Array(hashBuffer));
        const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, "0")).join("");
        return hashHex.substring(0, 8);
    }

    // リンクにチェックマークを追加する関数
    function addCheckmark(link) {
        // リンク内にimgタグが含まれていない場合のみチェックマークを追加
        if (!link.textContent.includes('✅') && !link.querySelector("img")) {
            link.textContent = "✅ " + link.textContent; // テキストの先頭にチェックマークを追加
        }
    }

    // ページ内のすべてのリンクをチェック
    async function checkLinks() {
        const visitedLinks = JSON.parse(localStorage.getItem("visitedLinks")) || {};
        const links = document.querySelectorAll("a[href]");

        for (const link of links) {
            const href = link.href;

            // ハッシュ値を計算して確認
            const hash = await computeHash(href);
            if (visitedLinks[hash]) {
                addCheckmark(link);
            }

            // クリックイベントを追加
            link.addEventListener("click", async () => {
                const clickHash = await computeHash(href);
                visitedLinks[clickHash] = true;
                localStorage.setItem("visitedLinks", JSON.stringify(visitedLinks));
                checkLinks();
            });
        }
    }

    // ページロード時にリンクをチェック
    checkLinks();
})();