GuresTürkiye - İsim Etiketi

guresturkiye.net için tüm hataları giderilmiş, taşma ve donma yapmayan, en kararlı isim etiketi sistemi. Ayarlanabilir gradient tonu ve tüm görsel sorunlar giderildi. Copyright Elricsilverhand.

// ==UserScript==
// @name         GuresTürkiye - İsim Etiketi
// @namespace    http://tampermonkey.net/
// @version      10.5.2
// @description  guresturkiye.net için tüm hataları giderilmiş, taşma ve donma yapmayan, en kararlı isim etiketi sistemi. Ayarlanabilir gradient tonu ve tüm görsel sorunlar giderildi. Copyright Elricsilverhand.
// @author       Elricsilverhand
// @match        *://*.guresturkiye.net/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @run-at       document-body
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // ============================ RENK PALETLERİ ============================
    const nameplate_palettes = {
        crimson: { "darkBackground": "#900007", "lightBackground": "#E7040F" },
        berry: { "darkBackground": "#893A99", "lightBackground": "#B11FCF" },
        sky: { "darkBackground": "#0080B7", "lightBackground": "#56CCFF" },
        teal: { "darkBackground": "#086460", "lightBackground": "#7DEED7" },
        forest: { "darkBackground": "#2D5401", "lightBackground": "#6AA624" },
        bubble_gum: { "darkBackground": "#DC3E97", "lightBackground": "#F957B3" },
        violet: { "darkBackground": "#730BC8", "lightBackground": "#972FED" },
        cobalt: { "darkBackground": "#0131C2", "lightBackground": "#4278FF" },
        clover: { "darkBackground": "#047B20", "lightBackground": "#63CD5A" },
        lemon: { "darkBackground": "#F6CD12", "lightBackground": "#FED400" },
        white: { "darkBackground": "#FFFFFF", "lightBackground": "#FFFFFF" }
    };

    // ============================ TEMALAR ============================
const THEMES = {
    'bonsai_bahcesi': {
        name: 'Bonsai Bahçesi',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v3/bonsai/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'bubble_gum'
    },
    'under_the_sea': {
        name: 'Under the Sea',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v3/under_the_sea/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'sky'
    },
    'aurora': {
        name: 'Aurora',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v3/aurora/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'teal'
    },
    'sun_and_moon': {
        name: 'Sun and Moon',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v3/sun_and_moon/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'cobalt'
    },
    'oasis': {
        name: 'Oasis',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v3/oasis/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'berry'
    },
    'touch_grass': {
        name: 'Touch Grass',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v3/touch_grass/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'sky'
    },
    'spirit_moon': {
        name: 'Spirit Moon',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v2/spirit_moon/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'pixie_dust': {
        name: 'Pixie Dust',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v2/pixie_dust/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'bubble_gum'
    },
    'glitch': {
        name: 'Glitch',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v2/glitch/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'starfall_tides': {
        name: 'Starfall Tides',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v2/starfall_tides/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'teal'
    },
    'cozy_cat': {
        name: 'Cozy Cat',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v2/cozy_cat/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'berry'
    },
    'sword_of_legend': {
        name: 'Sword of Legend',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates_v2/sword_of_legend/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'cobalt'
    },
    'cherry_blossoms': { // Note: Different from 'Cherry Blossom' (singular)
        name: 'Cherry Blossoms',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/cherry_blossoms/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'berry'
    },
    'cat_beans': {
        name: 'Cat Beans',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/cat_beans/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'spirit_of_spring': {
        name: 'Spirit of Spring',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/spirit_of_spring/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'sky'
    },
    'twilight': {
        name: 'Twilight',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/twilight/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'cobalt'
    },
    'koi_pond': {
        name: 'Koi Pond',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/koi_pond/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'sky'
    },
    'vengeance': {
        name: 'Vengeance',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/vengeance/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'cityscape': {
        name: 'Cityscape',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/cityscape/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'angels': { // Only one 'Angels' entry is included, as requested.
        name: 'Angels',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplates/angels/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'bubble_gum'
    },
    'red_dragon': {
        name: 'Red Dragon',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/chance/red_dragon/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'crimson'
    },
    'd20_roll': {
        name: 'D20 Roll',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/chance/d20_roll/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'berry'
    },
    'owlbear_cub': {
        name: 'Owlbear Cub',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/chance/owlbear_cub/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'bubble_gum'
    },
    'white_mana': {
        name: 'White Mana',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/spell/white_mana/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'bubble_gum'
    },
    'blue_mana': {
        name: 'Blue Mana',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/spell/blue_mana/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'cobalt'
    },
    'black_mana': {
        name: 'Black Mana',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/spell/black_mana/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'red_mana': {
        name: 'Red Mana',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/spell/red_mana/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'crimson'
    },
    'green_mana': {
        name: 'Green Mana',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/spell/green_mana/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'clover'
    },
    'cherry_blossom': { // Note: Different from 'Cherry Blossoms' (plural)
        name: 'Cherry Blossom',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplatetest/cherry_blossom/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'berry'
    },
    'heart_bloom': {
        name: 'Heart Bloom',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplatetest/heart_bloom/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'bubble_gum'
    },
    'kawaii_gaming': {
        name: 'Kawaii Gaming',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplatetest/kawaii_gaming/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'sky'
    },
    'kitsune': {
        name: 'Kitsune',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/nameplatetest/kitsune/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'cobalt'
    },
    'tv_woman': {
        name: 'TV Woman',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/paper/tv_woman/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'secret_agent': {
        name: 'Secret Agent',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/paper/secret_agent/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'forest'
    },
    'skibidi_toilet': {
        name: 'Skibidi Toilet',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/paper/skibidi_toilet/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'lemon'
    },
    'spirit_blossom_petals': {
        name: 'Spirit Blossom Petals',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/petal/spirit_blossom_petals/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'violet'
    },
    'yunaras_aion_erna': {
        name: 'Yunara\'s Aion Er\'na',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/petal/yunaras_aion_erna/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'cobalt'
    },
    'spirit_blossom_springs': {
        name: 'Spirit Blossom Springs',
        videoUrl: 'https://cdn.discordapp.com/assets/collectibles/nameplates/petal/spirit_blossom_springs/asset.webm',
        textColor: '#FFFFFF',
        bannerWidth: '220px',
        bannerHeight: '48px',
        borderRadius: '12px',
        paletteKey: 'teal'
    }
};

    // ============================ AYARLAR ============================
    const CONFIG = {
        userId: '13059',
        selectedTheme: 'bonsai_bahcesi',
        gradientTone: 'dark' // Varsayılan ton
    };

    async function loadConfig() {
        CONFIG.userId = await GM_getValue('userId', '13059');
        CONFIG.gradientTone = await GM_getValue('selectedGradientTone', 'dark'); // Tonu yükle
        let savedTheme = await GM_getValue('selectedTheme', 'bonsai_bahcesi');

        if (!THEMES[savedTheme] || !nameplate_palettes[THEMES[savedTheme]?.paletteKey]) {
            savedTheme = Object.keys(THEMES)[0];
            if (!savedTheme) {
                console.error("[GT Nameplate] Hiç tema tanımlanmamış!");
                return;
            }
        }
        CONFIG.selectedTheme = savedTheme;
    }

    async function saveConfigAndApply() {
        const oldUserId = CONFIG.userId;
        const newUserId = document.getElementById('gt-user-id-input').value.trim();

        if (newUserId && newUserId !== oldUserId) {
            clearStylesForUser(oldUserId);
            CONFIG.userId = newUserId;
            await GM_setValue('userId', newUserId);
        }

        const newTheme = document.querySelector('.gt-theme-card.selected')?.dataset.themeKey || CONFIG.selectedTheme;
        CONFIG.selectedTheme = newTheme;
        await GM_setValue('selectedTheme', newTheme);

        const newTone = document.querySelector('input[name="gt-gradient-tone"]:checked').value;
        CONFIG.gradientTone = newTone;
        await GM_setValue('selectedGradientTone', newTone);

        injectDynamicStyles();
        clearStylesForUser(CONFIG.userId); // Ayarlar değiştiğinde mevcutları temizleyip yeniden uygula
        processNode(document.body);
        alert('Ayarlar kaydedildi!');
        document.getElementById('gt-theme-modal-overlay').style.display = 'none';
    }

    // ============================ AYAR PANELİ (MODAL) ============================

function setupModal() {
    if (document.getElementById('gt-theme-modal-overlay')) return;

    // gradientColor'u setupModal içinde dinamik olarak hesapla
    const theme = THEMES[CONFIG.selectedTheme];
    const palette = nameplate_palettes[theme.paletteKey];
    const gradientColor = CONFIG.gradientTone === 'light' ? palette.lightBackground : palette.darkBackground;

    GM_addStyle(`
        #gt-theme-modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.85);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 99999;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
        }
        #gt-theme-modal {
            background: linear-gradient(135deg, #2c2f33 0%, #1e2124 100%);
            border-radius: 16px;
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
            width: 90%;
            max-width: 800px;
            color: #ffffff;
            display: flex;
            flex-direction: column;
            max-height: 90vh;
            overflow: hidden;
            animation: slideIn 0.3s ease-out;
        }
        @keyframes slideIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        #gt-modal-header {
            padding: 20px 40px;
            border-bottom: 1px solid #40444b;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: #1e2124;
        }
        #gt-modal-header h2 {
            margin: 0;
            font-size: 1.7em;
            color: #ffffff;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            font-weight: 700;
        }
        #gt-modal-close-btn {
            background: none;
            border: none;
            color: #b9bbbe;
            font-size: 1.9em;
            cursor: pointer;
            padding: 5px;
            border-radius: 50%;
            transition: color 0.2s ease, transform 0.2s ease;
        }
        #gt-modal-close-btn:hover {
            color: #ff5555;
            transform: rotate(90deg);
        }
        #gt-modal-content {
            padding: 30px 45px;
            overflow-y: auto;
            flex-grow: 1;
            background-color: #2c2f33;
        }
        #gt-modal-content h3 {
            color: #b9bbbe;
            margin-top: 30px;
            margin-bottom: 20px;
            font-size: 1.4em;
            border-bottom: 3px solid #7289da;
            padding-bottom: 8px;
            font-weight: 600;
            text-transform: uppercase;
        }
        #gt-theme-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 30px;
            margin-bottom: 30px;
        }
        .gt-theme-card {
            background: #36393f;
            border-radius: 12px;
            overflow: hidden;
            cursor: pointer;
            border: 2px solid transparent;
            transition: all 0.3s ease;
            display: flex;
            flex-direction: column;
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }
        .gt-theme-card:hover {
            border-color: #7289da;
            transform: translateY(-6px);
            box-shadow: 0 8px 25px rgba(114, 137, 218, 0.4);
        }
        .gt-theme-card.selected {
            border-color: #7289da;
            box-shadow: 0 0 0 4px rgba(114, 137, 218, 0.5);
        }
        .gt-theme-preview {
            width: 103%;
            height: 60px;
            position: relative;
            overflow: hidden;
        }
        .gt-theme-video-preview {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            z-index: 1;
        }
        .gt-theme-card:hover .gt-theme-video-preview {
            opacity: 1;
        }
        .gt-theme-preview-overlay {
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 0;
            background: linear-gradient(90deg, rgba(0,0,0,0.5) -20%, ${gradientColor} 180%);
        }
        .gt-theme-name {
            padding: 15px;
            font-size: 1.2em;
            color: #ffffff;
            text-align: center;
            background-color: #2f3136;
            border-top: 2px solid #40444b;
            font-weight: 600;
            text-transform: capitalize;
        }
        .gt-tone-option {
            display: flex;
            gap: 20px;
            margin-top: 10px;
        }
        .gt-tone-option label {
            font-size: 1.1em;
            color: #b9bbbe;
            font-weight: 600;
            cursor: pointer;
            padding: 10px 15px;
            background-color: #36393f;
            border-radius: 8px;
            transition: all 0.3s ease;
        }
        .gt-tone-option label:hover {
            background-color: #40444b;
            color: #ffffff;
        }
        .gt-tone-option input[type="radio"]:checked + label {
            background-color: #7289da;
            color: #ffffff;
            box-shadow: 0 0 0 2px rgba(114, 137, 218, 0.5);
        }
        .gt-setting-item {
            margin-bottom: 25px;
        }
        .gt-setting-item label {
            font-size: 1.2em;
            margin-bottom: 12px;
            color: #b9bbbe;
            display: block;
            font-weight: 600;
        }
        .gt-setting-item input[type="text"] {
            background-color: #40444b;
            border: 2px solid #4f545c;
            color: #ffffff;
            padding: 12px 15px;
            border-radius: 10px;
            font-size: 1.1em;
            width: 100%;
            box-sizing: border-box;
            transition: border-color 0.2s ease, box-shadow 0.2s ease;
        }
        .gt-setting-item input[type="text"]:focus {
            border-color: #7289da;
            box-shadow: 0 0 0 3px rgba(114, 137, 218, 0.3);
            outline: none;
        }
        #gt-modal-footer {
            padding: 20px 40px;
            border-top: 1px solid #40444b;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: #1e2124;
        }
        #gt-copyright {
            font-size: 0.95em;
            color: #72767d;
            font-style: italic;
        }
        #gt-save-settings-btn {
            background: linear-gradient(90deg, #7289da 0%, #5865f2 100%);
            color: #ffffff;
            border: none;
            padding: 12px 30px;
            border-radius: 10px;
            cursor: pointer;
            font-size: 1.2em;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
        }
        #gt-save-settings-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(88, 101, 242, 0.5);
        }
    `);

    const modalContainer = document.createElement('div');
    modalContainer.id = 'gt-theme-modal-overlay';
    modalContainer.style.display = 'none';

    const themeCardsHTML = Object.entries(THEMES).map(([key, theme]) => {
        const palette = nameplate_palettes[theme.paletteKey];
        const previewGradientColor = CONFIG.gradientTone === 'light' ? palette.lightBackground : palette.darkBackground;
        return `<div class="gt-theme-card" data-theme-key="${key}">
                    <div class="gt-theme-preview">
                        <video muted loop autoplay disablepictureinpicture class="gt-theme-video-preview" src="${theme.videoUrl}" preload="auto" onerror="console.log('Video yüklenemedi: ${theme.videoUrl}')" onloadeddata="console.log('Video yüklendi: ${theme.videoUrl}')"></video>
                        <div class="gt-theme-preview-overlay" style="background: linear-gradient(90deg, rgba(0,0,0,0.5) -20%, ${previewGradientColor} 180%);"></div>
                    </div>
                    <div class="gt-theme-name">${theme.name}</div>
                </div>`;
    }).join('');

    const toneOptionsHTML = `
        <div class="gt-tone-option">
            <input type="radio" name="gt-gradient-tone" value="dark" id="dark-tone" ${CONFIG.gradientTone === 'dark' ? 'checked' : ''}>
            <label for="dark-tone">Koyu Ton</label>
            <input type="radio" name="gt-gradient-tone" value="light" id="light-tone" ${CONFIG.gradientTone === 'light' ? 'checked' : ''}>
            <label for="light-tone">Açık Ton</label>
        </div>
    `;

    modalContainer.innerHTML = `
        <div id="gt-theme-modal">
            <div id="gt-modal-header"><h2>İsim Etiketi Ayarları</h2><button id="gt-modal-close-btn">×</button></div>
            <div id="gt-modal-content">
                <h3>Tema Seçimi</h3>
                <div id="gt-theme-grid">${themeCardsHTML}</div>
                <h3>Genel Ayarlar</h3>
                <div class="gt-setting-item">
                    <label for="gt-user-id-input">Hedef Kullanıcı ID:</label>
                    <input type="text" id="gt-user-id-input" value="${CONFIG.userId || ''}" placeholder="Örnek: 13059">
                </div>
                <div class="gt-setting-item">
                    <label>Gradient Tonu:</label>
                    ${toneOptionsHTML}
                </div>
            </div>
            <div id="gt-modal-footer">
                <small id="gt-copyright">Copyright © Elricsilverhand</small>
                <button id="gt-save-settings-btn">Kaydet ve Uygula</button>
            </div>
        </div>`;

    document.body.appendChild(modalContainer);

    modalContainer.querySelector('#gt-modal-close-btn').addEventListener('click', () => { modalContainer.style.display = 'none'; });
    modalContainer.querySelector('#gt-save-settings-btn').addEventListener('click', saveConfigAndApply);
    modalContainer.querySelectorAll('.gt-theme-card').forEach(card => {
        card.addEventListener('click', (e) => {
            modalContainer.querySelector('.gt-theme-card.selected')?.classList.remove('selected');
            e.currentTarget.classList.add('selected');
            CONFIG.selectedTheme = e.currentTarget.dataset.themeKey;
        });
        const video = card.querySelector('video');
        if (video) {
            video.addEventListener('loadeddata', () => console.log('Video yüklendi:', theme.videoUrl));
            video.addEventListener('error', (e) => console.log('Video hatası:', e));
            card.addEventListener('mouseenter', () => video.play().catch(e => console.log('Video oynatılamadı:', e)));
            card.addEventListener('mouseleave', () => { video.pause(); video.currentTime = 0; });
        }
    });
    modalContainer.querySelectorAll('input[name="gt-gradient-tone"]').forEach(radio => {
        radio.addEventListener('change', (e) => {
            CONFIG.gradientTone = e.target.value;
            const newGradient = CONFIG.gradientTone === 'light' ? palette.lightBackground : palette.darkBackground;
            modalContainer.querySelectorAll('.gt-theme-preview-overlay').forEach(overlay => {
                overlay.style.background = `linear-gradient(90deg, rgba(0,0,0,0.5) -20%, ${newGradient} 180%)`;
            });
        });
    });
}

    function openSettingsModal() {
        const modal = document.getElementById('gt-theme-modal-overlay');
        if (!modal) return;
        modal.querySelector('#gt-user-id-input').value = CONFIG.userId;
        modal.querySelector('.gt-theme-card.selected')?.classList.remove('selected');
        const currentCard = modal.querySelector(`.gt-theme-card[data-theme-key="${CONFIG.selectedTheme}"]`);
        if (currentCard) currentCard.classList.add('selected');
        const currentToneRadio = modal.querySelector(`input[name="gt-gradient-tone"][value="${CONFIG.gradientTone}"]`);
        if (currentToneRadio) currentToneRadio.checked = true;
        modal.style.display = 'flex';
    }

    // ============================ STİL VE UYGULAMA ============================
function injectDynamicStyles() {
    document.getElementById('gt-dynamic-nameplate-style')?.remove();
    const theme = THEMES[CONFIG.selectedTheme];
    const palette = nameplate_palettes[theme.paletteKey];
    const gradientColor = CONFIG.gradientTone === 'light' ? palette.lightBackground : palette.darkBackground;

    const style = `
        :root {
            --gt-max-width: 220px; /* Maksimum genişlik */
            --gt-height: 48px; /* Güncellenmiş yükseklik */
            --gt-border-radius: ${theme.borderRadius};
            --gt-gradient-color: ${gradientColor};
            --gt-text-color: ${theme.textColor};
        }
        /* Ana kullanıcı adı bağlantısı - tüm görsel elementleri kapsar */
        a.username[data-user-id="${CONFIG.userId}"] {
            position: relative;
            display: inline-flex; /* Flexbox ile profile resmi ve nameplate'i hizala */
            align-items: center;
            justify-content: flex-start; /* Profile resmi sola hizalı */
            max-width: var(--gt-max-width); /* Maksimum genişlik */
            height: var(--gt-height); /* Güncellenmiş yükseklik */
            overflow: hidden; /* Dışarı taşan içeriği kırpar */
            border-radius: var(--gt-border-radius);
            text-decoration: none !important;
            pointer-events: auto;
            width: 100%; /* Tam genişlik kullan */
        }
        /* Profile resmi için alan ayır */
        a.username[data-user-id="${CONFIG.userId}"] img:first-child {
            width: 32px; /* Profil resminin boyutunu ayarla */
            height: 32px;
            margin-right: 8px; /* Nameplate ile boşluk bırak */
            border-radius: 50%; /* Yuvarlak ikon */
            flex-shrink: 0; /* Boyutunu koru */
            z-index: 3; /* Profil resmini en üstte tut */
        }
        /* Nameplate konteyneri - profil resminin yanına yerleştir */
        a.username[data-user-id="${CONFIG.userId}"] .gt-nameplate-container {
            position: relative;
            width: 100%; /* Tam genişlik kullan */
            height: 100%;
            flex-grow: 1; /* Kalan alanı doldur */
            min-width: 0; /* Taşmayı önlemek için */
            overflow: hidden;
        }
        /* Orijinal kullanıcı adı metnini gizle */
        a.username[data-user-id="${CONFIG.userId}"] .username--style2 {
            opacity: 0;
            pointer-events: none;
            position: absolute;
        }
        /* İsim etiketi videosu */
        .gt-nameplate-video {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%; /* Konteynere tam sığsın */
            height: 100%; /* Konteynere tam sığsın */
            object-fit: fill; /* Konteyneri tamamen doldur, oranları zorla */
            z-index: 1; /* Videonun gradientin üzerinde */
        }
        /* Gradient kaplaması - videonun arkasında, metnin altında */
        .gt-gradient-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-image: linear-gradient(90deg, rgba(0,0,0,0) -30%, var(--gt-gradient-color) 200%);
            z-index: 0; /* Videonun arkasında */
        }
        /* Yeni isim etiketi metni - en üstte */
        .gt-nameplate-text {
            position: relative;
            color: var(--gt-text-color) !important;
            font-weight: bold;
            text-shadow: 1px 1px 3px rgba(0,0,0,0.7); /* Daha şık gölge */
            z-index: 2; /* Metni videonun ve gradientin üzerinde */
            pointer-events: none;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            padding: 0 10px; /* Daha fazla boşluk için */
            font-size: clamp(14px, 3vw, 18px); /* Daha büyük ve responsive font */
            text-align: center; /* Metni ortala */
            line-height: var(--gt-height); /* Yükseklikle uyumlu hizalama */
        }
    `;
    GM_addStyle(style, { id: 'gt-dynamic-nameplate-style' });
}

function applyStyleToLink(userLink) {
    if (userLink.dataset.gtStyled === 'true') return;
    userLink.dataset.gtStyled = 'true';

    const usernameSpan = userLink.querySelector('[class*="username--"]');

    const usernameText = usernameSpan?.textContent || '...';
    const theme = THEMES[CONFIG.selectedTheme];

    userLink.insertAdjacentHTML('afterbegin', `
        <div class="gt-nameplate-container">
            <video class="gt-nameplate-video" src="${theme.videoUrl}" autoplay loop muted disablepictureinpicture preload="auto"></video>
            <div class="gt-gradient-overlay"></div>
            <span class="gt-nameplate-text">${usernameText}</span>
        </div>
    `);

    if (usernameSpan) {
        usernameSpan.remove();
    }
}

    function clearStylesForUser(userId) {
        document.querySelectorAll(`a.username[data-user-id="${userId}"][data-gt-styled="true"]`).forEach(link => {
            // Sadece bizim eklediğimiz elemanları kaldır
            link.querySelector('.gt-nameplate-video')?.remove();
            link.querySelector('.gt-gradient-overlay')?.remove();
            link.querySelector('.gt-nameplate-text')?.remove();

            // Orijinal metnin görünürlüğünü geri yükle (eğer varsa)
            const originalText = link.querySelector('.username--style2');
            if (originalText) {
                originalText.style.opacity = '';
                originalText.style.position = ''; // Pozisyonu sıfırla
            }
            delete link.dataset.gtStyled; // data-gt-styled özelliğini kaldır
        });
    }

    function processNode(node) {
        if (node.nodeType !== Node.ELEMENT_NODE) return;
        const selector = `a.username[data-user-id="${CONFIG.userId}"]:not([data-gt-styled])`;

        if (node.matches(selector)) {
            applyStyleToLink(node);
        }
        node.querySelectorAll(selector).forEach(applyStyleToLink);
    }

    // ============================ BAŞLANGIÇ ============================
    async function init() {
        await loadConfig();
        setupModal();
        injectDynamicStyles();
        processNode(document.body);

        // DOM değişikliklerini gözlemle ve yeni elemanlara stil uygula
        const observer = new MutationObserver((mutations) => {
            for (const mutation of mutations) {
                if (mutation.type === 'childList') {
                    for (const addedNode of mutation.addedNodes) {
                        if (addedNode.nodeType === Node.ELEMENT_NODE) {
                            processNode(addedNode);
                        }
                    }
                }
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });

        // Tampermonkey menüsüne ayar komutu ekle
        GM_registerMenuCommand('İsim Etiketi Ayarları', openSettingsModal);
    }

    init();
})();