Skip to content

Commit 902e3fb

Browse files
committed
update back of card layout in audio quiz
1 parent 036a33b commit 902e3fb

1 file changed

Lines changed: 29 additions & 23 deletions

File tree

script.user.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name JPDB Userscript (6a67)
33
// @namespace http://tampermonkey.net/
4-
// @version 0.1.201
4+
// @version 0.1.202
55
// @description Script for JPDB that adds some styling and functionality
66
// @match *://jpdb.io/*
77
// @grant GM_addStyle
@@ -5341,21 +5341,21 @@
53415341
}
53425342

53435343
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}`;
53455346
const response = await httpRequest(url, 30 * 24 * 60 * 60, true, false, true, true);
53465347

5347-
// get class="icon-link vocabulary-audio"
53485348
const text = response.responseText;
53495349
const parser = new DOMParser();
53505350
const doc = parser.parseFromString(text, 'text/html');
53515351
const audioElement = doc.querySelector('.icon-link.vocabulary-audio');
53525352

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+
}
53565357

5357-
// get class="spelling"
5358-
const spellingElement = doc.querySelector('.spelling');
5358+
let spellingElement = doc.querySelector('.spelling');
53595359
spellingElement.classList.remove('spelling');
53605360
spellingElement.classList.add('jp');
53615361

@@ -5364,8 +5364,16 @@
53645364
el.classList.remove('v');
53655365
});
53665366

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');
53675373
spellingElement.style.fontSize = '225%';
5368-
spellingElement.style.textAlign = 'center';
5374+
spellingElement.style.display = 'flex';
5375+
spellingElement.style.justifyContent = 'center';
5376+
spellingElement.appendChild(spellingLink);
53695377

53705378
return {
53715379
audioElement,
@@ -5530,7 +5538,7 @@
55305538
const normalizedUserAnswer = normalizeUserKanaInput(userAnswer);
55315539

55325540
// Show the vocabulary information
5533-
document.querySelector('#spelling').style.display = '';
5541+
document.querySelector('#spelling').style.display = 'flex';
55345542
document.querySelector('#meanings').style.display = '';
55355543

55365544
// Check if the answer is correct
@@ -5586,19 +5594,17 @@
55865594
vocabData.meaningsElement.style.display = 'none';
55875595

55885596
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 || ''}
56025608
`;
56035609

56045610
addReloadButton();

0 commit comments

Comments
 (0)