diff --git a/gulpfile.js b/gulpfile.js index fe048a49d..77431062b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -104,6 +104,7 @@ const refactoredSrc = [ "./src/js/chart-controller.js", "./src/js/theme-controller.js", "./src/js/test/caret.js", + "./src/js/word-filter.js", "./src/js/custom-text-popup.js", "./src/js/manual-restart-tracker.js", "./src/js/config.js", diff --git a/src/js/custom-text-popup.js b/src/js/custom-text-popup.js index 02a89098f..0b4ea962c 100644 --- a/src/js/custom-text-popup.js +++ b/src/js/custom-text-popup.js @@ -2,6 +2,7 @@ import * as CustomText from "./custom-text"; import * as ManualRestart from "./manual-restart-tracker"; import * as Misc from "./misc"; import * as Notifications from "./notification-center"; +import * as WordFilter from "./word-filter"; import * as TestLogic from "./test-logic"; let wrapper = "#customTextPopupWrapper"; @@ -81,7 +82,7 @@ $(`${popup} .randomInputFields .time input`).keypress((e) => { $(`${popup} .randomInputFields .wordcount input`).val(""); }); -$("#customTextPopup .button").click(() => { +$("#customTextPopup .apply").click(() => { let text = $("#customTextPopup textarea").val(); text = text.trim(); // text = text.replace(/[\r]/gm, " "); @@ -154,3 +155,7 @@ $("#customTextPopup .button").click(() => { TestLogic.restart(); hide(); }); + +$("#customTextPopup .wordfilter").click(() => { + WordFilter.showWordFilterPopup(); +}) \ No newline at end of file diff --git a/src/js/exports.js b/src/js/exports.js index c3dc504c0..22286defe 100644 --- a/src/js/exports.js +++ b/src/js/exports.js @@ -10,3 +10,5 @@ global.snapshot = DB.getSnapshot; global.config = Config; // global.addnotif = Notifications.add; global.link = linkWithGoogle; + +global.wordFilter = WordFilter; \ No newline at end of file diff --git a/src/js/global-dependencies.js b/src/js/global-dependencies.js index f0074f490..8a15db298 100644 --- a/src/js/global-dependencies.js +++ b/src/js/global-dependencies.js @@ -30,6 +30,7 @@ import * as OutOfFocus from "./out-of-focus"; import * as ChartController from "./chart-controller"; import * as ThemeController from "./theme-controller"; import * as Caret from "./caret"; +import * as WordFilter from "./word-filter"; import * as CustomTextPopup from "./custom-text-popup"; import * as ManualRestart from "./manual-restart-tracker"; import Config, * as UpdateConfig from "./config"; diff --git a/src/js/script.js b/src/js/script.js index cae5fa375..71761dce8 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -813,7 +813,8 @@ $(document).keydown(function (event) { let modePopupVisible = !$("#customTextPopupWrapper").hasClass("hidden") || !$("#customMode2PopupWrapper").hasClass("hidden") || - !$("#quoteSearchPopupWrapper").hasClass("hidden"); + !$("#quoteSearchPopupWrapper").hasClass("hidden") || + !$("#wordFilterPopupWrapper").hasClass("hidden"); if ( pageTestActive && !commandLineVisible && diff --git a/src/js/word-filter.js b/src/js/word-filter.js new file mode 100644 index 000000000..ced7eac18 --- /dev/null +++ b/src/js/word-filter.js @@ -0,0 +1,81 @@ +import { setCustomThemeColors } from "./config"; +import * as Misc from "./misc"; +import * as ThemeColors from "./theme-colors"; +//import * as config from "./userconfig"; + +export async function showWordFilterPopup(){ + + $("#wordFilterPopupWrapper").removeClass("hidden"); + $("#customTextPopupWrapper").addClass("hidden"); + let LanguageList = await Misc.getLanguageList(); + LanguageList.forEach(language => { + let prettyLang = language; + prettyLang = prettyLang.replace("_", " "); + $("#languageList").append(` + + `) + }) + $("#languageList").select2({ + minimumResultsForSearch: -1, + }); +} + +function hideWordFilterPopup(){ + $("#wordFilterPopupWrapper").addClass("hidden"); + $("#customTextPopupWrapper").removeClass("hidden"); +} + +async function applyWordFilterPopup(){ + let language = $("#languageList").val(); + let filteredWords = await filter(language); + let customText = ""; + filteredWords.forEach( word => { + customText += (word + " "); + }) + hideWordFilterPopup(); + $("#customTextPopup textarea").val(customText); +} + +$("#wordFilterPopupWrapper").mousedown((e) => { + if ($(e.target).attr("id") === "wordFilterPopupWrapper") { + hideWordFilterPopup(); + } +}); + +$("#wordFilterPopupWrapper .button").mousedown((e) => { + $("#wordFilterPopupWrapper .wfload").removeClass("hidden"); + $("#wordFilterPopupWrapper .button").addClass("hidden"); + setTimeout(() => { + applyWordFilterPopup(); + $("#wordFilterPopupWrapper .wfload").addClass("hidden"); + $("#wordFilterPopupWrapper .button").removeClass("hidden"); + }, 1) +}); + +async function filter(language){ + let filterin = $("#wordFilter").val(); + filterin = filterin.replace(/ /gi, "|"); + let regincl = new RegExp(filterin, "i"); + let filterout = $("#wordExclude").val(); + filterout = filterout.replace(/ /gi, "|"); + let regexcl = new RegExp(filterout, "i"); + let filteredWords = []; + let languageWordList = await Misc.getLanguage(language); + let maxLength = $("#wordMax").val(); + let minLength = $("#wordMin").val(); + if(maxLength == ""){ + maxLength = 999; + } + if(minLength == ""){ + minLength = 1; + } + for( let i = 0; i < languageWordList.words.length; i++){ + let word = languageWordList.words[i]; + let test1 = regincl.test(word); + let test2 = regexcl.test(word); + if((test1 && !test2 || test1 && filterout == "") && word.length <= maxLength && word.length >= minLength){ + filteredWords.push(word); + } + } + return filteredWords; +} \ No newline at end of file diff --git a/src/sass/style.scss b/src/sass/style.scss index 088e1958e..1109b2499 100644 --- a/src/sass/style.scss +++ b/src/sass/style.scss @@ -414,6 +414,11 @@ a:hover { gap: 1rem; width: 60vw; + .wordfilter{ + width: 33%; + justify-self:right; + } + textarea { background: var(--bg-color); padding: 1rem; @@ -427,6 +432,8 @@ a:hover { resize: vertical; height: 200px; color: var(--text-color); + overflow-x: hidden; + overflow-y: scroll; } .inputs { @@ -512,6 +519,81 @@ a:hover { } } +#wordFilterPopupWrapper{ + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.75); + position: fixed; + left: 0; + top: 0; + z-index: 1000; + display: grid; + justify-content: center; + align-items: center; + padding: 5rem 0; + + #wordFilterPopup{ + background: var(--bg-color); + border-radius: var(--roundness); + padding: 2rem; + display: grid; + gap: 1rem; + width: 400px; + + .lengthgrid{ + display:grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: 1fr 1fr; + gap: 0.2rem; + } + + .wordLength{ + width: 10rem; + } + + #languageList{ + background: rgba(0, 0, 0, 0.1); + height: fit-content; + padding: 5px; + border-radius: 5px; + color: var(--text-color); + font: var(--font); + border: none; + + + option{ + background: var(--bg-color); + } + } + #languageList:focus{ + height: fit-content; + padding: 5px; + border-radius: 5px; + color: var(--text-color); + font: var(--font); + border: none; + outline: none; + } + #languageList:active{ + height: fit-content; + padding: 5px; + border-radius: 5px; + color: var(--text-color); + font: var(--font); + border: none; + outline: none; + } + .wftip{ + color: var(--sub-color); + font-size: 0.8rem; + } + + .wfload{ + justify-self: center; + } + } +} + #simplePopupWrapper { width: 100%; height: 100%; diff --git a/static/index.html b/static/index.html index be7da9eb4..a4571c513 100644 --- a/static/index.html +++ b/static/index.html @@ -5,6 +5,7 @@ Monkeytype + @@ -102,6 +103,7 @@ + @@ -3754,5 +3777,6 @@ +