Removed status bar, replaced with Show: Stats command

This commit is contained in:
Zef Hemel
2022-08-01 11:04:48 +02:00
parent 525b30c9bb
commit ec7c272594
6 changed files with 30 additions and 42 deletions
+8
View File
@@ -342,3 +342,11 @@ functions:
path: ./link.ts:titleUnfurl
events:
- unfurl:title-unfurl
# Random stuff
statsCommand:
path: ./stats.ts:statsCommand
command:
name: "Stats: Show"
key: "Ctrl-Shift-s"
mac: "Cmd-Shift-s"
+21
View File
@@ -0,0 +1,21 @@
import {
flashNotification,
getText,
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
function countWords(str: string): number {
const matches = str.match(/[\w\d\'-]+/gi);
return matches ? matches.length : 0;
}
function readingTime(wordCount: number): number {
// 225 is average word reading speed for adults
return Math.ceil(wordCount / 225);
}
export async function statsCommand() {
const text = await getText();
const wordCount = countWords(text);
const time = readingTime(wordCount);
await flashNotification(`${wordCount} words, ${time} minutes to read.`);
}