Sniffies Saved Phrases

Adds an overlay for quick phrase selection and user blocking on Sniffies.com

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Sniffies Saved Phrases
// @version      1.4
// @description  Adds an overlay for quick phrase selection and user blocking on Sniffies.com
// @author       LiveCamShow
// @match        *://sniffies.com/*
// @grant        GM_xmlhttpRequest
// @homepageURL  https://gitlab.com/livecamshow/UserScripts
// @namespace    LiveCamShow.scripts
// @license MIT
// ==/UserScript==


(function () {
    'use strict';

    const phrases = [
        "Hey man, what's up?",
        "Hey man, looking good!",
        "Wanna hang out?",
        "I'm into...."
    ];

    let currentIndex = 0;
    let overlayVisible = false;

    const overlay = document.createElement("div");
    overlay.id = "phraseOverlay";
    const style = document.createElement("style");
    style.textContent = `
        #phraseOverlay {
            position: absolute;
            width: 320px;
            max-height: 90%;
            background: #0f1e35;
            border-radius: 8px;
            padding: 12px;
            box-shadow: 0 4px 12px rgba(14, 22, 33, .25);
            color: #d4d9e4;
            border-top: 4px solid #4b84e6;
            border-bottom: 4px solid #4b84e6;
            font-family: "Arial", sans-serif;
            z-index: 9999;
            display: none;
            animation: fadeIn 0.25s cubic-bezier(.165, .84, .44, 1);
            overflow-y: auto;
        }

        #phraseOverlay ul {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        #phraseOverlay li {
            padding: 8px;
            cursor: pointer;
            background-color: #2e3d51;
            color: #d4d9e4;
            border-radius: 4px;
            margin-bottom: 4px;
        }

        #phraseOverlay li:hover {
            background-color: #3c5f9c;
        }

        #phraseOverlay li.active {
            background-color: #4b84e6;
            color: #ffffff;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
    `;
    document.head.appendChild(style);
    document.body.appendChild(overlay);

    const phraseList = document.createElement("ul");
    phrases.forEach((phrase, index) => {
        const listItem = document.createElement("li");
        listItem.textContent = phrase;
        listItem.classList.toggle("active", index === currentIndex);
        listItem.addEventListener("click", () => selectPhrase(index));
        phraseList.appendChild(listItem);
    });
    overlay.appendChild(phraseList);

    // Helper function to update the overlay display
    function updateOverlay() {
        const listItems = Array.from(phraseList.children);
        listItems.forEach((li, index) => li.classList.toggle("active", index === currentIndex));
    }

    // Optimized positioning function
    function positionOverlay() {
        const chatInputPanel = document.getElementById("chat-input-panel");
        if (!chatInputPanel) return; // If panel doesn't exist, no need to position the overlay

        const chatInputRect = chatInputPanel.getBoundingClientRect();
        overlay.style.left = `${chatInputRect.left + (chatInputRect.width / 2) - (overlay.offsetWidth / 2)}px`;
        overlay.style.top = `${chatInputRect.top - overlay.offsetHeight}px`;
    }

    // Event listener to toggle the overlay visibility
    document.addEventListener("keydown", (e) => {
        if (e.shiftKey && e.ctrlKey && window.location.pathname.endsWith('/chat')) {
            overlayVisible = !overlayVisible;
            overlay.style.display = overlayVisible ? "block" : "none";
            if (overlayVisible) {
                currentIndex = 0;
                updateOverlay();
                positionOverlay(); // Only update position when overlay is visible
            }
        }

        if (overlayVisible) {
            if (e.key === "ArrowDown") {
                currentIndex = (currentIndex + 1) % phrases.length;
                updateOverlay();
                e.preventDefault();
            } else if (e.key === "ArrowUp") {
                currentIndex = (currentIndex - 1 + phrases.length) % phrases.length;
                updateOverlay();
                e.preventDefault();
            } else if (e.key === "Enter") {
                selectPhrase(currentIndex);
                e.preventDefault();
            }
        }
    });

    // Function to handle the phrase selection
    function selectPhrase(index) {
        const selectedPhrase = phrases[index];
        overlay.style.display = "none";
        overlayVisible = false;

        const inputField = document.querySelector("input[type='text'], textarea");
        const submitButton = document.querySelector('#chat-input-send-text-or-saved-photo');

        if (inputField) {
            inputField.value = selectedPhrase;
            inputField.dispatchEvent(new Event("input", { bubbles: true }));
            if (submitButton) {
                submitButton.click();
            }
        }
    }

    // Mutation observer to handle removal of the chat input panel
    const observer = new MutationObserver(() => {
        if (!document.getElementById("chat-input-panel")) {
            overlay.style.display = "none";
            overlayVisible = false;
        }
    });
    observer.observe(document.body, { childList: true, subtree: true });

    // Ensure overlay is positioned correctly when the page is loaded
    window.addEventListener('load', positionOverlay);
})();