Skip to content

Commit e1473dd

Browse files
committed
added word count
1 parent 3dd762c commit e1473dd

File tree

7 files changed

+37
-9
lines changed

7 files changed

+37
-9
lines changed

components.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare module 'vue' {
2424
NTooltip: typeof import('naive-ui')['NTooltip']
2525
Options: typeof import('./src/components/Options.vue')['default']
2626
Toolbar: typeof import('./src/components/Toolbar.vue')['default']
27+
WordCount: typeof import('./src/components/WordCount.vue')['default']
2728
}
2829
}
2930

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "window-reader",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"scripts": {
55
"dev": "tauri dev",
66
"build": "tauri build"

src-tauri/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "window_reader"
3-
version = "1.2.1"
3+
version = "1.2.2"
44
description = "A transparent notepad-like app"
55
authors = ["Ripwords"]
66
license = ""

src-tauri/tauri.conf.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"package": {
33
"productName": "window-reader",
4-
"version": "1.2.1"
4+
"version": "1.2.2"
55
},
66
"build": {
77
"distDir": "../dist",

src/components/Content.vue

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script lang="ts" setup>
2-
import { QuillEditor } from '@vueup/vue-quill'
3-
import { appWindow } from '@tauri-apps/api/window'
4-
import { isRegistered, register, unregister } from '@tauri-apps/api/globalShortcut'
2+
import { saveAs } from 'file-saver'
53
import { mainStore } from '../store'
4+
import { useMessage } from 'naive-ui'
65
import { pdfExporter } from 'quill-to-pdf'
76
import * as wordExporter from 'quill-to-word'
8-
import { saveAs } from 'file-saver'
9-
import { useMessage } from 'naive-ui'
7+
import { QuillEditor } from '@vueup/vue-quill'
8+
import { appWindow } from '@tauri-apps/api/window'
9+
import { isRegistered, register, unregister } from '@tauri-apps/api/globalShortcut'
1010
import '@vueup/vue-quill/dist/vue-quill.snow.css'
1111
1212
const store = mainStore()
@@ -96,6 +96,31 @@ watch([() => store.opacity, () => store.theme], () => {
9696
text.value.style.backgroundColor = `rgba(${themeColor.value}, ${themeColor.value}, ${themeColor.value}, ${store.opacity / 100})`
9797
})
9898
99+
watch(() => store.content.ops.ops, () => {
100+
let arr: any = []
101+
let count = 0
102+
store.content.ops.ops.forEach((arrItem: any) => {
103+
if(typeof(arrItem.insert) === 'string') {
104+
if(!arrItem.insert.endsWith('\n')) {
105+
arr.push(arrItem.insert.split(' '))
106+
} else {
107+
arr.push(arrItem.insert.split('\n'))
108+
}
109+
}
110+
})
111+
arr.forEach((arrItem: any) => {
112+
arrItem.forEach((item: any) => {
113+
const words = item.split(" ")
114+
words.forEach((word: any) => {
115+
if(word.length > 0) {
116+
count++
117+
}
118+
})
119+
})
120+
})
121+
store.wordCount = count
122+
})
123+
99124
appWindow.listen("tauri://blur", () => {
100125
shortcutUnregister()
101126
})
@@ -123,6 +148,7 @@ await shortcutRegister()
123148
@changeSpellcheck="changeSpellcheck()"
124149
/>
125150
<div :class="{ 'dark': store.theme === 'dark' }">
151+
<div class="fixed right-1 mt-1 z-20 text-size-[12px] opacity-70 text-dark-900 dark:text-light-500 transition-colors duration-150 ease-linear">{{ store.wordCount }}</div>
126152
<div v-show="settings" class="absolute z-10 w-8/10 h-20px bottom-100px transform translate-x-5vh">
127153
<n-h2 class="text-dark-900 dark:text-light-50">Opacity</n-h2>
128154
<n-slider :theme-overrides="store.themeOverrides" v-model:value="store.opacity" :step="1"></n-slider>

src/store.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const mainStore = defineStore('mainStore', {
99
}
1010
},
1111
content: useSessionStorage('content', { ops: [] }) as any,
12+
wordCount: useSessionStorage('wordCount', 0),
1213
opacity: useLocalStorage('opacity', 50),
1314
theme: useLocalStorage('theme', 'dark'),
1415
exportName: useLocalStorage('exportName', 'export'),

0 commit comments

Comments
 (0)