DeepCo HR Tracker

Says here your name is....

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         DeepCo HR Tracker
// @namespace    deepco_hr
// @version      2026.04.22
// @description  Says here your name is....
// @icon         https://www.google.com/s2/favicons?sz=64&domain=deepco.app
// @match        https://deepco.app/*
// @license      MIT
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    const getVar = (k, d, description = '') => {
        const o = GM_getValue('aaa_user_variables', {});

        if (!(k in o)) {
            o[k] = { value: d, description };
            GM_setValue('aaa_user_variables', o);
            return d;
        }

        if (typeof o[k] !== 'object' || o[k] === null || !('value' in o[k])) {
            o[k] = { value: o[k], description };
            GM_setValue('aaa_user_variables', o);
            return o[k].value;
        }

        if (description && !o[k].description) {
            o[k].description = description;
            GM_setValue('aaa_user_variables', o);
        }

        return o[k].value;
    };

    // ---------- User adjustable config ----------
    const DEBUG     = getVar('DEBUG',     false, "Enable console logging.");
    const SHOW_ID   = getVar('SHOW_ID',   false,  "Prefix the WorkerID on names.");
    const HIGHLIGHT = getVar('HIGHLIGHT', false,  "Apply 'valuable' CSS to new names.");
    const STORAGE_KEY = "workerAliasMap";

    const workerMap = new Map(Object.entries(GM_getValue(STORAGE_KEY, {})));

    function log(...args) {
        if (DEBUG) console.log("[DeepCo HR]", ...args);
    }

    function save() {
        const obj = {};
        for (const [id, names] of workerMap.entries()) {
            obj[id] = Array.from(names);
        }
        GM_setValue(STORAGE_KEY, obj);
    }

    function updateAnchorTitle(anchor, workerId) {
        const names = Array.from(workerMap.get(workerId) || []);
        anchor.title = `${workerId}: ${names.join(' | ')}`;
    }

    function processMessage(el) {
        const workerId = el.dataset.workerId?.replace(/"/g, '');
        if (!workerId) return;

        const anchor = el.querySelector('.worker-name-link');
        const nameSpan = anchor?.querySelector('.truncate');
        if (!anchor || !nameSpan) return;

        const name = nameSpan.textContent.trim();
        if (!name) return;

        if (!workerMap.has(workerId)) {
            workerMap.set(workerId, new Set());
        } else if (!(workerMap.get(workerId) instanceof Set)) {
            workerMap.set(workerId, new Set(workerMap.get(workerId)));
        }

        const set = workerMap.get(workerId);
        const beforeSize = set.size;
        set.add(name);
        const isNewAlias = set.size !== beforeSize;

        if (isNewAlias) {
            log("New alias", workerId, name);
            save();
        }

        // prefix worker id
        if (SHOW_ID && !nameSpan.dataset.prefixed) {
            nameSpan.textContent = `${workerId}:${name}`;
            nameSpan.dataset.prefixed = "1";
        }

        // highlight new alias
        if (HIGHLIGHT && isNewAlias) {
            log("Applying class")
            if (nameSpan) {
                nameSpan.classList.add('valuable');
            }
        }

        updateAnchorTitle(anchor, workerId);
    }

    function scan() {
        document.querySelectorAll('[data-role="chat-message"]').forEach(processMessage);
    }

    scan();

    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const node of m.addedNodes) {
                if (!(node instanceof HTMLElement)) continue;

                if (node.matches?.('[data-role="chat-message"]')) {
                    processMessage(node);
                }

                node.querySelectorAll?.('[data-role="chat-message"]').forEach(processMessage);
            }
        }
    });

    observer.observe(document, {
        childList: true,
        subtree: true
    });

})();