Skip to content

Commit ccb10b6

Browse files
committed
add setting to show hidden vocabulary on card back
1 parent b675f83 commit ccb10b6

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

script.user.js

Lines changed: 55 additions & 1 deletion
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.192
4+
// @version 0.1.193
55
// @description Script for JPDB that adds some styling and functionality
66
// @match *://jpdb.io/*
77
// @grant GM_addStyle
@@ -266,6 +266,15 @@
266266
settings.searchBarOverlayTransition = new UserSetting('searchBarOverlayTransition', false, 'Search overlay animation');
267267
settings.alwaysShowKanjiGrid = new UserSetting('alwaysShowKanjiGrid', true, 'Always show kanji grid');
268268
settings.autoExpandNavMenu = new UserSetting('autoExpandNavMenu', false, 'Auto-expand the navigation menu on review page');
269+
settings.showHiddenVocabularyOnBack = new UserSetting(
270+
'showHiddenVocabularyOnBack',
271+
false,
272+
'Show hidden vocabulary on the back of the card',
273+
{
274+
longDescription:
275+
'If "Enlarge the example sentence and do not show the reviewed word by itself on a separate line (when possible)" is enabled, this setting will show the hidden vocabulary on the back of the card.'
276+
}
277+
);
269278
settings.enableMonolingualMachineTranslation = new UserSetting(
270279
'enableMonolingualMachineTranslation',
271280
true,
@@ -4371,6 +4380,47 @@
43714380
});
43724381
}
43734382

4383+
// TODO: make sure this works for new cards
4384+
function initShowHiddenVocabularyOnBack() {
4385+
let observer = null;
4386+
4387+
function checkReviewReveal() {
4388+
const reviewReveal = document.querySelector('.review-reveal');
4389+
if (reviewReveal) {
4390+
const plain = reviewReveal.querySelector('.answer-box > .plain');
4391+
if (plain) {
4392+
if (plain.style.display === 'none' || getComputedStyle(plain).display === 'none') {
4393+
const currentStyle = plain.getAttribute('style') || '';
4394+
const newStyle = currentStyle
4395+
.split(';')
4396+
.map((rule) => rule.trim())
4397+
.filter((rule) => {
4398+
if (rule.startsWith('display:')) {
4399+
return rule.split(':')[1].trim() !== 'none';
4400+
}
4401+
return rule.length > 0;
4402+
})
4403+
.join('; ');
4404+
plain.setAttribute('style', newStyle);
4405+
if (observer) {
4406+
observer.disconnect();
4407+
observer = null;
4408+
}
4409+
}
4410+
}
4411+
}
4412+
}
4413+
4414+
checkReviewReveal();
4415+
4416+
if (!document.querySelector('.review-reveal')) {
4417+
observer = new MutationObserver(() => {
4418+
checkReviewReveal();
4419+
});
4420+
observer.observe(document.body, { childList: true, subtree: true });
4421+
}
4422+
}
4423+
43744424
function init() {
43754425
applyStyles();
43764426
injectFont();
@@ -4414,6 +4464,10 @@
44144464
autoExpandMenuOnReviewPage();
44154465
}
44164466

4467+
if (USER_SETTINGS.showHiddenVocabularyOnBack() && window.location.href.startsWith(CONFIG.reviewPageUrlPrefix)) {
4468+
initShowHiddenVocabularyOnBack();
4469+
}
4470+
44174471
initKanjiCopyButton();
44184472
initCtrlEnter();
44194473
initShowSearchBar();

0 commit comments

Comments
 (0)