Skip to content

Commit 010cf24

Browse files
committed
cleaned up code, added icon, removed ribbon icon
1 parent e18bc34 commit 010cf24

File tree

10 files changed

+2812
-121
lines changed

10 files changed

+2812
-121
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This plugin solves this issue by allowing you to:
2121
- Title that is pasted when 'Open Video Player' hotkey is used
2222

2323
## Usage
24-
- Highlight a video url and select either the Ribbon clock icon or use the 'Open Video Player' hotkey
24+
- Highlight a video url and use the 'Open Video Player' hotkey
2525
- Jot down notes and anytime you want to insert a timestamp, press the registered hotkey
2626
- Toggle pausing/playing the video by using hotkey (my default is option space)
2727
- Open videos at the timestamp you left off on (this is reset if plugin is disabled)

main.js

Lines changed: 17 additions & 45 deletions
Large diffs are not rendered by default.

main.ts

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
import { Editor, MarkdownView, Notice, Plugin, } from 'obsidian';
1+
import { Editor, MarkdownView, Plugin, } from 'obsidian';
22
import ReactPlayer from 'react-player/lazy'
33

44
import { VideoView, VIDEO_VIEW } from './view/VideoView';
55
import { TimestampPluginSettings, TimestampPluginSettingTab, DEFAULT_SETTINGS } from 'settings';
6-
import { SetupVideoModal } from 'ribbonModal';
76

87

98
const ERRORS: { [key: string]: string } = {
109
"INVALID_URL": "\n> [!error] Invalid Video URL\n> The highlighted link is not a valid video url. Please try again with a valid link.\n",
11-
"NO_ACTIVE_VIDEO": "\n> [!caution] Select Video\n> A video needs to be opened before using this hotkey.\n Click the TimestampVideo ribbon icon or highlight your video link and input your 'Open video player' hotkey to register a video.\n",
10+
"NO_ACTIVE_VIDEO": "\n> [!caution] Select Video\n> A video needs to be opened before using this hotkey.\n Highlight your video link and input your 'Open video player' hotkey to register a video.\n",
1211
}
1312

1413
export default class TimestampPlugin extends Plugin {
1514
settings: TimestampPluginSettings;
1615
player: ReactPlayer;
1716
setPlaying: React.Dispatch<React.SetStateAction<boolean>>;
1817
editor: Editor;
19-
// Helper function to validate url and activate view
20-
validateURL = (url: string) => {
21-
url = url.trim();
22-
if (!ReactPlayer.canPlay(url)) return ERRORS["INVALID_URL"];
23-
if (this.settings.noteTitle) return "\n" + this.settings.noteTitle
24-
return "";
25-
}
2618

2719
async onload() {
2820
// Register view
@@ -34,17 +26,6 @@ export default class TimestampPlugin extends Plugin {
3426
// Register settings
3527
await this.loadSettings();
3628

37-
// Create ribbon button that opens modal to use for inserting video url
38-
this.addRibbonIcon("clock", "Timestamp Notes", () => {
39-
new SetupVideoModal(this.app, async (url) => {
40-
new Notice(`Opening, ${url}!`)
41-
this.validateURL(url);
42-
// Activate the view with the valid link
43-
this.activateView(url);
44-
if (this.editor) this.editor.replaceSelection("```timestamp-url \n " + url + "\n ```\n");
45-
}).open();
46-
});
47-
4829
// Markdown processor that turns timestamps into buttons
4930
this.registerMarkdownCodeBlockProcessor("timestamp", (source, el, ctx) => {
5031
// Match mm:ss or hh:mm:ss timestamp format
@@ -85,7 +66,7 @@ export default class TimestampPlugin extends Plugin {
8566
button.style.color = this.settings.urlTextColor;
8667

8768
button.addEventListener("click", () => {
88-
this.editor ? this.activateView(url, this.editor) : this.activateView(url);
69+
this.activateView(url, this.editor);
8970
});
9071
} else {
9172
if (this.editor) {
@@ -99,14 +80,18 @@ export default class TimestampPlugin extends Plugin {
9980
id: 'trigger-player',
10081
name: 'Open video player (copy video url and use hotkey)',
10182
editorCallback: (editor: Editor, view: MarkdownView) => {
102-
// Get selected text and match against video url to convert link to video video id => also triggers activateView in validateURL
83+
// Get selected text and match against video url to convert link to video video id
10384
const url = editor.getSelection().trim();
10485

10586
// Activate the view with the valid link
10687
if (ReactPlayer.canPlay(url)) {
10788
this.activateView(url, editor);
108-
editor.replaceSelection("```timestamp-url \n " + url + "\n ```\n");
89+
this.settings.noteTitle ?
90+
editor.replaceSelection("\n" + this.settings.noteTitle + "\n" + "```timestamp-url \n " + url + "\n ```\n") :
91+
editor.replaceSelection("```timestamp-url \n " + url + "\n ```\n")
10992
this.editor = editor;
93+
} else {
94+
editor.replaceSelection(ERRORS["INVALID_URL"])
11095
}
11196
editor.setCursor(editor.getCursor().line + 1)
11297
}
@@ -119,11 +104,11 @@ export default class TimestampPlugin extends Plugin {
119104
editorCallback: (editor: Editor, view: MarkdownView) => {
120105
if (!this.player) {
121106
editor.replaceSelection(ERRORS["NO_ACTIVE_VIDEO"])
107+
return
122108
}
123109

124-
const leadingZero = (num: number) => num < 10 ? "0" + num.toFixed(0) : num.toFixed(0);
125-
126110
// convert current video time into timestamp
111+
const leadingZero = (num: number) => num < 10 ? "0" + num.toFixed(0) : num.toFixed(0);
127112
const totalSeconds = Number(this.player.getCurrentTime().toFixed(2));
128113
const hours = Math.floor(totalSeconds / 3600);
129114
const minutes = Math.floor((totalSeconds - (hours * 3600)) / 60);
@@ -156,7 +141,7 @@ export default class TimestampPlugin extends Plugin {
156141
}
157142

158143
// This is called when a valid url is found => it activates the View which loads the React view
159-
async activateView(url: string, editor: Editor = null) {
144+
async activateView(url: string, editor: Editor) {
160145
this.app.workspace.detachLeavesOfType(VIDEO_VIEW);
161146

162147
await this.app.workspace.getRightLeaf(false).setViewState({

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-timestamp-notes",
33
"name": "Timestamp Notes",
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"minAppVersion": "0.12.0",
66
"description": "This plugin allows side-by-side notetaking with videos. Annotate your notes with timestamps to directly control the video and remember where each note comes from.",
77
"author": "Julian Grunauer",

0 commit comments

Comments
 (0)