From d44ea0d566ac0ba9f6858903cf8fc23be99d8159 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 17 Nov 2025 09:31:36 +0100 Subject: [PATCH] contrib/html: support click on code block to copy to clipboard --- contrib/html.sh | 2 ++ contrib/html.sh.d/head.html | 1 + general/clipboard.js | 4 ++++ 3 files changed, 7 insertions(+) create mode 100644 general/clipboard.js diff --git a/contrib/html.sh b/contrib/html.sh index 11dcefc..182ad97 100755 --- a/contrib/html.sh +++ b/contrib/html.sh @@ -10,12 +10,14 @@ sed \ -e "s|__LOGO__|$(realpath --relative-to="${RELTO}" logo.png)|" \ -e "s|__EWORM__|$(realpath --relative-to="${RELTO}" general/eworm-meadow.avif)|" \ -e "s|__QR_CODE__|$(realpath --relative-to="${RELTO}" general/qr-code.png)|" \ + -e "s|__CLIPBOARD__|$(realpath --relative-to="${RELTO}" general/clipboard.js)|" \ < "${0}.d/head.html" markdown -f toc,idanchor "${1}" | sed \ -e 's/href="\([-_\./[:alnum:]]*\)\.md\(#[-[:alnum:]]*\)\?"/href="\1.html\2"/g' \ -e '/| id="\L\1">|' \ -e '//s|pre|pre onclick="CopyToClipboard(this)"|g' \ -e '/The above link may be broken on code hosting sites/s|blockquote|blockquote style="display: none;"|' sed \ diff --git a/contrib/html.sh.d/head.html b/contrib/html.sh.d/head.html index da54157..861a87b 100644 --- a/contrib/html.sh.d/head.html +++ b/contrib/html.sh.d/head.html @@ -3,6 +3,7 @@ RouterOS Scripts :: __TITLE__ + diff --git a/general/clipboard.js b/general/clipboard.js new file mode 100644 index 0000000..c392df7 --- /dev/null +++ b/general/clipboard.js @@ -0,0 +1,4 @@ +/* copy code to clipboard */ +function CopyToClipboard(pre) { + navigator.clipboard.writeText(pre.firstElementChild.innerHTML); +}