Skip to content

Commit

Permalink
add setting to show hidden vocabulary on card back
Browse files Browse the repository at this point in the history
  • Loading branch information
6a67 committed Feb 9, 2025
1 parent b675f83 commit ccb10b6
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion script.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name JPDB Userscript (6a67)
// @namespace http://tampermonkey.net/
// @version 0.1.192
// @version 0.1.193
// @description Script for JPDB that adds some styling and functionality
// @match *://jpdb.io/*
// @grant GM_addStyle
Expand Down Expand Up @@ -266,6 +266,15 @@
settings.searchBarOverlayTransition = new UserSetting('searchBarOverlayTransition', false, 'Search overlay animation');
settings.alwaysShowKanjiGrid = new UserSetting('alwaysShowKanjiGrid', true, 'Always show kanji grid');
settings.autoExpandNavMenu = new UserSetting('autoExpandNavMenu', false, 'Auto-expand the navigation menu on review page');
settings.showHiddenVocabularyOnBack = new UserSetting(
'showHiddenVocabularyOnBack',
false,
'Show hidden vocabulary on the back of the card',
{
longDescription:
'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.'
}
);
settings.enableMonolingualMachineTranslation = new UserSetting(
'enableMonolingualMachineTranslation',
true,
Expand Down Expand Up @@ -4371,6 +4380,47 @@
});
}

// TODO: make sure this works for new cards
function initShowHiddenVocabularyOnBack() {
let observer = null;

function checkReviewReveal() {
const reviewReveal = document.querySelector('.review-reveal');
if (reviewReveal) {
const plain = reviewReveal.querySelector('.answer-box > .plain');
if (plain) {
if (plain.style.display === 'none' || getComputedStyle(plain).display === 'none') {
const currentStyle = plain.getAttribute('style') || '';
const newStyle = currentStyle
.split(';')
.map((rule) => rule.trim())
.filter((rule) => {
if (rule.startsWith('display:')) {
return rule.split(':')[1].trim() !== 'none';
}
return rule.length > 0;
})
.join('; ');
plain.setAttribute('style', newStyle);
if (observer) {
observer.disconnect();
observer = null;
}
}
}
}
}

checkReviewReveal();

if (!document.querySelector('.review-reveal')) {
observer = new MutationObserver(() => {
checkReviewReveal();
});
observer.observe(document.body, { childList: true, subtree: true });
}
}

function init() {
applyStyles();
injectFont();
Expand Down Expand Up @@ -4414,6 +4464,10 @@
autoExpandMenuOnReviewPage();
}

if (USER_SETTINGS.showHiddenVocabularyOnBack() && window.location.href.startsWith(CONFIG.reviewPageUrlPrefix)) {
initShowHiddenVocabularyOnBack();
}

initKanjiCopyButton();
initCtrlEnter();
initShowSearchBar();
Expand Down

0 comments on commit ccb10b6

Please sign in to comment.