mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-11-25 04:43:04 +00:00
22 lines
520 B
JavaScript
22 lines
520 B
JavaScript
(function () {
|
|
function select(element) {
|
|
const selection = window.getSelection();
|
|
|
|
const range = document.createRange();
|
|
range.selectNodeContents(element);
|
|
|
|
selection.removeAllRanges();
|
|
selection.addRange(range);
|
|
}
|
|
|
|
document.querySelectorAll("pre code").forEach(code => {
|
|
code.addEventListener("click", function (event) {
|
|
select(code.parentElement);
|
|
|
|
if (navigator.clipboard) {
|
|
navigator.clipboard.writeText(code.parentElement.textContent);
|
|
}
|
|
});
|
|
});
|
|
})();
|