☰

Bongacams Links Buttons

Добавляет кнопки, переключатель ников, cкрывает "Король чата".

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         Bongacams Links Buttons
// @version      2.7
// @description  Добавляет кнопки, переключатель ников, cкрывает "Король чата".
// @match        *://*.bongacams*.com/*
// @include      *://*.bongacams*.com/*
// @grant        none
// @inject-into  auto
// @run-at       document-start
// @namespace https://greasyfork.org/users/1425459
// ==/UserScript==

(function() {
    'use strict';

    // Вставляем стили вручную
    function addStyles() {
        const style = document.createElement('style');
        style.textContent = `
            /* Скрываем уведомление о Короле чата */
            .bc_chat_tip_king {
                display: none !important;
            }

            .custom-links-container {
                display: flex;
                align-items: center;
                justify-content: flex-start;
                gap: 6px;
                margin-right: 15px;
            }

            /* Стили для кнопок-иконок */
            .bc_chat_button.custom-icon-btn {
                padding-inline-start: 6px !important;
                padding-inline-end: 6px !important;
                min-width: 26px;
            }

            .custom-icon-btn img {
                width: 14px;
                height: 14px;
                border-radius: 50%;
                object-fit: cover;
                display: block;
            }

            /* Стили для плавного переключателя (Toggle Pill) */
            .nick-toggle-container {
                display: inline-flex;
                position: relative;
                background: var(--bc-thm-chat-button-bg, #ffffff);
                border: 1px solid var(--bc-thm-chat-button-borderColor, #e6e6e6);
                border-radius: 20px;
                padding: 2px;
                cursor: pointer;
                margin-left: 4px;
                align-items: center;
                height: 26px;
                box-sizing: border-box;
                user-select: none;
            }

            .nick-toggle-option {
                position: relative;
                z-index: 2;
                padding: 0 10px;
                font: 600 12px / 22px Open Sans, sans-serif;
                color: var(--bc-thm-chat-button-color, #333333);
                opacity: 0.4;
                transition: opacity 0.3s ease;
                white-space: nowrap;
            }

            .nick-toggle-option.active {
                opacity: 1;
            }

            .nick-toggle-slider {
                position: absolute;
                top: 2px;
                bottom: 2px;
                left: 2px;
                background: var(--bc-thm-chat-button-bg-hover, #f0f0f0);
                border-radius: 18px;
                z-index: 1;
                transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
                box-shadow: 0 1px 3px rgba(0,0,0,0.15);
            }

            .username-copy-target {
                cursor: pointer;
            }

            .copy-notification {
                position: fixed;
                bottom: 20px;
                right: 20px;
                background: #4caf50;
                color: #ffffff;
                padding: 10px 20px;
                border-radius: 5px;
                z-index: 1001;
                opacity: 0;
                transform: translateY(20px);
                transition: opacity 0.3s ease, transform 0.3s ease;
            }
            .copy-notification.show {
                opacity: 1;
                transform: translateY(0);
            }
        `;
        document.head.appendChild(style);
    }
    addStyles();

    function formatCamWhoresName(name) {
        return name.replace(/-/g, '--');
    }

    function getModelNameFromUrl() {
        const pathSegments = window.location.pathname.split('/').filter(Boolean);
        if (pathSegments.length > 0 && pathSegments[0] !== 'ru' && pathSegments[0] !== 'en') {
            return pathSegments[0];
        }
        return null;
    }

    function getServiceUrl(serviceName, name) {
        if (!name) return '#';
        switch (serviceName) {
            case 'Nrtool':        return `https://nrtool.st/nrtool/history/bc/${name}/1?group_by=week`;
            case 'CamWhores':     return `https://www.camwhores.tv/search/${formatCamWhoresName(name)}/`;
            case 'Livecamrips':   return `https://livecamrips.to/search/${name}/1`;
            case 'Privateshow':   return `https://privateshow.cam/model/${name}/`;
            case 'CamGirlFinder': return `https://camgirlfinder.net/models/bc/${name}#1`;
            case 'Camclips':      return `https://www.camsclips.co/search/${formatCamWhoresName(name)}/`;
            case 'Yandex':        return `https://ya.ru/search/?text=${name}`;
            case 'Google':        return `https://www.google.com/search?q=${name}`;
            case 'Forumsmotri':   return `https://forumsmotri.su/index.php?do=search&subaction=search&search_start=0&full_search=1&result_from=1&story=${name}&titleonly=1&searchuser=&replyless=0&replylimit=0&searchdate=0&beforeafter=after&sortby=date&resorder=desc&showposts=0&catlist%5B%5D=0`;
            default:              return '#';
        }
    }

    const services = [
        { name: 'Nrtool',         icon: 'https://nobodyhome.tv/favicon.ico' },
        { name: 'CamWhores',      icon: 'https://www.camwhores.tv/favicon.ico' },
        { name: 'Livecamrips',    icon: 'https://livecamrips.to/ico/favicon.ico' },
        { name: 'Privateshow',    icon: 'https://privateshow.cam/favicon.ico' },
        { name: 'CamGirlFinder',  icon: 'https://camgirlfinder.net/favicon.ico' },
        { name: 'Camclips',       icon: 'https://www.camsclips.co/favicon.ico' },
        { name: 'Yandex',         icon: 'https://ya.ru/favicon.ico' },
        { name: 'Google',         icon: 'https://www.google.com/favicon.ico' },
        { name: 'Forumsmotri',    icon: 'https://forumsmotri.su/favicon.ico' }
    ];

    function showCopyNotification(text) {
        const existing = document.querySelector('.copy-notification');
        if (existing) existing.remove();

        const notification = document.createElement('div');
        notification.className = 'copy-notification';
        notification.textContent = `Ник "${text}" скопирован!`;
        document.body.appendChild(notification);

        requestAnimationFrame(() => notification.classList.add('show'));
        setTimeout(() => {
            notification.classList.remove('show');
            setTimeout(() => notification.remove(), 300);
        }, 2000);
    }

    function copyToClipboard(text) {
        navigator.clipboard.writeText(text).then(() => showCopyNotification(text)).catch(() => {});
    }

    function findModelNameElement() {
        return document.querySelector('.username, .profile_username, .model-username, .display-name, .ch_h_name, .profile-name, .model-name, h1, h2');
    }

    function findTargetContainer() {
        return document.querySelector('.ch_cell.__tip_king');
    }

function init() {
        const nameElement = findModelNameElement();
        const targetContainer = findTargetContainer();

        if (!nameElement || !targetContainer) return;

        const currentModelName = nameElement.textContent.trim();
        if (!currentModelName) return;

        // Если состояние (имя модели + состояние переключателя) уже применено — выходим
        if (targetContainer.dataset.attachedModelName === currentModelName) return;

        // Очистка перед перерисовкой
        const oldButtons = targetContainer.querySelector('.custom-links-container');
        if (oldButtons) oldButtons.remove();

        targetContainer.dataset.attachedModelName = currentModelName;

        const urlModelName = getModelNameFromUrl() || currentModelName;

        // Обработка копирования ника
        if (!nameElement.dataset.copyAttached) {
            nameElement.dataset.copyAttached = 'true';
            nameElement.classList.add('username-copy-target');
            nameElement.addEventListener('click', (e) => {
                e.preventDefault();
                e.stopPropagation();
                copyToClipboard(nameElement.textContent.trim());
            });
        }

        const buttonsContainer = document.createElement('div');
        buttonsContainer.className = 'custom-links-container';

        // Создаем кнопки
        services.forEach(service => {
            const btn = document.createElement('a');
            btn.className = 'bc_chat_button custom-icon-btn';
            btn.dataset.service = service.name;
            btn.href = getServiceUrl(service.name, currentModelName);
            btn.target = '_blank';
            btn.rel = 'noopener';

            const img = document.createElement('img');
            img.src = service.icon;
            img.alt = service.name;
            img.onerror = () => btn.remove();

            btn.appendChild(img);
            buttonsContainer.appendChild(btn);
        });

        // ПРОВЕРКА: переключатель создается ТОЛЬКО если ники РАЗНЫЕ
        if (urlModelName.toLowerCase() !== currentModelName.toLowerCase()) {
            const toggleContainer = document.createElement('div');
            toggleContainer.className = 'nick-toggle-container';

            const slider = document.createElement('div');
            slider.className = 'nick-toggle-slider';

            const optCurrent = document.createElement('div');
            optCurrent.className = 'nick-toggle-option active';
            optCurrent.textContent = currentModelName;

            const optUrl = document.createElement('div');
            optUrl.className = 'nick-toggle-option';
            optUrl.textContent = urlModelName;

            toggleContainer.appendChild(slider);
            toggleContainer.appendChild(optCurrent);
            toggleContainer.appendChild(optUrl);

            let useUrlNick = false;

            const updateToggleState = () => {
                const activeOpt = useUrlNick ? optUrl : optCurrent;
                slider.style.width = `${activeOpt.offsetWidth}px`;
                slider.style.transform = `translateX(${activeOpt.offsetLeft - 2}px)`;

                optCurrent.classList.toggle('active', !useUrlNick);
                optUrl.classList.toggle('active', useUrlNick);
            };

            toggleContainer.addEventListener('click', () => {
                useUrlNick = !useUrlNick;
                updateToggleState();

                const activeNick = useUrlNick ? urlModelName : currentModelName;
                const btns = buttonsContainer.querySelectorAll('.custom-icon-btn');
                btns.forEach(btn => {
                    btn.href = getServiceUrl(btn.dataset.service, activeNick);
                });
            });

            buttonsContainer.appendChild(toggleContainer);
            setTimeout(updateToggleState, 50);
        }

        targetContainer.prepend(buttonsContainer);
        targetContainer.style.display = 'flex';
        targetContainer.style.alignItems = 'center';
    }

    function start() {
        const tryInit = () => init();
        const observer = new MutationObserver(tryInit);
        observer.observe(document.documentElement, { childList: true, subtree: true });

        tryInit();
        setInterval(tryInit, 1000);
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', start);
    } else {
        start();
    }
})();