Add enhanced Markdown to LinkedIn conversion and X thread splitter

This commit is contained in:
2026-04-29 23:28:28 +02:00
parent a7db8ef418
commit 834451f33b
6 changed files with 417 additions and 55 deletions
+72
View File
@@ -0,0 +1,72 @@
import { App, Modal } from "obsidian";
export class ThreadModal extends Modal {
private tweets: string[];
constructor(app: App, tweets: string[]) {
super(app);
this.tweets = tweets;
}
onOpen(): void {
const { contentEl } = this;
contentEl.empty();
contentEl.addClass("unicode-thread-modal");
const headingText = this.tweets.length === 1
? "X post"
: `X thread (${this.tweets.length} posts)`;
contentEl.createEl("h3", { text: headingText });
const list = contentEl.createDiv({ cls: "thread-tweet-list" });
for (let i = 0; i < this.tweets.length; i++) {
const tweet = this.tweets[i]!;
const item = list.createDiv({ cls: "thread-tweet-item" });
const header = item.createDiv({ cls: "thread-tweet-header" });
if (this.tweets.length > 1) {
header.createSpan({
text: `Post ${i + 1}/${this.tweets.length}`,
cls: "thread-tweet-label",
});
}
item.createEl("textarea", {
text: tweet,
attr: { readonly: "true" },
cls: "thread-tweet-textarea",
});
const copyBtn = item.createEl("button", {
text: "Copy",
cls: "thread-copy-button",
});
copyBtn.addEventListener("click", () => {
navigator.clipboard.writeText(tweet).then(() => {
copyBtn.setText("Copied");
setTimeout(() => copyBtn.setText("Copy"), 2000);
}).catch(() => {});
});
}
if (this.tweets.length > 1) {
const copyAllBtn = contentEl.createEl("button", {
text: "Copy all",
cls: "thread-copy-all-button",
});
copyAllBtn.addEventListener("click", () => {
const all = this.tweets.join("\n\n");
navigator.clipboard.writeText(all).then(() => {
copyAllBtn.setText("Copied");
setTimeout(() => copyAllBtn.setText("Copy all"), 2000);
}).catch(() => {});
});
}
}
onClose(): void {
const { contentEl } = this;
contentEl.empty();
}
}