Ctrl+Shift+C Copy Fix

Override Ctrl+Shift+C to copy selected text instead of opening console

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Ctrl+Shift+C Copy Fix
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Override Ctrl+Shift+C to copy selected text instead of opening console
// @author       You
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keydown', function(e) {
        // Check if Ctrl+Shift+C is pressed
        if (e.ctrlKey && e.shiftKey && e.key === 'C') {
            // Prevent the default behavior (opening console)
            e.preventDefault();
            e.stopPropagation();

            // Get selected text
            const selectedText = window.getSelection().toString().trim();

            if (selectedText) {
                // Use Clipboard API to copy text
                navigator.clipboard.writeText(selectedText).then(function() {
                    console.log('Text copied to clipboard');
                    showCopyNotification('✓ Copied!');
                }).catch(function(err) {
                    console.error('Failed to copy text: ', err);

                    // Fallback for older browsers
                    fallbackCopyText(selectedText);
                });
            } else {
                console.log('No text selected to copy');
                showCopyNotification('📋 No text selected');
            }
        }
    }, true);

    // Also show notification for regular Ctrl+C copy
    document.addEventListener('keydown', function(e) {
        if (e.ctrlKey && !e.shiftKey && e.key === 'c') {
            // Small delay to ensure copy happens first
            setTimeout(() => {
                const selectedText = window.getSelection().toString().trim();
                if (selectedText) {
                    showCopyNotification('✓ Copied!');
                }
            }, 100);
        }
    }, true);

    // Fallback method for copying text
    function fallbackCopyText(text) {
        const textArea = document.createElement('textarea');
        textArea.value = text;
        textArea.style.position = 'fixed';
        textArea.style.left = '-999999px';
        textArea.style.top = '-999999px';
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();

        try {
            const successful = document.execCommand('copy');
            if (successful) {
                console.log('Text copied using fallback method');
                showCopyNotification('✓ Copied!');
            } else {
                console.error('Fallback copy method failed');
                showCopyNotification('❌ Copy failed');
            }
        } catch (err) {
            console.error('Fallback copy error: ', err);
            showCopyNotification('❌ Copy failed');
        }

        document.body.removeChild(textArea);
    }

    // Function to show a temporary notification with enhanced animations
    function showCopyNotification(message) {
        // Remove existing notification if any
        const existingNotification = document.getElementById('copy-notification');
        if (existingNotification) {
            // Quick disappear animation for existing notification
            existingNotification.style.transition = 'all 0.3s ease-out';
            existingNotification.style.transform = 'translateX(-50%) translateY(20px)';
            existingNotification.style.opacity = '0';
            setTimeout(() => {
                if (existingNotification.parentNode) {
                    existingNotification.parentNode.removeChild(existingNotification);
                }
            }, 300);
        }

        // Create new notification
        const notification = document.createElement('div');
        notification.id = 'copy-notification';
        notification.textContent = message;

        // Initial styles - starting state for appear animation
        notification.style.cssText = `
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%) translateY(100px);
            background: #6B7280;
            color: white;
            padding: 16px 32px;
            border-radius: 25px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            font-size: 14px;
            font-weight: 500;
            z-index: 10000;
            box-shadow: 0 8px 35px rgba(0,0,0,0.3);
            backdrop-filter: blur(15px);
            border: 1px solid rgba(255,255,255,0.15);
            min-width: 120px;
            text-align: center;
            transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
            opacity: 0;
            cursor: pointer;
            will-change: transform, opacity;
        `;

        document.body.appendChild(notification);

        // Trigger appear animation after a small delay to ensure CSS is applied
        setTimeout(() => {
            notification.style.transform = 'translateX(-50%) translateY(0)';
            notification.style.opacity = '1';
        }, 10);

        // Auto remove after 2 seconds with disappear animation
        let removeTimeout = setTimeout(() => {
            startDisappearAnimation(notification);
        }, 2000);

        // Click to dismiss with animation
        notification.addEventListener('click', () => {
            clearTimeout(removeTimeout);
            startDisappearAnimation(notification);
        });

        // Enhanced disappear animation function
        function startDisappearAnimation(element) {
            element.style.transition = 'all 0.4s cubic-bezier(0.4, 0, 0.2, 1)';
            element.style.transform = 'translateX(-50%) translateY(100px)';
            element.style.opacity = '0';

            setTimeout(() => {
                if (element.parentNode) {
                    element.parentNode.removeChild(element);
                }
            }, 400);
        }

        // Add hover effect for better interactivity
        notification.addEventListener('mouseenter', () => {
            notification.style.transform = 'translateX(-50%) translateY(0) scale(1.05)';
            notification.style.background = '#7E858F';
            notification.style.boxShadow = '0 12px 40px rgba(0,0,0,0.4)';
        });

        notification.addEventListener('mouseleave', () => {
            notification.style.transform = 'translateX(-50%) translateY(0) scale(1)';
            notification.style.background = '#6B7280';
            notification.style.boxShadow = '0 8px 35px rgba(0,0,0,0.3)';
        });
    }
})();