2026-06-08 20:51:09 +00:00
|
|
|
// retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
import { Component } from "./Component.js";
|
|
|
|
|
import { contentRenderer } from "../ContentRenderer.js";
|
|
|
|
|
|
|
|
|
|
export class AppContent extends Component {
|
|
|
|
|
connectedCallback() {
|
|
|
|
|
if (this._rendered) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (typeof DOMPurify === "undefined" || typeof marked === "undefined") {
|
|
|
|
|
window.addEventListener("load", () => this.connectedCallback(), { once: true });
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-06 03:57:47 +00:00
|
|
|
if (!contentRenderer.emojiLoaded) {
|
|
|
|
|
contentRenderer.ready.then(() => this.connectedCallback());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-06-08 20:51:09 +00:00
|
|
|
this._rendered = true;
|
2026-06-15 12:10:14 +00:00
|
|
|
this._source = this.textContent;
|
2026-06-08 20:51:09 +00:00
|
|
|
this.classList.add("rendered-content");
|
|
|
|
|
contentRenderer.applyTo(this);
|
|
|
|
|
if (typeof hljs !== "undefined") {
|
|
|
|
|
this.querySelectorAll("pre code").forEach((block) => hljs.highlightElement(block));
|
|
|
|
|
}
|
2026-06-15 12:10:14 +00:00
|
|
|
if (!this.hasAttribute("no-copy")) {
|
|
|
|
|
this.addCopyButton();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addCopyButton() {
|
|
|
|
|
if (!this._source || !this._source.trim()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.querySelector(":scope > .content-copy-btn")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const btn = document.createElement("button");
|
|
|
|
|
btn.type = "button";
|
|
|
|
|
btn.className = "content-copy-btn";
|
|
|
|
|
btn.textContent = "Copy";
|
|
|
|
|
btn.addEventListener("click", async () => {
|
|
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(this._source);
|
|
|
|
|
btn.textContent = "Copied";
|
|
|
|
|
} catch {
|
|
|
|
|
btn.textContent = "Failed";
|
|
|
|
|
}
|
|
|
|
|
setTimeout(() => { btn.textContent = "Copy"; }, 1500);
|
|
|
|
|
});
|
|
|
|
|
this.appendChild(btn);
|
2026-06-08 20:51:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customElements.define("dp-content", AppContent);
|