mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
1.0.1
This commit is contained in:
27
main.ts
27
main.ts
@@ -1,4 +1,4 @@
|
||||
import { TFile, Plugin } from 'obsidian';
|
||||
import { TFile, Plugin, MarkdownView } from 'obsidian';
|
||||
|
||||
interface WordCount {
|
||||
initial: number;
|
||||
@@ -26,18 +26,18 @@ export default class DailyStats extends Plugin {
|
||||
|
||||
this.statusBarEl = this.addStatusBarItem();
|
||||
this.updateDate();
|
||||
if (this.today in this.settings.dayCounts) {
|
||||
if (this.settings.dayCounts.hasOwnProperty(this.today)) {
|
||||
this.updateCounts();
|
||||
} else {
|
||||
this.currentWordCount = 0;
|
||||
}
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("quit", this.onunload, this)
|
||||
this.app.workspace.on("quit", this.onunload.bind(this))
|
||||
);
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("quick-preview", this.onQuickPreview, this)
|
||||
this.app.workspace.on("quick-preview", this.onQuickPreview.bind(this))
|
||||
);
|
||||
|
||||
this.registerInterval(
|
||||
@@ -56,12 +56,9 @@ export default class DailyStats extends Plugin {
|
||||
await this.saveSettings();
|
||||
}
|
||||
|
||||
//Credit: better-word-count by Luke Leppan (https://github.com/lukeleppan/better-word-count)
|
||||
onQuickPreview(file: TFile, contents: string) {
|
||||
const leaf = this.app.workspace.activeLeaf;
|
||||
|
||||
if (leaf && leaf.view.getViewType() === "markdown") {
|
||||
this.updateWordCount(contents, file.name);
|
||||
if (this.app.workspace.getActiveViewOfType(MarkdownView)) {
|
||||
this.updateWordCount(contents, file.path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,17 +83,17 @@ export default class DailyStats extends Plugin {
|
||||
return words;
|
||||
}
|
||||
|
||||
updateWordCount(contents: string, filename: string) {
|
||||
updateWordCount(contents: string, filepath: string) {
|
||||
const curr = this.getWordCount(contents);
|
||||
if (this.today in this.settings.dayCounts) {
|
||||
if (filename in this.settings.todaysWordCount) {//updating existing file
|
||||
this.settings.todaysWordCount[filename].current = curr;
|
||||
if (this.settings.dayCounts.hasOwnProperty(this.today)) {
|
||||
if (this.settings.todaysWordCount.hasOwnProperty(filepath)) {//updating existing file
|
||||
this.settings.todaysWordCount[filepath].current = curr;
|
||||
} else {//created new file during session
|
||||
this.settings.todaysWordCount[filename] = { initial: curr, current: curr };
|
||||
this.settings.todaysWordCount[filepath] = { initial: curr, current: curr };
|
||||
}
|
||||
} else {//new day, flush the cache
|
||||
this.settings.todaysWordCount = {};
|
||||
this.settings.todaysWordCount[filename] = { initial: curr, current: curr };
|
||||
this.settings.todaysWordCount[filepath] = { initial: curr, current: curr };
|
||||
}
|
||||
this.updateCounts();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"id": "obsidian-daily-stats",
|
||||
"name": "Daily Stats",
|
||||
"version": "1.0.0",
|
||||
"minAppVersion": "0.9.12",
|
||||
"version": "1.0.1",
|
||||
"minAppVersion": "0.9.10",
|
||||
"description": "Track your daily word count across all notes in your vault.",
|
||||
"author": "Dhruvik Parikh",
|
||||
"authorUrl": "https://github.com/dhruvik7",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "obsidian-daily-stats",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "This is an Obsidian.md plugin that lets you view your daily word count.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user