blog: kopier-knap paa kodeblokke
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
54fc09ca0e
commit
428df33cf5
@@ -72,4 +72,39 @@ const crumbs = breadcrumb([
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
||||
<style is:global>
|
||||
.prose pre { position: relative; }
|
||||
.copy-btn {
|
||||
position: absolute; top: .45rem; right: .45rem;
|
||||
font-size: .68rem; line-height: 1; padding: .35rem .6rem;
|
||||
color: var(--color-muted); background: var(--color-surface-2);
|
||||
border: 1px solid var(--color-border); border-radius: .5rem;
|
||||
opacity: 0; transition: opacity .15s ease; cursor: pointer;
|
||||
}
|
||||
.prose pre:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
|
||||
.copy-btn:hover { color: var(--color-text); }
|
||||
</style>
|
||||
<script is:inline>
|
||||
(function () {
|
||||
if (window.__copycode) return; window.__copycode = true;
|
||||
var enhance = function () {
|
||||
document.querySelectorAll('.prose pre').forEach(function (pre) {
|
||||
if (pre.querySelector('.copy-btn')) return;
|
||||
var b = document.createElement('button');
|
||||
b.className = 'copy-btn'; b.type = 'button'; b.textContent = 'kopiér';
|
||||
b.addEventListener('click', function () {
|
||||
var code = pre.querySelector('code');
|
||||
navigator.clipboard.writeText(code ? code.innerText : pre.innerText).then(function () {
|
||||
b.textContent = 'kopieret ✓';
|
||||
setTimeout(function () { b.textContent = 'kopiér'; }, 1500);
|
||||
});
|
||||
});
|
||||
pre.appendChild(b);
|
||||
});
|
||||
};
|
||||
document.addEventListener('astro:page-load', enhance);
|
||||
enhance();
|
||||
})();
|
||||
</script>
|
||||
</Base>
|
||||
|
||||
Reference in New Issue
Block a user