mirror of
https://github.com/lizard-heart/obsidian-to-omnifocus.git
synced 2026-07-22 07:30:26 +00:00
refactor
This commit is contained in:
parent
b7aecc8ad6
commit
05e7ef1219
2 changed files with 30 additions and 87 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "tasks-to-omnifocus",
|
"id": "tasks-to-omnifocus",
|
||||||
"name": "Send Tasks to OmniFocus",
|
"name": "Send Tasks to OmniFocus",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"minAppVersion": "0.12.0",
|
"minAppVersion": "0.12.0",
|
||||||
"description": "An Obsidian plugin will extract tasks from the current note and create them in OmniFocus.",
|
"description": "An Obsidian plugin will extract tasks from the current note and create them in OmniFocus.",
|
||||||
"author": "Henry Gustafson",
|
"author": "Henry Gustafson",
|
||||||
|
|
|
||||||
115
src/main.ts
115
src/main.ts
|
|
@ -21,40 +21,13 @@ export default class TasksToOmnifocus extends Plugin {
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
// this.addCommand({
|
|
||||||
// id: "extract-tasks",
|
|
||||||
// name: "Extract Tasks Into OmniFocus",
|
|
||||||
// callback: () => this.sendToOF(),
|
|
||||||
// });
|
|
||||||
|
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: 'extract-tasks',
|
id: 'extract-tasks',
|
||||||
name: 'Extract Tasks Into OmniFocus',
|
name: 'Extract Tasks Into OmniFocus',
|
||||||
editorCallback: (editor: Editor, view: MarkdownView) => {
|
editorCallback: (editor: Editor, view: MarkdownView) => {
|
||||||
const editorText = editor.getValue()
|
const editorText = editor.getValue()
|
||||||
try {
|
this.addToOmnifocus(editorText, editor, view);
|
||||||
let tasks = editorText.match(/- \[ \] .*/g);
|
|
||||||
|
|
||||||
for (let task of tasks) {
|
|
||||||
let taskName = task.replace("- [ ] ", "");
|
|
||||||
let taskNameEncoded = encodeURIComponent(taskName);
|
|
||||||
let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
|
|
||||||
let vaultName = app.vault.getName();
|
|
||||||
let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL);
|
|
||||||
|
|
||||||
window.open(
|
|
||||||
`omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.settings.markComplete) {
|
|
||||||
let completedText = editorText.replace(/- \[ \]/g, "- [x]");
|
|
||||||
editor.setValue(completedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -62,76 +35,46 @@ export default class TasksToOmnifocus extends Plugin {
|
||||||
id: 'extract-tasks-selection',
|
id: 'extract-tasks-selection',
|
||||||
name: 'Extract Tasks from selection Into OmniFocus',
|
name: 'Extract Tasks from selection Into OmniFocus',
|
||||||
editorCallback: (editor: Editor, view: MarkdownView) => {
|
editorCallback: (editor: Editor, view: MarkdownView) => {
|
||||||
const editorText = editor.getSelection()
|
const editorText = editor.getSelection();
|
||||||
try {
|
this.addToOmnifocus(editorText, editor, view);
|
||||||
let tasks = editorText.match(/- \[ \] .*/g);
|
|
||||||
|
|
||||||
for (let task of tasks) {
|
|
||||||
let taskName = task.replace("- [ ] ", "");
|
|
||||||
let taskNameEncoded = encodeURIComponent(taskName);
|
|
||||||
let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
|
|
||||||
let vaultName = app.vault.getName();
|
|
||||||
let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL);
|
|
||||||
|
|
||||||
window.open(
|
|
||||||
`omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.settings.markComplete) {
|
|
||||||
let completedText = editorText.replace(/- \[ \]/g, "- [x]");
|
|
||||||
editor.replaceSelection(completedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
|
this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async addToOmnifocus(editorText: string, editor: Editor, view: MarkdownView) {
|
||||||
|
try {
|
||||||
|
let tasks = editorText.match(/- \[ \] .*/g);
|
||||||
|
|
||||||
|
for (let task of tasks) {
|
||||||
|
let taskName = task.replace("- [ ] ", "");
|
||||||
|
let taskNameEncoded = encodeURIComponent(taskName);
|
||||||
|
let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
|
||||||
|
let vaultName = app.vault.getName();
|
||||||
|
let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL);
|
||||||
|
|
||||||
|
window.open(
|
||||||
|
`omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.settings.markComplete) {
|
||||||
|
let completedText = editorText.replace(/- \[ \]/g, "- [x]");
|
||||||
|
editor.replaceSelection(completedText);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
await this.saveData(this.settings);
|
await this.saveData(this.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
onunload() {}
|
onunload() {}
|
||||||
|
|
||||||
// // the first function that runs
|
|
||||||
// async sendToOF() {
|
|
||||||
// // const app = window.app as App;
|
|
||||||
// const view = this.app.workspace.getActiveViewOfType(MarkdownView);
|
|
||||||
// if (view!=null) {
|
|
||||||
// const editor = view.editor;
|
|
||||||
// const editorText = editor.getValue();
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// let tasks = editorText.match(/- \[ \] .*/g);
|
|
||||||
|
|
||||||
// for (let task of tasks) {
|
|
||||||
// let taskName = task.replace("- [ ] ", "");
|
|
||||||
// let taskNameEncoded = encodeURIComponent(taskName);
|
|
||||||
// let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
|
|
||||||
// let vaultName = app.vault.getName();
|
|
||||||
// let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file="+noteURL);
|
|
||||||
|
|
||||||
// window.open(
|
|
||||||
// `omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}`
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (this.settings.markComplete) {
|
|
||||||
// let completedText = editorText.replace(/- \[ \]/g, "- [x]");
|
|
||||||
// editor.setValue(completedText);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// } catch (err) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
private async loadSettings() {
|
private async loadSettings() {
|
||||||
this.settings = Object.assign(
|
this.settings = Object.assign(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue