GA Core (ManagerZone)

Núcleo compartido del GA ManagerZone Assistant: inicializa el namespace window.GA, expone mzFetch (byte-idéntico al monolito) y GA.cargarEnCruce (inyección unificada al input de Cruzar Usuarios). Pensado para @require desde el userscript principal. Debe cargarse PRIMERO.

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greasyfork.org/scripts/588168/1882655/GA%20Core%20%28ManagerZone%29.js

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 betiği yüklemek için bir betik yöneticisi eklentisi yüklemeniz gerekecektir.

(Zaten bir betik yöneticim var, hadi yükleyelim!)

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         GA Core (ManagerZone)
// @namespace    https://control.managerzone.com/ga
// @version      1.0.0
// @description  Núcleo compartido del GA ManagerZone Assistant: inicializa el namespace window.GA, expone mzFetch (byte-idéntico al monolito) y GA.cargarEnCruce (inyección unificada al input de Cruzar Usuarios). Pensado para @require desde el userscript principal. Debe cargarse PRIMERO.
// ==/UserScript==

(function () {
    'use strict';

    // Namespace compartido entre el principal y todas las libraries @require.
    // En el sandbox de Tampermonkey, window.GA persiste a través de los
    // @require y del script principal (no se filtra a la página).
    window.GA = window.GA || {};
    const GA = window.GA;

    // ------------------------------------------------------------------
    //  mzFetch  — wrapper de GM_xmlhttpRequest (GET) que devuelve Promise.
    //  Cuerpo BYTE-IDÉNTICO al del monolito (userscript 1.7.2, líneas
    //  148–167). Lo usan ip-amistosos, cruce (resolveUser) y racimo.
    //
    //  NOTA: requiere que el PRINCIPAL declare `// @grant GM_xmlhttpRequest`
    //  en su metadata; los @grant no pueden ir en un archivo @require-ado.
    // ------------------------------------------------------------------
    function mzFetch(url) {
        return new Promise((resolve, reject) => {
            GM_xmlhttpRequest({
                method: "GET",
                url: url,
                onload: function(res) {
                    if (res.status === 200) {
                        resolve(res.responseText);
                    } else {
                        reject("Error HTTP: " + res.status);
                    }
                },
                onerror: function(err) {
                    reject(err);
                }
            });
        });
    }
    GA.mzFetch = mzFetch;

    // ------------------------------------------------------------------
    //  cargarEnCruce  — CÓDIGO NUEVO. Unifica la "danza" de inyección que
    //  hoy está duplicada en 4 sitios (limpiador, botones [+] de bidhistory,
    //  y dos en analizarTransferencias). Agrega uno o más tokens al input
    //  de "Cruzar Usuarios" (#ga-simple-cross-input), deduplicando
    //  case-insensitive y preservando el orden.
    //
    //  Semántica idéntica a las copias existentes:
    //    · split(/[ ,\t\n]+/) → trim → filter(Boolean) sobre lo ya cargado
    //    · dedup case-insensitive vía Set de minúsculas
    //    · join(', ')
    //
    //  @param   {string|Array<string|number>} nombres  token o lista.
    //  @returns {number}  cantidad de tokens efectivamente agregados.
    //
    //  Si el widget de cruce no está en la página, no hace nada y devuelve 0.
    //  Un caller que necesite distinguir "widget ausente" de "0 nuevos"
    //  (p. ej. para alertar) debe chequear el elemento antes de llamar.
    // ------------------------------------------------------------------
    GA.cargarEnCruce = function (nombres) {
        const input = document.getElementById('ga-simple-cross-input');
        if (!input) return 0;

        const actuales = input.value.split(/[ ,\t\n]+/).map(s => s.trim()).filter(Boolean);
        const lower = new Set(actuales.map(s => s.toLowerCase()));
        let agregados = 0;

        (Array.isArray(nombres) ? nombres : [nombres]).forEach(n => {
            n = String(n == null ? '' : n).trim();
            if (n && !lower.has(n.toLowerCase())) {
                actuales.push(n);
                lower.add(n.toLowerCase());
                agregados++;
            }
        });

        input.value = actuales.join(', ');
        return agregados;
    };

})();