2021-05-03 23:52:00 +02:00
|
|
|
(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) {
|
2022-07-04 08:55:54 +02:00
|
|
|
if (window.getSelection().toString()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-03 23:52:00 +02:00
|
|
|
select(code.parentElement);
|
|
|
|
|
|
|
|
if (navigator.clipboard) {
|
|
|
|
navigator.clipboard.writeText(code.parentElement.textContent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|