Added a delimiter switch (#1754) by pran01

* Added a delimiter switch

* Added delimiter to wordfilter

* Delimiter Switch to Delimiter Checkbox

* fixed random input fields styling

* regenerated lockfile to version 2

* brought back example.evn

* removed console logs

Co-authored-by: Jack <bartnikjack@gmail.com>
This commit is contained in:
Pranav Sinha 2021-08-25 19:16:37 +05:30 committed by GitHub
parent 69e7bc641c
commit 3df0230c70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 121 additions and 36 deletions

View file

@ -10,7 +10,6 @@ If your change is visual (mainly themes) it would be extra awesome if you could
<!-- Please describe the change(s) made in your PR -->
Closes #
<!-- the issue(s) your PR resolves if any (delete if that is not the case) -->

View file

@ -1,2 +1,2 @@
DB_URI=mongodb://localhost:27017
DB_NAME=monkeytype
DB_NAME=monkeytype

3
package-lock.json generated
View file

@ -10314,9 +10314,6 @@
},
"bin": {
"nopt": "bin/nopt.js"
},
"engines": {
"node": "*"
}
},
"node_modules/normalize-package-data": {

View file

@ -21,7 +21,7 @@ export function show() {
.css("opacity", 0)
.removeClass("hidden")
.animate({ opacity: 1 }, 100, () => {
let newtext = CustomText.text.join(" ");
let newtext = CustomText.text.join(CustomText.delimiter);
newtext = newtext.replace(/\n /g, "\n");
$(`${popup} textarea`).val(newtext);
$(`${popup} .wordcount input`).val(CustomText.word);
@ -34,6 +34,49 @@ export function show() {
}, 150);
}
$(`${popup} .delimiter.switch .buttons .delimiter.button`).click((e) => {
$(`${popup} .delimiter.switch .buttons .delimiter.button.active`).removeClass(
"active"
);
let target = $(e.currentTarget);
let delimiter = target.attr("delimiter");
target.addClass("active");
CustomText.setDelimiter(delimiter);
$(wrapper).animate({ opacity: 1 }, 100, () => {
let newtext = CustomText.text.join(CustomText.delimiter);
newtext = newtext.replace(/\n /g, "\n");
$(`${popup} textarea`).val(newtext);
});
});
$(`${popup} .delimiterCheck input`).change(() => {
let delimiter;
if ($(`${popup} .delimiterCheck input`).prop("checked")) {
delimiter = "|";
} else {
delimiter = " ";
}
if (
$(`${popup} textarea`).val() != CustomText.text.join(CustomText.delimiter)
) {
let currentText = $(`${popup} textarea`).val();
let currentTextSplit = currentText.split(CustomText.delimiter);
let newtext = currentTextSplit.join(delimiter);
newtext = newtext.replace(/\n /g, "\n");
$(`${popup} textarea`).val(newtext);
} else {
let newtext = CustomText.text.join(delimiter);
newtext = newtext.replace(/\n /g, "\n");
$(`${popup} textarea`).val(newtext);
}
CustomText.setDelimiter(delimiter);
// $(wrapper).animate({ opacity: 1 }, 100, () => {
// let newtext = CustomText.text.join(CustomText.delimiter);
// newtext = newtext.replace(/\n /g, "\n");
// $(`${popup} textarea`).val(newtext);
// });
});
export function hide() {
if (!$(wrapper).hasClass("hidden")) {
$(wrapper)
@ -101,7 +144,7 @@ $("#customTextPopup .apply").click(() => {
}
// text = Misc.remove_non_ascii(text);
text = text.replace(/[\u2060]/g, "");
text = text.split(" ");
text = text.split(CustomText.delimiter);
CustomText.setText(text);
CustomText.setWord(parseInt($("#customTextPopup .wordcount input").val()));
CustomText.setTime(parseInt($("#customTextPopup .time input").val()));

View file

@ -1,4 +1,5 @@
import * as Misc from "./misc";
import * as CustomText from "./custom-text";
let initialised = false;
@ -68,7 +69,7 @@ async function filter(language) {
async function apply(set) {
let language = $("#wordFilterPopup .languageInput").val();
let filteredWords = await filter(language);
let customText = filteredWords.join(" ");
let customText = filteredWords.join(CustomText.delimiter);
$("#customTextPopup textarea").val(
(index, val) => (set ? "" : val + " ") + customText

View file

@ -3,6 +3,7 @@ export let isWordRandom = false;
export let isTimeRandom = false;
export let word = "";
export let time = "";
export let delimiter = " ";
export function setText(txt) {
text = txt;
@ -23,3 +24,7 @@ export function setTime(val) {
export function setWord(val) {
word = val;
}
export function setDelimiter(val) {
delimiter = val;
}

View file

@ -89,6 +89,18 @@ class Words {
increaseCurrentIndex() {
this.currentIndex++;
}
clean() {
for (let s of this.list) {
if (/ +/.test(s)) {
let id = this.list.indexOf(s);
let tempList = s.split(" ");
this.list.splice(id, 1);
for (let i = 0; i < tempList.length; i++) {
this.list.splice(id + i, 0, tempList[i]);
}
}
}
}
}
class Input {
@ -546,8 +558,7 @@ export async function init() {
regenarationCount < 100 &&
(randomWord == previousWord ||
randomWord == previousWord2 ||
(!Config.punctuation && randomWord == "I") ||
randomWord.indexOf(" ") > -1)
(!Config.punctuation && randomWord == "I"))
) {
regenarationCount++;
randomWord = wordset.randomWord();
@ -605,8 +616,29 @@ export async function init() {
if (/\t/g.test(randomWord)) {
setHasTab(true);
}
randomWord = randomWord.trim();
randomWord = randomWord.replace(/\\\\t/g, "\t");
randomWord = randomWord.replace(/\\\\n/g, "\n");
randomWord = randomWord.replace(/\\t/g, "\t");
randomWord = randomWord.replace(/\\n/g, "\n");
randomWord = randomWord.replace(/ +/g, " ");
randomWord = randomWord.replace(/( *(\r\n|\r|\n) *)/g, "\n ");
randomWord = randomWord.replace(/[\u2060]/g, " ");
console.log(`randomwordLast=${randomWord}`);
if (/ +/.test(randomWord)) {
let randomList = randomWord.split(" ");
let id = 0;
while (id < randomList.length) {
words.push(randomList[id]);
id++;
words.push(randomWord);
if (words.length == wordsBound) break;
}
i = words.length - 1;
} else {
words.push(randomWord);
}
console.log(`words=${words.list} i=${i}`);
}
}
} else if (Config.mode == "quote") {

View file

@ -580,7 +580,6 @@ a:hover {
display: grid;
gap: 1rem;
width: 60vw;
.wordfilter {
width: 33%;
justify-self: right;
@ -613,9 +612,11 @@ a:hover {
.randomInputFields {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-columns: 1fr auto 1fr;
text-align: center;
align-items: center;
width: 100%;
gap: 1rem;
}
}
}

View file

@ -90,6 +90,7 @@
></script>
</head>
<div class="customBackground"></div>
<body>
<div id="ad_rich_media" class="hidden"></div>
<div id="backgroundLoader" style="display: none"></div>
@ -150,10 +151,19 @@
</div>
<div id="customTextPopupWrapper" class="hidden">
<div id="customTextPopup" action="">
<!-- <div class="container"> -->
<!-- <div class="delimiter switch">
<div class="text">Delimiter</div>
<div class="buttons">
<div class="delimiter button active" delimiter=" ">Space</div>
<div class="delimiter button" delimiter="|">Pipe(|)</div>
</div>
</div> -->
<div class="wordfilter button">
<i class="fas fa-filter"></i>
Words filter
</div>
<!-- </div> -->
<textarea class="textarea" placeholder="Custom text"></textarea>
<div class="inputs">
<label class="checkbox">
@ -184,6 +194,15 @@
Standardises typography symbols (for example “ and ” become ")
</span>
</label>
<label class="checkbox delimiterCheck">
<input type="checkbox" />
<div class="customTextCheckbox customTextDelimiterCheckbox"></div>
Pipe Delimiter
<span>
Change how words are separated. Using the pipe delimiter allows
you to randomize groups of words.
</span>
</label>
</div>
<div class="button apply">ok</div>
</div>

View file

@ -85,7 +85,7 @@
"name": "thai",
"languages": ["thai"]
},
{
{
"name": "tamil",
"languages": ["tamil"]
},

View file

@ -1,22 +1,10 @@
{
"language": "arabic",
"groups": [
[
0,
100
],
[
101,
300
],
[
301,
600
],
[
601,
9999
]
[0, 100],
[101, 300],
[301, 600],
[601, 9999]
],
"quotes": [
{
@ -109,7 +97,7 @@
"length": 232,
"id": 15
},
{
{
"text": "مشكلة هذه الحياة أنك لا تستطيع أن تجد فيها شيئا ينفع من غير ضرر أو يضر من غير نفع في كل حين !",
"source": "علي الوردي",
"length": 93,
@ -214,7 +202,7 @@
{
"text": "احتقرت نفسي سبع مرات: الأولى، عندما رأيتها تتظاهر الوضاعة وهي تنشد الرفعة. والثانية عندما رأيتها تترنح متجاوزة العرجى. والثالثة عندما خيرت بين السهل والشاق ففضلت السهل. والرابعة عندما اقترفت ذنبا وراحت تبرره باقتراف الآخرين ذنوبا مماثلة. والخامسة عندما عجزت عن فعل شيء لضعفها وعزت صبرها إلى القوة. والسادسة عندما احتقرت بشاعة وجه تبين أنه أحد براقعها. والسابعة عندما غنت مديحا واعتبرت غناءها فضيلة.",
"source": "جبران خليل جبران",
"length":398 ,
"length": 398,
"id": 33
},
{
@ -226,7 +214,7 @@
{
"text": "كل لغة وكل ثقافة هي عالم بحد ذاته. عندما يتكلم الإنسان لغات مختلفة ويعيش في ثقافات مختلفة فهو ثراء.",
"source": "عابد عازية",
"length":99 ,
"length": 99,
"id": 35
},
{

View file

@ -33706,12 +33706,12 @@
"source": "Brian David Gilbert, I'm not superstitious but I'm afraid to prune my money tree",
"length": 518,
"id": 5686
},
},
{
"text": "I got a letter from somebody here a while back, and they said, 'Bob, everything in your world seems to be happy.' That's for sure. That's why I paint. It's because I can create the kind of world that I want, and I can make this world as happy as I want it. Shoot, if you want bad stuff, watch the news.",
"source": "Bob Ross",
"length": 302,
"id": 5687
"id": 5687
},
{
"text": "We don't make mistakes, just happy little accidents.",
@ -33720,7 +33720,7 @@
"id": 5688
},
{
"text": "Talent is a pursued interest. Anything that you're willing to practice, you can do.",
"text": "Talent is a pursued interest. Anything that you're willing to practice, you can do.",
"source": "Bob Ross",
"length": 82,
"id": 5689