Skip to content

Commit

Permalink
Negative word check. Closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusurbelis committed Apr 15, 2021
1 parent bcabc27 commit db77ae6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function createWindow() {
resizable: false
});

win.removeMenu();
// win.removeMenu();

win.on("page-title-updated", event => event.preventDefault());

Expand Down
21 changes: 20 additions & 1 deletion src/classes/DatabaseManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,33 @@ export default class DatabaseManager {
var streak = summary({ dates });
stats.uploadStreak = streak.currentStreak;

console.log(streak);
// console.log(streak);

resolve(stats);
}
);
});
}

getNegativeWordsList() {
return new Promise(resolve => {
var request = require("request");
request.get(
"https://gist.githubusercontent.com/mkulakowski2/4289441/raw/dad8b64b307cd6df8068a379079becbb3f91101a/negative-words.txt",
function(error, response, body) {
if (!error && response.statusCode == 200) {
var wordsString = body;
var words = wordsString.split(/\r?\n/);
var negativeWords = words.splice(35, words.length);
resolve(negativeWords);
} else {
console.log("Error occured");
}
}
);
});
}

initializeFolders() {
if (!fs.existsSync(this.dataFolder)) fs.mkdirSync(this.dataFolder);
if (!fs.existsSync(this.videoDataFolder))
Expand Down
72 changes: 68 additions & 4 deletions src/components/VideoScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@
/>
<input type="hidden" id="video-tags-copy" :value="video.tags" />

<div class="row mt-3">
<div class="col-6">
Negative words in the title: {{ negativeWordsTitle }}
</div>
<div class="col-6">
Negative words in the description:
{{ negativeWordsDescription }}
</div>
</div>

<div class="row justify-content-center mt-3">
<button @click="checkForBadWords" class="btn btn-dark col-4">
Check for negative words
</button>
</div>

<div class="row mt-3">
<div class="text-left col-6">
<p v-if="timeConverter">
Expand Down Expand Up @@ -147,7 +163,11 @@
<font-awesome-icon icon="save" />
Save
</button>
<button v-if="video.filePath" class="btn btn-danger col-4 offset-1" v-on:click="uploadVideo">
<button
v-if="video.filePath"
class="btn btn-danger col-4 offset-1"
v-on:click="uploadVideo"
>
<font-awesome-icon icon="cloud-upload-alt" />
Upload Video
</button>
Expand All @@ -164,15 +184,16 @@ export default {
return {
video: "",
filePath: "",
uploadStatus: ""
uploadStatus: "",
negativeWords: null,
negativeWordsTitle: 0,
negativeWordsDescription: 0
};
},
beforeCreate() {
EventBus.$on("loadVideoScreen", (videoID) => {
this.loadData(videoID);
});
// console.log("VideoScreen initialized");
},
created() {
this.clearVideoScreen();
Expand All @@ -190,6 +211,10 @@ export default {
ipcRenderer.on("videoUploadError", () => {
this.toast("Video upload error", 5, "error");
});
DB.getNegativeWordsList().then((data) => {
this.negativeWords = data;
});
},
methods: {
clearVideoScreen() {
Expand Down Expand Up @@ -273,6 +298,45 @@ export default {
/* unselect the range */
testingCodeToCopy.setAttribute("type", "hidden");
window.getSelection().removeAllRanges();
},
checkForBadWords() {
// console.log(this.negativeWords);
if (this.negativeWords === null) {
console.log("Error. Word list empty");
} else {
var title = this.video.title
.toLowerCase()
.replace(/\n/g, " ")
.split(" ");
var description = this.video.description
.toLowerCase()
.replace(/\n/g, " ")
.split(" ");
console.log(
`Title: ${title.length}, Desc: ${description.length}`
);
this.negativeWordsTitle = 0;
this.negativeWordsDescription = 0;
if (this.video.title.length > 0) {
title.forEach((element) => {
if (this.negativeWords.includes(element)) {
this.negativeWordsTitle++;
}
});
}
if (this.video.description.length > 0) {
description.forEach((element) => {
if (this.negativeWords.includes(element)) {
this.negativeWordsDescription++;
}
});
}
}
}
}
};
Expand Down

0 comments on commit db77ae6

Please sign in to comment.