// ==UserScript== // @name LZT Article Summarizer // @namespace http://tampermonkey.net/ // @version 0.3 // @description Утилита, которая сокращает текст темы, экономя ваше время на прочтение. // @author @planetus (lolz) // @match https://lolz.live/threads/* // @match https://zelenka.guru/threads/* // @match https://lolz.guru/threads/* // @icon https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru // @license MIT // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @downloadURL https://update.greasyfork.icu/scripts/515565/LZT%20Article%20Summarizer.user.js // @updateURL https://update.greasyfork.icu/scripts/515565/LZT%20Article%20Summarizer.meta.js // ==/UserScript== (function() { 'use strict'; const defaultSettings = { minTextLength: 200, maxSummaryLength: 500, maxKeyPoints: 5, buttonColor: '#228e5d', summaryBgColor: '#091e15', summaryTextColor: '#ecf0f1', animationSpeed: 300, wordsPerMinute: 200 }; let settings = Object.assign({}, defaultSettings, GM_getValue('lztSummarizerSettings', {})); function saveSettings() { GM_setValue('lztSummarizerSettings', settings); updateStyles(); } function clearSettings() { GM_setValue('lztSummarizerSettings', {}); settings = Object.assign({}, defaultSettings); updateStyles(); } function createSettingsMenu() { const settingsHTML = `
`; const settingsDiv = document.createElement('div'); settingsDiv.innerHTML = settingsHTML; document.body.appendChild(settingsDiv); const overlay = document.getElementById('lzt-settings-overlay'); const settingsPanel = document.getElementById('lzt-settings'); setTimeout(() => { overlay.style.opacity = '1'; settingsPanel.style.transform = 'translate(-50%, -50%) scale(1)'; }, 50); document.getElementById('saveSettings').addEventListener('click', function() { settings.minTextLength = parseInt(document.getElementById('minTextLength').value); settings.maxSummaryLength = parseInt(document.getElementById('maxSummaryLength').value); settings.maxKeyPoints = parseInt(document.getElementById('maxKeyPoints').value); settings.buttonColor = document.getElementById('buttonColor').value; settings.summaryBgColor = document.getElementById('summaryBgColor').value; settings.summaryTextColor = document.getElementById('summaryTextColor').value; settings.animationSpeed = parseInt(document.getElementById('animationSpeed').value); saveSettings(); closeSettingsMenu(); }); document.getElementById('clearSettings').addEventListener('click', function() { if (confirm('Вы уверены, что хотите сбросить все настройки?')) { clearSettings(); closeSettingsMenu(); alert('Настройки сброшены до значений по умолчанию.'); } }); document.getElementById('closeSettings').addEventListener('click', closeSettingsMenu); function closeSettingsMenu() { overlay.style.opacity = '0'; settingsPanel.style.transform = 'translate(-50%, -50%) scale(0.9)'; setTimeout(() => { settingsDiv.remove(); }, 300); } } function updateStyles() { GM_addStyle(` .lzt-summary-button { background: linear-gradient(45deg, ${settings.buttonColor}, ${lightenDarkenColor(settings.buttonColor, -20)}); border: none; color: white; padding: 10px 15px; text-align: center; text-decoration: none; display: inline-block; font-size: 14px; user-select: none; margin: 10px 0; cursor: pointer; border-radius: 4px; transition: all ${settings.animationSpeed}ms ease; box-shadow: 0 2px 4px rgba(0,0,0,0.1); animation: fadeInButton ${settings.animationSpeed}ms ease-out; } .lzt-summary-button:hover { background: linear-gradient(45deg, ${lightenDarkenColor(settings.buttonColor, -20)}, ${lightenDarkenColor(settings.buttonColor, -40)}); transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.2); } .lzt-summary-button:active { transform: translateY(0); } .lzt-summary { position: relative; z-index: 99; background-color: ${settings.summaryBgColor}; border-left: 4px solid ${settings.buttonColor}; color: ${settings.summaryTextColor}; padding: 20px; margin: 15px 0; border-radius: 8px; font-size: 14px; line-height: 1.6; animation: fadeIn ${settings.animationSpeed}ms ease-out; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } @keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } } @keyframes fadeInButton { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } .lzt-flex { display: flex; align-items: center; gap: 30px; flex-wrap: nowrap; margin-bottom: 15px; justify-content: space-between; } .lzt-summary-title { color: ${settings.buttonColor}; font-weight: bold; margin-bottom: 15px; font-size: 18px; font-weight: bold; display: flex; align-items: center; gap: 5px; } .lzt-summary-content { margin-top: 10px; white-space: pre-line; } .lzt-key-points { margin-top: 20px; padding-top: 15px; border-top: 1px solid rgba(255,255,255,0.2); } .lzt-key-points-title { color: ${settings.buttonColor}; font-weight: bold; margin-bottom: 10px; display: flex; align-items: center; gap: 5px; } .lzt-key-point { margin: 8px 0; padding-left: 20px; position: relative; } .lzt-key-point:before { content: "•"; color: ${settings.buttonColor}; position: absolute; left: 0; font-size: 18px; } .lzt-popup { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.9); background-color: ${settings.summaryBgColor}; padding: 30px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 999999; width: 90%; max-width: 800px; max-height: 90vh; overflow-y: auto; opacity: 0; transition: all ${settings.animationSpeed}ms ease; } .lzt-popup.show { opacity: 1; transform: translate(-50%, -50%) scale(1); } .lzt-popup-close { position: absolute; top: 15px; right: 20px; font-size: 28px; color: ${settings.summaryTextColor}; cursor: pointer; transition: color ${settings.animationSpeed}ms ease; } .lzt-popup-close:hover { color: ${settings.buttonColor}; } .lzt-original-content { transition: opacity ${settings.animationSpeed}ms ease, height ${settings.animationSpeed}ms ease; overflow: hidden; } .lzt-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.7); backdrop-filter: blur(8px); z-index: 99998; opacity: 0; transition: opacity ${settings.animationSpeed}ms ease; } .lzt-overlay.show { opacity: 1; } .lzt-settings-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.8); z-index: 10000; display: flex; justify-content: center; align-items: center; opacity: 0; backdrop-filter: blur(8px); transition: opacity ${settings.animationSpeed}ms ease; } .lzt-settings { background-color: #303030b0; padding: 30px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); width: 90%; max-width: 500px; transform: translate(-50%, -50%) scale(0.9); transition: transform ${settings.animationSpeed}ms ease; position: fixed; top: 50%; left: 50%; } .lzt-settings-title { display: flex; align-items: center; gap: 5px; color: #228e5d; font-weight: bold; margin-bottom: 0; font-size: 18px; white-space: nowrap; text-overflow: ellipsis; } .lzt-settings-group { margin-bottom: 15px; } .lzt-settings-group label { display: block; color: #bdc3c7; margin-bottom: 5px; } .lzt-settings-group input { width: 100%; padding: 8px; border: none; border-radius: 4px; background-color: #303030; color: #ecf0f1; font-size: 14px; } .lzt-settings-group input[type="color"] { height: 40px; cursor: pointer; } .lzt-settings-buttons { display: flex; gap: 5px; justify-content: space-between; margin-top: 20px; } .lzt-settings-button { padding: 10px 20px; border: none; border-radius: 4px; font-size: 15px; cursor: pointer; transition: background-color ${settings.animationSpeed}ms ease; } .lzt-settings-save { display: block; width: -webkit-fill-available; background-color: #2ecc7161; color: white; } .lzt-settings-save:hover { background-color: #27ae60; } .lzt-settings-clear { display: block; width: -webkit-fill-available; background-color: #f39c1291; color: white; } .lzt-settings-clear:hover { background-color: #d35400; } .lzt-settings-close { display: flex; border-radius: 12px; padding: 8px 18px; width: max-content; background-color: #313131; color: white; } .lzt-settings-close:hover { background-color: #c0392b; } .lzt-reading-time { display: flex; align-items: center; gap: 5px; font-size: 12px; opacity: .8; color: ${settings.summaryTextColor}; margin-top: 10px; } `); } function lightenDarkenColor(col, amt) { let usePound = false; if (col[0] == "#") { col = col.slice(1); usePound = true; } let num = parseInt(col,16); let r = (num >> 16) + amt; if (r > 255) r = 255; else if (r < 0) r = 0; let b = ((num >> 8) & 0x00FF) + amt; if (b > 255) b = 255; else if (b < 0) b = 0; let g = (num & 0x0000FF) + amt; if (g > 255) g = 255; else if (g < 0) g = 0; return (usePound?"#":"") + (g | (b << 8) | (r << 16)).toString(16).padStart(6, '0'); } function extractKeyPoints(text) { const sentences = text.match(/[^\.!\?]+[\.!\?]+/g) || []; const keyPoints = []; const indicators = [ 'важно', 'главное', 'необходимо', 'следует', 'нужно', 'основной', 'ключевой', 'рекомендуется', 'обратите внимание', 'в первую очередь', 'самое важное', 'ключевая идея', 'существенно', 'критически', 'принципиально', 'фундаментально', 'приоритетно' ]; sentences.forEach(sentence => { const lowercaseSentence = sentence.toLowerCase(); if (indicators.some(indicator => lowercaseSentence.includes(indicator)) || (sentence.length > 30 && sentence.length < 200 && /[0-9]/.test(sentence)) || /^[•\-]/.test(sentence.trim())) { keyPoints.push(sentence.trim()); } }); const startIndicators = ['ключевые моменты', 'основные пункты', 'главные идеи']; let foundKeyPointSection = false; sentences.forEach(sentence => { const lowercaseSentence = sentence.toLowerCase().trim(); if (startIndicators.some(indicator => lowercaseSentence.startsWith(indicator))) { foundKeyPointSection = true; } if (foundKeyPointSection && /^[•\-]/.test(sentence.trim())) { keyPoints.push(sentence.trim()); } }); return [...new Set(keyPoints)].slice(0, settings.maxKeyPoints); } function summarizeText(text) { text = text.replace(/\s+/g, ' ').trim(); const sentences = text.split(/(?<=[.!?])\s+(?=[A-ZА-Я])/); if (sentences.length === 0) { return ''; } const sentenceScores = sentences.map((sentence, index) => { const words = sentence.toLowerCase().split(' '); let score = 0; const importantWords = [ 'важно', 'главное', 'необходимо', 'ключевой', 'существенно', 'критически', 'спонсор', 'проект', 'результат', 'итог', 'вывод', 'следовательно', 'таким образом', 'поэтому', 'значит', 'суть', 'основа', 'цель', 'задача' ]; const importantWordsCount = words.filter(word => importantWords.some(important => word.includes(important)) ).length; score += importantWordsCount * 3; if (sentence.length > 50 && sentence.length < 200) { score += 2; } if (/[0-9]/.test(sentence)) score += 2; if (/[%$€₽]/.test(sentence)) score += 2; if (index < 3) score += 3; if (index > sentences.length - 4) score += 2; if (index > 0) { const prevSentence = sentences[index - 1].toLowerCase(); const commonWords = words.filter(word => word.length > 3 && prevSentence.includes(word) ); score += commonWords.length * 0.5; } return { sentence, score, index }; }); sentenceScores.sort((a, b) => b.score - a.score); const selectedSentences = sentenceScores .slice(0, Math.ceil(sentences.length * 0.3)) .sort((a, b) => a.index - b.index); let summary = selectedSentences .map(item => item.sentence.trim()) .join('\n\n'); if (summary.length > settings.maxSummaryLength) { summary = summary.substring(0, settings.maxSummaryLength).trim(); const lastDot = summary.lastIndexOf('.'); if (lastDot > 0) { summary = summary.substring(0, lastDot + 1); } } return summary; } function createPopup(content) { const overlay = document.createElement('div'); overlay.className = 'lzt-overlay'; document.body.appendChild(overlay); const popup = document.createElement('div'); popup.className = 'lzt-popup'; popup.innerHTML = `