Автоматически пролистывает страницу GitHub до конца для загрузки динамического контента, а затем копирует весь текст в буфер обмена.
Versión del día
// ==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);
}
})();