您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
提取并复制 ytd-engagement-panel-section-list-renderer 标签下的文本
当前为
// ==UserScript== // @name YouTube Engagement Panel Text Extractor // @namespace http://tampermonkey.net/ // @version 0.2 // @description 提取并复制 ytd-engagement-panel-section-list-renderer 标签下的文本 // @author 微信:civilpy // @match https://www.youtube.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // 创建一个容器来保持两个按钮在一起 const buttonContainer = document.createElement('div'); buttonContainer.style.position = 'fixed'; buttonContainer.style.top = '50%'; // 设置为页面高度的50% buttonContainer.style.right = '10px'; // 距离右侧10像素 buttonContainer.style.transform = 'translateY(-50%)'; // 垂直居中对齐 buttonContainer.style.display = 'flex'; buttonContainer.style.flexDirection = 'column'; buttonContainer.style.alignItems = 'flex-end'; // 将子元素靠右对齐 // 创建两个按钮 const button1 = document.createElement('button'); button1.innerText = '提取文字'; button1.style.marginBottom = '10px'; // 给两个按钮之间添加一些间距 const button2 = document.createElement('button'); button2.innerText = '复制文字'; button2.disabled = true; // 初始状态下禁用复制按钮 // 添加到容器 buttonContainer.appendChild(button1); buttonContainer.appendChild(button2); // 添加到页面 document.body.appendChild(buttonContainer); let extractedText = ''; // 按钮1点击事件 - 提取文字 button1.addEventListener('click', () => { // 查找所有ytd-engagement-panel-section-list-renderer元素并提取其文本内容 const elements = document.querySelectorAll('ytd-engagement-panel-section-list-renderer'); // 提取文本并去除前后空白,过滤掉空行或仅有空白字符的行 extractedText = Array.from(elements) .map(el => el.textContent.trim()) .filter(line => line.length > 0) // 过滤掉空行 .join('\n'); console.log('已提取的文字:', extractedText); // 输出到控制台供调试 // 启用复制按钮 button2.disabled = false; }); // 按钮2点击事件 - 复制文字 button2.addEventListener('click', () => { if (extractedText) { navigator.clipboard.writeText("分析总结以下文本:\n"+extractedText).then(() => { console.log('文本已复制到剪贴板'); alert('文本已复制到剪贴板'); }).catch(err => { console.error('无法复制文本: ', err); }); } }); })();