forked from FHachez/obsidian-convert-url-to-iframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
39 lines (34 loc) · 1012 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Notice, Plugin } from 'obsidian';
import { isUrl, updateUrlIfYoutube } from 'iframe_converter';
import { ConfigureIframeModal } from './configure_iframe_modal';
export default class FormatNotionPlugin extends Plugin {
async onload() {
console.log(this.app);
this.addCommand({
id: "url-to-iframe",
name: "URL to iframe/preview",
callback: () => this.urlToIframe(),
hotkeys: [
{
modifiers: ["Mod", "Shift"],
key: "i",
},
],
});
}
urlToIframe(): void {
let activeLeaf: any = this.app.workspace.activeLeaf;
let editor = activeLeaf.view.sourceMode.cmEditor;
let selectedText = editor.somethingSelected()
? editor.getSelection()
: false;
if (selectedText && isUrl(selectedText)) {
const url = updateUrlIfYoutube(selectedText)
const modal = new ConfigureIframeModal(this.app, url, editor)
modal.open();
console.log(modal)
} else {
new Notice('Select a URL to convert to an iframe.');
}
}
}