您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a copy button to copy the content of the specified pre element
// ==UserScript== // @name SAP AI Playground | Copy Pre Content Button // @namespace http://tampermonkey.net/ // @version 1.0 // @description Adds a copy button to copy the content of the specified pre element // @author ChatGPT, tddschn // @match https://ai-playground.cfapps.sap.hana.ondemand.com/index.html // @grant none // ==/UserScript== (function() { 'use strict'; function processChildNodes(element) { let textContent = ''; for (const child of element.childNodes) { if (child.nodeType === Node.TEXT_NODE) { textContent += child.textContent; } else if (child.tagName === 'BR') { textContent += '\n'; } } return textContent; } function copyToClipboard(text) { const textarea = document.createElement('textarea'); textarea.value = text; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); } function addButton() { const preElement = document.querySelector('body > div > div:nth-child(2) > div:nth-child(2) > pre'); if (preElement) { const copyButton = document.createElement('button'); copyButton.textContent = 'Copy'; copyButton.style.position = 'absolute'; copyButton.style.zIndex = 1000; copyButton.addEventListener('click', () => { const preContent = processChildNodes(preElement); copyToClipboard(preContent); }); preElement.parentElement.insertBefore(copyButton, preElement); } } addButton(); })();