Copiar Scripts

Adiciona um botão de cópia bonito abaixo da borda direita da tela (feito Por kenite-kelve)

当前为 2023-12-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Copiar Scripts
// @namespace    http://tampermonkey.net/
// @copyright    Kenite-Kelve (Ken-devs) 2023
// @version      0.5
// @description  Adiciona um botão de cópia bonito abaixo da borda direita da tela (feito Por kenite-kelve)
// @author       Kenite-Kelve
// @match        https://greasyfork.org/*/scripts/*/code
// @license      Todos os direitos reservados
// @grant        GM_setClipboard
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Função para criar e estilizar o botão
    function createCopyButton() {
        const copyButton = document.createElement('button');
        copyButton.innerHTML = 'Copy';
        copyButton.style.position = 'fixed';
        copyButton.style.padding = '5px 10px'; // Maior altura e largura do botão
        copyButton.style.backgroundColor = '#4CAF50'; // Cor verde (pode ser ajustada)
        copyButton.style.color = 'white';
        copyButton.style.border = 'none';
        copyButton.style.borderRadius = '8px'; // Borda mais arredondada
        copyButton.style.cursor = 'pointer';
        copyButton.style.zIndex = '9999';
        copyButton.style.transition = 'all 0.3s ease';

        // Adicione estilos personalizados ao botão (opcional)
        GM_addStyle(`
            /* Adicione estilos adicionais aqui */
        `);

        // Adicione o botão ao corpo do documento
        document.body.appendChild(copyButton);

        return copyButton;
    }

    // Função para mover o botão para a posição desejada
    function moveButton(button, direction, offset) {
        switch (direction) {
            case 'top':
                button.style.top = offset + 'px';
                break;
            case 'bottom':
                button.style.bottom = offset + 'px';
                break;
            case 'left':
                button.style.left = offset + 'px';
                break;
            case 'right':
                button.style.right = offset + 'px';
                break;
        }
    }

    const copyButton = createCopyButton();

    // Adicione um evento de clique ao botão
    copyButton.addEventListener('click', function() {
        // Encontre o elemento com a classe "code-container"
        const codeContainer = document.querySelector('.code-container');

        // Verifique se o elemento existe
        if (codeContainer) {
            // Crie um intervalo para selecionar e copiar o texto
            const selection = window.getSelection();
            const range = document.createRange();
            range.selectNodeContents(codeContainer);
            selection.removeAllRanges();
            selection.addRange(range);
            document.execCommand('copy');
            selection.removeAllRanges();

            // Você pode adicionar uma mensagem ou efeito visual para indicar que o texto foi copiado
            alert('Texto copiado com sucesso!');
        } else {
            alert('Scripts não encontrado!.');
        }
    });

    // Configure a posição inicial do botão (você pode ajustar isso)
    moveButton(copyButton, 'bottom', 304);
   moveButton(copyButton, 'right', 110);

})();