|
1 | 1 | // ==UserScript== |
2 | 2 | // @name JPDB Userscript (6a67) |
3 | 3 | // @namespace http://tampermonkey.net/ |
4 | | -// @version 0.1.192 |
| 4 | +// @version 0.1.193 |
5 | 5 | // @description Script for JPDB that adds some styling and functionality |
6 | 6 | // @match *://jpdb.io/* |
7 | 7 | // @grant GM_addStyle |
|
266 | 266 | settings.searchBarOverlayTransition = new UserSetting('searchBarOverlayTransition', false, 'Search overlay animation'); |
267 | 267 | settings.alwaysShowKanjiGrid = new UserSetting('alwaysShowKanjiGrid', true, 'Always show kanji grid'); |
268 | 268 | 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 | + ); |
269 | 278 | settings.enableMonolingualMachineTranslation = new UserSetting( |
270 | 279 | 'enableMonolingualMachineTranslation', |
271 | 280 | true, |
|
4371 | 4380 | }); |
4372 | 4381 | } |
4373 | 4382 |
|
| 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 | + |
4374 | 4424 | function init() { |
4375 | 4425 | applyStyles(); |
4376 | 4426 | injectFont(); |
|
4414 | 4464 | autoExpandMenuOnReviewPage(); |
4415 | 4465 | } |
4416 | 4466 |
|
| 4467 | + if (USER_SETTINGS.showHiddenVocabularyOnBack() && window.location.href.startsWith(CONFIG.reviewPageUrlPrefix)) { |
| 4468 | + initShowHiddenVocabularyOnBack(); |
| 4469 | + } |
| 4470 | + |
4417 | 4471 | initKanjiCopyButton(); |
4418 | 4472 | initCtrlEnter(); |
4419 | 4473 | initShowSearchBar(); |
|
0 commit comments