Files
meet/docs/javascripts/console-copy.js
T
unteem d06fddab56 📝(doc) create complete documentation website for Meet
Add a documentation site built with Zensical: getting started,
self-hosting with compose and Kubernetes, configuration, user guide,
contributing and reference pages, and every environment variable on
one page, grouped by feature.

Co-authored-by: davd-gzl <60177543+davd-gzl@users.noreply.github.com>
2026-11-16 10:59:49 +01:00

22 lines
748 B
JavaScript

// The copy button of a terminal block copies its commands alone: no $ prompt, no output.
// The text is built at the click, so a page the preview reloaded copies what it shows.
function consoleCommands(code) {
const commands = []
for (const line of code.textContent.split("\n")) {
if (line.startsWith("$ ")) commands.push(line.slice(2))
}
return commands.join("\n")
}
document.addEventListener(
"click",
(event) => {
const button = event.target.closest("[data-clipboard-target]")
if (!button) return
const code = document.querySelector(button.dataset.clipboardTarget)
const commands = code?.querySelector(".gp") && consoleCommands(code)
if (commands) code.closest("pre").dataset.copy = commands
},
true,
)