|
1 | 1 | // ==UserScript== |
2 | 2 | // @name JPDB Userscript (6a67) |
3 | 3 | // @namespace http://tampermonkey.net/ |
4 | | -// @version 0.1.201 |
| 4 | +// @version 0.1.202 |
5 | 5 | // @description Script for JPDB that adds some styling and functionality |
6 | 6 | // @match *://jpdb.io/* |
7 | 7 | // @grant GM_addStyle |
|
5341 | 5341 | } |
5342 | 5342 |
|
5343 | 5343 | async getVocabData(vid, spelling, reading) { |
5344 | | - const url = `https://jpdb.io/vocabulary/${vid}/${spelling}/${reading}`; |
| 5344 | + const vocabRef = `/vocabulary/${vid}/${spelling}/${reading}`; |
| 5345 | + const url = `https://jpdb.io${vocabRef}`; |
5345 | 5346 | const response = await httpRequest(url, 30 * 24 * 60 * 60, true, false, true, true); |
5346 | 5347 |
|
5347 | | - // get class="icon-link vocabulary-audio" |
5348 | 5348 | const text = response.responseText; |
5349 | 5349 | const parser = new DOMParser(); |
5350 | 5350 | const doc = parser.parseFromString(text, 'text/html'); |
5351 | 5351 | const audioElement = doc.querySelector('.icon-link.vocabulary-audio'); |
5352 | 5352 |
|
5353 | | - // get class="subsection-meanings" |
5354 | | - const meaningsElement = doc.querySelector('.subsection-meanings'); |
5355 | | - meaningsElement.style.textAlign = 'justify'; |
| 5353 | + const meaningsElement = doc.querySelector('.subsection-meanings')?.parentElement; |
| 5354 | + if (meaningsElement) { |
| 5355 | + meaningsElement.style.textAlign = 'justify'; |
| 5356 | + } |
5356 | 5357 |
|
5357 | | - // get class="spelling" |
5358 | | - const spellingElement = doc.querySelector('.spelling'); |
| 5358 | + let spellingElement = doc.querySelector('.spelling'); |
5359 | 5359 | spellingElement.classList.remove('spelling'); |
5360 | 5360 | spellingElement.classList.add('jp'); |
5361 | 5361 |
|
|
5364 | 5364 | el.classList.remove('v'); |
5365 | 5365 | }); |
5366 | 5366 |
|
| 5367 | + const spellingLink = document.createElement('a'); |
| 5368 | + spellingLink.href = `${vocabRef}`; |
| 5369 | + spellingLink.innerHTML = spellingElement.firstChild.innerHTML; |
| 5370 | + spellingLink.classList.add('plain'); |
| 5371 | + |
| 5372 | + spellingElement = document.createElement('div'); |
5367 | 5373 | spellingElement.style.fontSize = '225%'; |
5368 | | - spellingElement.style.textAlign = 'center'; |
| 5374 | + spellingElement.style.display = 'flex'; |
| 5375 | + spellingElement.style.justifyContent = 'center'; |
| 5376 | + spellingElement.appendChild(spellingLink); |
5369 | 5377 |
|
5370 | 5378 | return { |
5371 | 5379 | audioElement, |
|
5530 | 5538 | const normalizedUserAnswer = normalizeUserKanaInput(userAnswer); |
5531 | 5539 |
|
5532 | 5540 | // Show the vocabulary information |
5533 | | - document.querySelector('#spelling').style.display = ''; |
| 5541 | + document.querySelector('#spelling').style.display = 'flex'; |
5534 | 5542 | document.querySelector('#meanings').style.display = ''; |
5535 | 5543 |
|
5536 | 5544 | // Check if the answer is correct |
|
5586 | 5594 | vocabData.meaningsElement.style.display = 'none'; |
5587 | 5595 |
|
5588 | 5596 | container.innerHTML = ` |
5589 | | - <div class="container bugfix"> |
5590 | | - <div style="text-align: center; margin-top: 1rem; margin-bottom: 2rem" id="vocab-audio"> |
5591 | | - ${vocabData.audioElement?.outerHTML || ''} |
5592 | | - </div> |
5593 | | - ${vocabData.spellingElement?.outerHTML || ''} |
5594 | | - ${vocabData.meaningsElement?.outerHTML || ''} |
5595 | | - <form id="quiz-form" style="display: inline;"> |
5596 | | - <input name="answer" type="text" value="" placeholder="Type in the answer..." autocomplete="off" autofocus="" /> |
5597 | | - <div style="display: flex; justify-content: flex-end"> |
5598 | | - <input type="submit" value="Submit" class="outline" style="display: block" /> |
5599 | | - </div> |
5600 | | - </form> |
5601 | | - </div> |
| 5597 | + <div style="text-align: center; margin-top: 1rem; margin-bottom: 2rem" id="vocab-audio"> |
| 5598 | + ${vocabData.audioElement?.outerHTML || ''} |
| 5599 | + </div> |
| 5600 | + ${vocabData.spellingElement?.outerHTML || ''} |
| 5601 | + <form id="quiz-form" style="display: inline;"> |
| 5602 | + <input name="answer" type="text" value="" placeholder="Type in the answer..." autocomplete="off" autofocus="" /> |
| 5603 | + <div style="display: flex; justify-content: flex-end"> |
| 5604 | + <input type="submit" value="Submit" class="outline" style="display: block" /> |
| 5605 | + </div> |
| 5606 | + </form> |
| 5607 | + ${vocabData.meaningsElement?.outerHTML || ''} |
5602 | 5608 | `; |
5603 | 5609 |
|
5604 | 5610 | addReloadButton(); |
|
0 commit comments