Skip to content

Commit

Permalink
Added the word count reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
fjwillemsen committed Aug 11, 2022
1 parent 15ec92f commit cd5be2b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ However, would it not be even better if it were to behave like a native app on y
- The preferences pane can be found in the same left-side menu as the other Overleaf settings.
- You can run multiple instances of Native Overleaf, allowing you to keep multiple projects open at the same time and receive notifications for each project.
- The word count tracker tracks the total words in the project, so includes anything written by other authors. It counts the words in the compiled PDF, hence it must be recompiled to reflect recent changes.
- The word count tracker uses the local date of your system, hence inconsistencies may arise when switching time zones. If necessary, the word count can be reset using the button in the preferences pane.
- Notice on notifications: For notifications to work, the app must be allowed to by your system. You will only receive notifications for projects that are opened in the background, so you will not get notifications while working in a project. **Important**: to get notifications for chats, the chat window must have been opened at least once after loading a project (you can close it again). This is a limitation of the way we listen for new chat messages. If someone has a better idea, please get in touch.

## How it works
Expand Down
2 changes: 1 addition & 1 deletion Scripts/appversion.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const appversion = "1.5.0";
const appversion = "1.5.1";
2 changes: 1 addition & 1 deletion Scripts/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function getWordCountChartConfig() {

// get the labels and data
const wordcounts_project = wordcounts[this.project_id];
if (wordcounts == undefined || wordcounts.size() <= 0) {
if (wordcounts == undefined || Object.keys(wordcounts).length <= 0) {
alert("Wordcounts have not been tracked, enable wordcount tracking and reload the project");
}
for (const [date, wordcount] of Object.entries(wordcounts_project)) {
Expand Down
17 changes: 17 additions & 0 deletions Scripts/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ function setupPreferencesPane() {
<br/>
<br/>
<div class="btn btn-primary" id="button_show_wordcount_graph">Show wordcount graph</div>
<br/>
<br/>
<div class="btn btn-warning" id="button_reset_wordcount">Reset wordcount</div>
</div>
</form>`;
if (document.querySelector("#left-menu")) {
Expand Down Expand Up @@ -184,6 +187,20 @@ function setupPreferencesPane() {
document.getElementById("button_show_wordcount_graph").addEventListener("click", () => {
showWordCountChart();
});
document.getElementById("button_reset_wordcount").addEventListener("click", () => {
let text_number_of_days = "";
if (wordcounts !== undefined && wordcounts[this.project_id] !== undefined) {
text_number_of_days = `You currently have ${
Object.keys(wordcounts[this.project_id]).length
} tracked days.`;
}
const resetWordCount = confirm(`Are you sure you want to remove all tracked wordcount history?
${text_number_of_days}`);
if (resetWordCount) {
resetWordCounts();
setupWordCount();
}
});
}
}

Expand Down
1 change: 1 addition & 0 deletions Scripts/wordcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function getWordCounts() {

// reset the wordcount history (in case you change your system's date / cross the international dateline)
function resetWordCounts() {
wordcounts = undefined;
return localStorage.removeItem("wordcounts");
}

Expand Down
2 changes: 1 addition & 1 deletion bundled_script.js

Large diffs are not rendered by default.

0 comments on commit cd5be2b

Please sign in to comment.