Skip to content

Commit

Permalink
Removed console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lstrzepek committed Feb 3, 2023
1 parent 4a843e0 commit d541c3b
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 191 deletions.
204 changes: 101 additions & 103 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,117 +1,115 @@
import { App, Editor, MarkdownView, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { TranscriptView, TRANSCRIPT_TYPE_VIEW } from 'transcript-view';
import { EditorExtensions } from './editor-extensions';
import { EditorExtensions } from './editor-extensions';

interface YTranscriptSettings {
timestampMod: number;
lang: string;
country: string;
timestampMod: number;
lang: string;
country: string;
}

const DEFAULT_SETTINGS: YTranscriptSettings = {
timestampMod: 5,
lang: 'en',
country: 'EN'
timestampMod: 5,
lang: 'en',
country: 'EN'
}

export default class YTranscriptPlugin extends Plugin {
settings: YTranscriptSettings;

async onload() {
await this.loadSettings();

this.registerView(TRANSCRIPT_TYPE_VIEW,
(leaf) => new TranscriptView(leaf, this));

this.addCommand({
id: 'fetch-transcript',
name: "Fetch transcription",
editorCallback: (editor: Editor, _: MarkdownView) => {
const url = EditorExtensions.getSelectedText(editor).trim();
console.log(url);
this.openView(url);
}
});

this.addSettingTab(new YTranslateSettingTab(this.app, this));
}

async openView(url: string) {
const leaf = this.app.workspace.getRightLeaf(false);
await leaf.setViewState({
type: TRANSCRIPT_TYPE_VIEW
});
this.app.workspace.revealLeaf(leaf);
leaf.setEphemeralState({
url,
timestampMod: this.settings.timestampMod,
lang: this.settings.lang,
country: this.settings.country
});
}

onunload() {
this.app.workspace.detachLeavesOfType(TRANSCRIPT_TYPE_VIEW);
}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async saveSettings() {
await this.saveData(this.settings);
}
settings: YTranscriptSettings;

async onload() {
await this.loadSettings();

this.registerView(TRANSCRIPT_TYPE_VIEW,
(leaf) => new TranscriptView(leaf, this));

this.addCommand({
id: 'fetch-transcript',
name: "Fetch transcription",
editorCallback: (editor: Editor, _: MarkdownView) => {
const url = EditorExtensions.getSelectedText(editor).trim();
this.openView(url);
}
});

this.addSettingTab(new YTranslateSettingTab(this.app, this));
}

async openView(url: string) {
const leaf = this.app.workspace.getRightLeaf(false);
await leaf.setViewState({
type: TRANSCRIPT_TYPE_VIEW
});
this.app.workspace.revealLeaf(leaf);
leaf.setEphemeralState({
url,
timestampMod: this.settings.timestampMod,
lang: this.settings.lang,
country: this.settings.country
});
}

onunload() {
this.app.workspace.detachLeavesOfType(TRANSCRIPT_TYPE_VIEW);
}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async saveSettings() {
await this.saveData(this.settings);
}
}

class YTranslateSettingTab extends PluginSettingTab {
plugin: YTranscriptPlugin;
values: Record<string, string>;


/**
*
*/
constructor(app: App, plugin: YTranscriptPlugin) {
super(app, plugin);
this.plugin = plugin;
}

display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h2', { text: 'Settings for YTranslate' });

new Setting(containerEl)
.setName('Timestamp mod')
.setDesc('Indicates how often timestamp should occure in text (1 - every line, 10 - every 10 lines)')
.addText(text => text
.setValue(this.plugin.settings.timestampMod.toFixed())
.onChange(async (value) => {
console.log('Timestamp:', value);
const v = Number.parseInt(value);
this.plugin.settings.timestampMod = Number.isNaN(v) ? 5 : v;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Language')
.setDesc('Prefered transcript language')
.addText(text => text
.setValue(this.plugin.settings.lang)
.onChange(async (value) => {
this.plugin.settings.lang = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Country')
.setDesc('Prefered transcript country code')
.addText(text => text
.setValue(this.plugin.settings.country)
.onChange(async (value) => {
this.plugin.settings.country = value;
await this.plugin.saveSettings();
}));

}
plugin: YTranscriptPlugin;
values: Record<string, string>;


/**
*
*/
constructor(app: App, plugin: YTranscriptPlugin) {
super(app, plugin);
this.plugin = plugin;
}

display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h2', { text: 'Settings for YTranslate' });

new Setting(containerEl)
.setName('Timestamp mod')
.setDesc('Indicates how often timestamp should occure in text (1 - every line, 10 - every 10 lines)')
.addText(text => text
.setValue(this.plugin.settings.timestampMod.toFixed())
.onChange(async (value) => {
const v = Number.parseInt(value);
this.plugin.settings.timestampMod = Number.isNaN(v) ? 5 : v;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Language')
.setDesc('Prefered transcript language')
.addText(text => text
.setValue(this.plugin.settings.lang)
.onChange(async (value) => {
this.plugin.settings.lang = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Country')
.setDesc('Prefered transcript country code')
.addText(text => text
.setValue(this.plugin.settings.country)
.onChange(async (value) => {
this.plugin.settings.country = value;
await this.plugin.saveSettings();
}));

}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-ytranscript",
"name": "YTranscript",
"version": "0.6.1",
"version": "0.6.2",
"minAppVersion": "0.15.0",
"description": "This is simple plugin to fetch transcription for Youtube.",
"author": "Łukasz Strzępek",
Expand Down
Loading

0 comments on commit d541c3b

Please sign in to comment.