I fixed it
urlToIframe(editor) {
let selectedText = editor.somethingSelected()
? editor.getSelection()
: false;
if (selectedText && this.isUrl(selectedText) && selectedText.includes("www.youtube.com/watch")) {
const url = selectedText;
ajaxPromise({
url: `http://iframely.server.crestify.com/iframely?url=${url}`,
}).then((res) => {
const data = JSON.parse(res);
const imageLink = data.links[3].href || '';
editor.replaceSelection(`
<div class="rich-link-card-container"><a class="rich-link-card" href="${url}" target="_blank">
<div class="rich-link-image-container">
<div class="rich-link-image" style="background-image: url('${imageLink}')">
</div>
</div>
<div class="rich-link-card-text">
<h1 class="rich-link-card-title">${(data.meta.title || "").replace(/\s{3,}/g, ' ').trim()}</h1>
<p class="rich-link-href">
${(data.meta.author)}
</p>
</div>
</a></div>
`);
});
}
else if (selectedText && this.isUrl(selectedText)) {
const url = selectedText;
ajaxPromise({
url: `http://iframely.server.crestify.com/iframely?url=${url}`,
}).then((res) => {
const data = JSON.parse(res);
const imageLink = data.links[0].href || '';
editor.replaceSelection(`
<div class="rich-link-card-container"><a class="rich-link-card" href="${url}" target="_blank">
<div class="rich-link-image-container">
<div class="rich-link-image" style="background-image: url('${imageLink}')">
</div>
</div>
<div class="rich-link-card-text">
<h1 class="rich-link-card-title">${(data.meta.title || "").replace(/\s{3,}/g, ' ').trim()}</h1>
<p class="rich-link-href">
${selectedText}
</p>
</div>
</a></div>
`);
});
}
else {
new obsidian.Notice("Select a URL to convert to rich link.");
}
}