Skip to content

Commit ecaf357

Browse files
committed
simplify centered answer box logic
1 parent dccfbe9 commit ecaf357

File tree

1 file changed

+8
-69
lines changed

1 file changed

+8
-69
lines changed

script.user.js

Lines changed: 8 additions & 69 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.153
4+
// @version 0.1.154
55
// @description Script for JPDB that adds some styling and functionality
66
// @match *://jpdb.io/*
77
// @grant GM_addStyle
@@ -994,22 +994,17 @@
994994
`,
995995

996996
fixCenteredAnswerBox: `
997-
.answer-box > .plain > :empty {
998-
display: none;
999-
}
1000-
1001997
.answer-box > .plain > div[style*="padding-left"] {
1002998
padding-left: 0px !important;
999+
flex: 1;
10031000
}
10041001
1005-
.answer-box > .plain {
1006-
display: flex;
1007-
align-items: baseline;
1008-
justify-content: space-between !important;
1002+
.answer-box > .plain > div[style*="width"] {
1003+
width: 0px !important;
10091004
}
10101005
1011-
.inserted-dropdown {
1012-
margin-right: 0px !important;
1006+
.answer-box > .plain > div[style*="column"] {
1007+
flex: 0 !important;
10131008
}
10141009
`
10151010
};
@@ -3276,63 +3271,7 @@
32763271
}
32773272

32783273
function initFixCenteredAnswerBox() {
3279-
function centerElements() {
3280-
const answerBox = document.querySelector('.answer-box');
3281-
if (!answerBox) return;
3282-
if (answerBox.classList.contains('centered-fix')) return;
3283-
const plain = answerBox.querySelector('.plain');
3284-
if (!plain) return;
3285-
let plain2 = plain.querySelector('.plain');
3286-
let revealed = true;
3287-
if (!plain2) {
3288-
const divs = plain.querySelectorAll('div');
3289-
for (const div of divs) {
3290-
if (div.style.cssText === '') {
3291-
plain2 = div;
3292-
revealed = false;
3293-
break;
3294-
}
3295-
}
3296-
}
3297-
if (!plain2) return;
3298-
3299-
const div = document.createElement('div');
3300-
div.style = 'display: flex; flex: 1;';
3301-
if (revealed) {
3302-
plain.insertBefore(div, plain2);
3303-
GM_addStyle(STYLES.fixCenteredAnswerBox);
3304-
} else {
3305-
plain.insertBefore(div, plain2);
3306-
const lastDiv = plain.querySelector('div:last-child');
3307-
lastDiv.style.paddingLeft = '0';
3308-
lastDiv.style.flex = '1';
3309-
3310-
const divs = plain.querySelectorAll('div');
3311-
divs.forEach((d) => {
3312-
if (d !== div && !d.textContent.trim() && !d.children.length) {
3313-
d.remove();
3314-
}
3315-
});
3316-
}
3317-
3318-
answerBox.classList.add('centered-fix');
3319-
}
3320-
3321-
centerElements();
3322-
3323-
let lastProcessedMutation = null;
3324-
3325-
const observer = new MutationObserver((mutations) => {
3326-
for (const mutation of mutations) {
3327-
if (mutation === lastProcessedMutation) {
3328-
continue;
3329-
}
3330-
lastProcessedMutation = mutation;
3331-
centerElements();
3332-
}
3333-
});
3334-
3335-
observer.observe(document.body.querySelector('.answer-box'), { childList: true, subtree: true });
3274+
GM_addStyle(STYLES.fixCenteredAnswerBox);
33363275
}
33373276

33383277
async function initReviewProgress() {
@@ -3589,7 +3528,7 @@
35893528

35903529
if (window.location.href.startsWith(CONFIG.reviewPageUrlPrefix)) {
35913530
initDropdownOnReviewPage();
3592-
// initFixCenteredAnswerBox();
3531+
initFixCenteredAnswerBox();
35933532
}
35943533

35953534
if (window.location.href.startsWith(CONFIG.reviewPageUrlPrefix) && DEBUG.enableProgress) {

0 commit comments

Comments
 (0)