GitHub Auto-Scroll & Copy

Автоматически пролистывает страницу GitHub до конца для загрузки динамического контента, а затем копирует весь текст в буфер обмена.

Από την 21/06/2026. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         GitHub Auto-Scroll & Copy
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Автоматически пролистывает страницу GitHub до конца для загрузки динамического контента, а затем копирует весь текст в буфер обмена.
// @author       torch
// @match        https://github.com/*
// @grant        GM_setClipboard
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Создаем кнопку интерфейса
    const btn = document.createElement('button');
    btn.innerText = '📜 Прокрутить и скопировать';
    btn.style.position = 'fixed';
    btn.style.bottom = '20px';
    btn.style.right = '20px';
    btn.style.zIndex = '99999';
    btn.style.padding = '10px 16px';
    btn.style.backgroundColor = '#24292e';
    btn.style.color = '#ffffff';
    btn.style.border = '1px solid rgba(27,31,35,0.15)';
    btn.style.borderRadius = '6px';
    btn.style.cursor = 'pointer';
    btn.style.fontSize = '14px';
    btn.style.fontWeight = '500';
    btn.style.boxShadow = '0 3px 12px rgba(0,0,0,0.15)';
    btn.style.transition = 'background-color 0.2s, transform 0.1s';

    // Эффект наведения
    btn.addEventListener('mouseenter', () => btn.style.backgroundColor = '#2f363d');
    btn.addEventListener('mouseleave', () => btn.style.backgroundColor = '#24292e');

    document.body.appendChild(btn);

    let isScrolling = false;

    btn.addEventListener('click', () => {
        if (isScrolling) return;
        isScrolling = true;
        btn.innerText = '⏳ Прокрутка страницы...';
        btn.disabled = true;
        btn.style.cursor = 'not-allowed';

        let lastScrollHeight = 0;
        let stopCount = 0;

        const interval = setInterval(() => {
            // Прокручиваем страницу на 80% высоты экрана за раз
            window.scrollBy(0, window.innerHeight * 0.8);

            const currentScrollHeight = document.documentElement.scrollHeight;
            const currentScrollTop = window.scrollY || window.pageYOffset;
            const windowHeight = window.innerHeight;

            // Проверка достижения нижнего края
            if (currentScrollTop + windowHeight >= currentScrollHeight - 50) {
                if (currentScrollHeight === lastScrollHeight) {
                    stopCount++;
                } else {
                    stopCount = 0;
                }
                lastScrollHeight = currentScrollHeight;

                // Если высота не меняется на протяжении 4 итераций (около 1 секунды),
                // значит весь динамический контент загружен
                if (stopCount >= 4) {
                    clearInterval(interval);
                    copyToClipboard();
                }
            } else {
                stopCount = 0;
                lastScrollHeight = currentScrollHeight;
            }
        }, 250); // Интервал прокрутки — 250 мс
    });

    function copyToClipboard() {
        // Извлекаем текстовое содержимое страницы
        const textToCopy = document.body.innerText;

        // Используем GM API для надежного копирования или fallback на стандартный API
        if (typeof GM_setClipboard !== 'undefined') {
            GM_setClipboard(textToCopy, 'text');
            showSuccess();
        } else if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(textToCopy)
                .then(showSuccess)
                .catch(err => {
                    console.error('Не удалось скопировать текст: ', err);
                    showError();
                });
        } else {
            showError();
        }
    }

    function showSuccess() {
        btn.innerText = '✅ Скопировано!';
        btn.style.backgroundColor = '#2ea44f'; // Зеленый цвет GitHub
        resetButton(3000);
    }

    function showError() {
        btn.innerText = '❌ Ошибка копирования';
        btn.style.backgroundColor = '#cb2431'; // Красный цвет GitHub
        resetButton(4000);
    }

    function resetButton(delay) {
        setTimeout(() => {
            btn.innerText = '📜 Прокрутить и скопировать';
            btn.style.backgroundColor = '#24292e';
            btn.disabled = false;
            btn.style.cursor = 'pointer';
            isScrolling = false;
        }, delay);
    }
})();