From 8753e52d866287d8fa8dd3244e914181a1991f3e Mon Sep 17 00:00:00 2001 From: GentleCold <1952173800@qq.com> Date: Sun, 8 May 2022 15:19:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90,=20?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E8=AE=BE?= =?UTF-8?q?=E5=AE=9A=EF=BC=88=E5=BE=85=E5=AE=9A=EF=BC=89,=20v-1.0.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + neutralino.config.json | 3 +- resources/css/index.css | 80 +++++++++- resources/index.html | 31 +++- resources/js/main.js | 337 ++++++++++++++++++++++++++-------------- 5 files changed, 317 insertions(+), 137 deletions(-) diff --git a/.gitignore b/.gitignore index 5473772..7a83a7d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,8 @@ fontawesome neutralino.js # Neutralinojs related files +backup +setup.iss +word .storage *.log diff --git a/neutralino.config.json b/neutralino.config.json index 5b5b97d..7e9d9c4 100644 --- a/neutralino.config.json +++ b/neutralino.config.json @@ -16,7 +16,8 @@ "window.*", "os.setTray", "app.*", - "storage.*" + "storage.*", + "filesystem.readFile" ], "modes": { "window": { diff --git a/resources/css/index.css b/resources/css/index.css index 579da57..937428e 100644 --- a/resources/css/index.css +++ b/resources/css/index.css @@ -27,7 +27,7 @@ body { #titleBar { width: 100%; height: 20px; - background-color: #C66A0D; + background-color: rgb(198, 106, 13); display: flex; align-items: center; justify-content: center; @@ -36,6 +36,7 @@ body { #more { cursor: pointer; + padding: 5px; } #close { @@ -46,6 +47,27 @@ body { padding: 5px; } +#nextBoard { + position: absolute; + right: 70px; + bottom: 80px; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + width: 20px; + height: 20px; + border-radius: 50%; + background-color: rgba(187, 54, 13, 0.8); + box-shadow: 0 0 2px 1px rgba(38, 40, 41, 0.5); + z-index: 1; +} + +#next { + font-size: 5px; + cursor: pointer; +} + #title { position: absolute; top: 25px; @@ -70,13 +92,19 @@ body { border: 2px solid #414547; } +#scroll { + overflow-y: scroll; + width: 100%; + height: 50%; +} + .block2 { display: flex; text-align: center; align-items: center; justify-content: center; - width: 100%; - height: 50%; + min-height: 100%; + max-height: 500%; background-color: #262829; border: 2px solid #414547; border-top: none; @@ -123,6 +151,12 @@ input { display: none; } +#cancel { + position: absolute; + right: 5px; + display: none; +} + #look1 { position: absolute; left: 5px; @@ -139,19 +173,49 @@ input { .text { width: 60%; cursor: zoom-in; + white-space: nowrap; word-wrap: break-word; + text-overflow: ellipsis; font-size: 14px; } +::-webkit-scrollbar { + display:none; +} + #text2 { display: none; } -#setting { +#listBoard { width: 100%; - height: 140px; + height: 0; + z-index: 2; + text-align: center; + position: absolute; + top: 20px; background-color: #262829; +} + +.list { + width: 100%; + height: 28px; + padding: 5px; border: 2px solid #414547; - z-index: 2; - display: none; -} \ No newline at end of file + border-top: none; + cursor: pointer; +} + +.list:hover { + color: #BB360D; + background-color: rgba(65, 69, 71, 0.5); +} + +/*#setting {*/ +/* width: 100%;*/ +/* height: 140px;*/ +/* background-color: #262829;*/ +/* border: 2px solid #414547;*/ +/* z-index: 1;*/ +/* display: none;*/ +/*}*/ \ No newline at end of file diff --git a/resources/index.html b/resources/index.html index 76b6000..c84e039 100644 --- a/resources/index.html +++ b/resources/index.html @@ -8,26 +8,41 @@
+ +
+
+
+
YOUR-WORD
+
CORE-700
+
CET-4
+
CET-6
+
POST-CET-6
+
+
+
-
- - - - -
- - +
+
+ + + + +
+ + +
+
diff --git a/resources/js/main.js b/resources/js/main.js index 251ff82..de240eb 100644 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -1,6 +1,8 @@ -let words = [], word = [], ifAnimate = false, wordIndex, loop = false; // word[english, chinese, time(minute), level(0-3), mark] -const duration = 60000; // minute -const level = [5, 30, 720, 1440]; +// word[english, chinese, meet, gap, mark, abandon] +let words = [], word = [], listIndex, wordIndex, id, zoomIn = false; +let ifAnimate = false, loop = false, menu = false; +const gap1 = 4, gap2 = 2; +const duration = 300000; // 5 minute const description = [ 'Word
Reminder', 'Minimize
to Tray', @@ -8,56 +10,74 @@ const description = [ 'Mark the
Word', 'See the
Translation', 'Hide the
Translation', - 'Delete the
Word', - 'Save the
Word' + 'Clear or
Delete the Word', + 'Save the
Word', + 'Cancel', + 'Menu', + 'Next Word' ]; +const wordList = [ + 'user', + 'core-700', + 'cet-4', + 'cet-6', + 'post-cet-6', +] // get dom +// draggable const titleBar = document.getElementById('titleBar'); +// text const title = document.getElementById('title'); +const text1 = document.getElementById('text1'); +const text2 = document.getElementById('text2'); +const input1 = document.getElementById('input1'); +const input2 = document.getElementById('input2'); +const lists = document.getElementsByClassName('list'); +// icon const close = document.getElementById('close'); const mark = document.getElementById('mark'); const more = document.getElementById('more'); const look1 = document.getElementById('look1'); const look2 = document.getElementById('look2'); -const text1 = document.getElementById('text1'); -const text2 = document.getElementById('text2'); const edit = document.getElementById('edit'); -const input1 = document.getElementById('input1'); -const input2 = document.getElementById('input2'); const check = document.getElementById('check'); +const cancel = document.getElementById('cancel'); const trash = document.getElementById('trash'); +const next = document.getElementById('nextBoard'); +// board +const listBoard = document.getElementById('listBoard'); const board = document.getElementById('board'); // define function function delayPrint(dom, str) { dom.innerHTML = ''; if (!str) return; - let count = 0, hide = 0; + let count = 0; (function f() { if (dom !== title) ifAnimate = true; - if (!hide) { - if (str[count] === '<') { - while(count < str.length && str[count] !== '>') count++; - count++; - if (count >= str.length) { - if (dom !== title) ifAnimate = false; - return; - } - dom.innerHTML += '
'; - } else { - dom.innerHTML += str[count]; - count++; + + // skip blank + if (str[count] === ' ') { + dom.innerHTML += ' '; + count++; + } + // skip '<...>' + if (str[count] === '<') { + while(count < str.length && str[count] !== '>') count++; + count++; + if (count >= str.length) { + if (dom !== title) ifAnimate = false; + return; } + dom.innerHTML += '
'; } else { - count = 7; + dom.innerHTML += str[count]; + count++; } + if (dom !== title) { - if (count === 7 && str.length > 7) { - dom.innerHTML += '.'; - hide++; - } - if (hide === 3) { - if (dom !== title) ifAnimate = false; + if (count >= 13 && str.length >= 13) { + ifAnimate = false; return; } } @@ -66,9 +86,9 @@ function delayPrint(dom, str) { return; } if (dom === title) { - loop = setTimeout(f, 100); + loop = setTimeout(f, 50); } else { - setTimeout(f, 100); + setTimeout(f, 50); } })(); } @@ -97,23 +117,28 @@ function setDraggable() { } } document.onmouseup = () => ifClick = false; +} +function setClick() { more.onclick = () => { + if (!menu) { + menu = true; + listBoard.style.height = '140px'; + } else { + menu = false; + listBoard.style.height = '0'; + } } -} -function setClick() { close.onclick = () => { Neutralino.window.hide().then(); - word = []; + id = setTimeout(countTime, duration); } look1.onclick = () => { - if (word.length) { + if (word.length && !ifAnimate) { look1.style.display = 'none'; look2.style.display = 'block'; text2.style.display = 'block'; - if (!ifAnimate) { - delayPrint(text2, word[1]); - } + delayPrint(text2, word[1]); } } look2.onclick = () => { @@ -123,38 +148,39 @@ function setClick() { text2.innerHTML = ''; } edit.onclick = () => { - look1.style.display = look2.style.display = text2.style.display = text1.style.display = trash.style.display = mark.style.display = 'none'; - input1.style.display = input2.style.display = check.style.display = 'block'; + next.style.display = look1.style.display = look2.style.display = text2.style.display = text1.style.display = trash.style.display = mark.style.display = 'none'; + input1.style.display = input2.style.display = check.style.display = cancel.style.display = 'block'; input1.focus(); } - trash.onclick = () => { + trash.ondblclick = () => { if (word.length) { + word = []; + text1.innerHTML = text2.innerHTML = ''; words.splice(wordIndex, 1); - if (words.length) { - let index = Math.floor(Math.random() * words.length); - word = words[index]; - wordIndex = index - words[index][2] = level[words[index][3]]; - delayPrint(text1, word[0]); + countTime().then(); + } + } + trash.onclick = () => { + if (word.length) { + words[wordIndex][5] = word[5] = !word[5]; + if (word[5]) { + text1.style.color = text2.style.color = '#A49C90'; } else { - text1.innerHTML = text2.innerHTML = ''; - word = []; + setColor(); } + word[4] = words[wordIndex][4] = false; } } check.onclick = () => { - look1.style.display = text1.style.display = trash.style.display = mark.style.display = 'block'; - input1.style.display = input2.style.display = check.style.display = 'none'; - word = [input1.value, input2.value, 5, 0, false]; + turnOrigin(); + word = [input1.value, input2.value, 0, 0, false, false]; words.push(word); wordIndex = words.length - 1; - setInterval(loopTime, 1000, wordIndex); - if (word[4]) { - text1.style.color = text2.style.color = 'rgb(187,54,13)'; - } else { - text1.style.color = text2.style.color = '#E8E6E3'; - } - delayPrint(text1, word[0]); + printWord(); + } + cancel.onclick = () => { + turnOrigin() + printWord(); } mark.onclick = () => { if (word.length) { @@ -162,7 +188,36 @@ function setClick() { if (word[4]) { text1.style.color = text2.style.color = 'rgb(187,54,13)'; } else { - text1.style.color = text2.style.color = '#E8E6E3'; + setColor(); + } + word[5] = words[wordIndex][5] = false; + } + } + next.onclick = () => { + if (!ifAnimate) countTime().then(); + } + for (let i in lists) { + lists[i].onclick = async () => { + if (i !== listIndex) { + lists[listIndex].style.backgroundColor = 'transparent'; + lists[listIndex].style.color = '#E8E6E3'; + lists[listIndex].style.pointerEvents = 'initial'; + lists[i].style.backgroundColor = 'rgba(65, 69, 71, 0.5)'; + lists[i].style.color = '#BB360D'; + lists[i].style.pointerEvents = 'none'; + + menu = false; + listBoard.style.height = '0'; + + if (zoomIn) text1.click(); + + Neutralino.storage.setData(wordList[listIndex], JSON.stringify(words)).then(); + listIndex = i; + words = await Neutralino.storage.getData(wordList[listIndex]); + words = JSON.parse(words); + word = []; + text1.innerHTML = text2.innerHTML = ''; + countTime().then(); } } } @@ -180,7 +235,7 @@ function setIcon(icon, n) { } } function setText() { - let tmp1, tmp2, zoomIn = false; + let tmp1, tmp2; text1.onclick = text2.onclick = () => { if (!ifAnimate) { if (!zoomIn) { @@ -191,9 +246,10 @@ function setText() { text2.innerHTML = word[1]; text1.style.cursor = text2.style.cursor = 'zoom-out'; text1.style.width = text2.style.width = '100%'; + text1.style.whiteSpace = text2.style.whiteSpace = 'normal'; board.style.height = '140px'; - edit.style.display = look1.style.display = look2.style.display = trash.style.display = mark.style.display = 'none'; + next.style.display = edit.style.display = look1.style.display = look2.style.display = trash.style.display = mark.style.display = 'none'; mark.style.zIndex = '0'; } else { zoomIn = false; @@ -201,9 +257,11 @@ function setText() { text2.innerHTML = tmp2; text1.style.cursor = text2.style.cursor = 'zoom-in'; text1.style.width = text2.style.width = '60%'; + text1.style.whiteSpace = text2.style.whiteSpace = 'nowrap'; board.style.height = '90px'; edit.style.display = trash.style.display = mark.style.display = 'block'; + next.style.display = 'flex'; mark.style.zIndex = '1'; if (!text2.innerHTML) look1.style.display = 'block'; else look2.style.display = 'block'; @@ -212,37 +270,16 @@ function setText() { } } async function setWord() { - words = await Neutralino.storage.getData('words'); - try { - words = JSON.parse(words); - } catch (e) { - words = []; - } + listIndex = await Neutralino.storage.getData('list'); + listIndex = JSON.parse(listIndex); - for (let i in words) { - setInterval(loopTime, duration, i); + lists[listIndex].style.pointerEvents = 'none'; + lists[listIndex].style.color = '#BB360D'; + lists[listIndex].style.backgroundColor = 'rgba(65, 69, 71, 0.5)'; - if (!word.length && words[i][2] === 0) { - word = words[i]; - wordIndex = i; - words[i][3]++; - words[i][2] = level[words[i][3]]; - } - } - if (words.length) { - if (!word.length) { - let index = Math.floor(Math.random() * words.length); - word = words[index]; - wordIndex = index; - words[index][2] = level[words[index][3]]; - } - if (word[4]) { - text1.style.color = text2.style.color = 'rgb(187,54,13)'; - } else { - text1.style.color = text2.style.color = '#E8E6E3'; - } - delayPrint(text1, word[0]); - } + words = await Neutralino.storage.getData(wordList[listIndex]); + words = JSON.parse(words); + countTime().then(); } // handle function @@ -250,47 +287,96 @@ function onTrayMenuItemClicked(event) { switch(event.detail.id) { case 'HOME': Neutralino.window.show().then(() => { - let index = Math.floor(Math.random() * words.length); - word = words[index]; - wordIndex = index; - words[index][2] = level[words[index][3]]; - - handleShow(); + clearTimeout(id); + countTime().then(); }); break; case 'QUIT': - Neutralino.storage.setData('words', JSON.stringify(words)).then(); + Neutralino.storage.setData(wordList[listIndex], JSON.stringify(words)).then(); + Neutralino.storage.setData('list', JSON.stringify(listIndex)).then(); Neutralino.app.exit().then(); break; } } -function handleShow() { - look1.style.display = 'block'; - look2.style.display = 'none'; - text2.innerHTML = ''; - if (word[4]) { - text1.style.color = text2.style.color = 'rgb(187,54,13)'; +function printWord() { + if (word.length) { + look1.style.display = 'block'; + look2.style.display = 'none'; + text2.innerHTML = ''; + text2.style.display = 'none'; + if (word[4]) { + text1.style.color = text2.style.color = 'rgb(187,54,13)'; + } else if (word[5]) { + text1.style.color = text2.style.color = '#A49C90'; + } else { + setColor(); + } + delayPrint(text1, word[0]); + } else { + text1.innerHTML = text2.innerHTML = ''; + } +} +function setColor() { + if (word[2] < 10) { + text1.style.color = text2.style.color = `#E8E6E3`; + } else if (word[2] < 20) { + text1.style.color = text2.style.color = `#78983B`; + } else if (word[2] < 30) { + text1.style.color = text2.style.color = `#0F8CC5`; } else { - text1.style.color = text2.style.color = '#E8E6E3'; + text1.style.color = text2.style.color = `#CE800D`; } - delayPrint(text1, word[0]); } -async function loopTime(i) { - let visible = await Neutralino.window.isVisible(); - if (visible) return; - if (words[i][2] === 0 && word.length === 0) { - Neutralino.window.show().then(); - Neutralino.window.focus().then(); - word = words[i]; - wordIndex = i; - words[i][3]++; - if (words[i][3] > 3) words[i][3] = 0; - words[i][2] = level[words[i][3]]; +function turnOrigin() { + look1.style.display = text1.style.display = trash.style.display = mark.style.display = 'block'; + next.style.display = 'flex'; + input1.style.display = input2.style.display = check.style.display = cancel.style.display = 'none'; +} +async function countTime() { + if (!words.length) return; - handleShow(); + let tmpWord = null, min = 1 / 0; + for (let i in words) { + if (words[i][2] < min) min = words[i][2]; + + if (!words[i][5] && ((!words[i][4] && words[i][3] && words[i][3] % gap1 === 0) || + (words[i][4] && words[i][3] && words[i][3] % gap2 === 0))) { + if (tmpWord && words[i][2] < tmpWord[0][2]) { + tmpWord = [words[i], i]; + } else if (!tmpWord) { + tmpWord = [words[i], i]; + } + } } - words[i][2]--; - if (words[i][2] < 0) words[i][2] = 0; + + if (tmpWord) { + word = tmpWord[0]; + wordIndex = tmpWord[1]; + } else { + let index; + do { + index = Math.floor(Math.random() * words.length); + } while (words[index][2] !== min); + word = words[index]; + wordIndex = index; + } + + if (!tmpWord) { + for (let i in words) { + if (words[i][2] > 0 && i !== wordIndex) { + if ((!words[i][4] && words[i][3] === gap1) || (words[i][4] && words[i][3] === gap2)) continue; + words[i][3]++; + } + } + } else { + words[wordIndex][3] = 0; + } + + words[wordIndex][2]++; + printWord(); + + Neutralino.window.show().then(); + Neutralino.window.focus().then(); } Neutralino.init(); @@ -307,6 +393,9 @@ setIcon(look1, 4); setIcon(look2, 5); setIcon(trash, 6); setIcon(check, 7); +setIcon(cancel, 8); +setIcon(more, 9); +setIcon(next, 10); setText(); setTray(); @@ -314,3 +403,11 @@ setTray(); Neutralino.events.on('trayMenuItemClicked', onTrayMenuItemClicked).then(); document.oncontextmenu = (e) => e.preventDefault(); + +// for (let i = 1; i <= 4; i++) { +// (async () => { +// let data = await Neutralino.filesystem.readFile('./resources/word/' + wordList[i] + '.txt'); +// data = JSON.parse(data); +// Neutralino.storage.setData(wordList[i], JSON.stringify(data)).then(); +// })() +// } \ No newline at end of file