|
1 | 1 | // ==UserScript== |
2 | 2 | // @name JPDB Userscript (6a67) |
3 | 3 | // @namespace http://tampermonkey.net/ |
4 | | -// @version 0.1.160 |
| 4 | +// @version 0.1.161 |
5 | 5 | // @description Script for JPDB that adds some styling and functionality |
6 | 6 | // @match *://jpdb.io/* |
7 | 7 | // @grant GM_addStyle |
|
1539 | 1539 | size: { width: 100, height: 100 }, |
1540 | 1540 | opacity: 1, |
1541 | 1541 | playBehind: false, |
1542 | | - rotation: 0 |
| 1542 | + rotation: 0, |
| 1543 | + alignTop: false |
1543 | 1544 | }; |
1544 | 1545 |
|
1545 | 1546 | const animOptions = { ...defaultOptions, ...options }; |
|
1570 | 1571 | const containerWidth = lottieContainer.offsetWidth; |
1571 | 1572 | const containerHeight = lottieContainer.offsetHeight; |
1572 | 1573 |
|
1573 | | - const left = rect.left + (targetWidth - containerWidth) / 2; |
1574 | | - const top = rect.top + (targetHeight - containerHeight) / 2; |
1575 | | - |
1576 | | - lottieContainer.style.left = left + 'px'; |
1577 | | - lottieContainer.style.top = top + 'px'; |
| 1574 | + if (animOptions.alignTop) { |
| 1575 | + const left = rect.left + (targetWidth - containerWidth) / 2; |
| 1576 | + const top = rect.top; |
| 1577 | + lottieContainer.style.left = left + 'px'; |
| 1578 | + lottieContainer.style.top = top + 'px'; |
| 1579 | + } else { |
| 1580 | + const left = rect.left + (targetWidth - containerWidth) / 2; |
| 1581 | + const top = rect.top + (targetHeight - containerHeight) / 2; |
| 1582 | + lottieContainer.style.left = left + 'px'; |
| 1583 | + lottieContainer.style.top = top + 'px'; |
| 1584 | + } |
1578 | 1585 | } |
1579 | 1586 | }; |
1580 | 1587 |
|
|
1641 | 1648 | } |
1642 | 1649 | const answerBox = document.querySelector('.answer-box'); |
1643 | 1650 | const target = answerBox || document.querySelector('.result.kanji')?.querySelector('.plain').firstElementChild; |
1644 | | - const rect = target.getBoundingClientRect(); |
| 1651 | + let rect = target.getBoundingClientRect(); |
| 1652 | + |
| 1653 | + if (target.querySelector('img')) { |
| 1654 | + const elements = Array.from(target.children).filter((child) => child.tagName !== 'IMG'); |
| 1655 | + rect = elements.reduce( |
| 1656 | + (acc, el) => { |
| 1657 | + const elRect = el.getBoundingClientRect(); |
| 1658 | + return { |
| 1659 | + top: Math.min(acc.top, elRect.top), |
| 1660 | + left: Math.min(acc.left, elRect.left), |
| 1661 | + right: Math.max(acc.right, elRect.right), |
| 1662 | + bottom: Math.max(acc.bottom, elRect.bottom) |
| 1663 | + }; |
| 1664 | + }, |
| 1665 | + { top: Infinity, left: Infinity, right: -Infinity, bottom: -Infinity } |
| 1666 | + ); |
| 1667 | + |
| 1668 | + rect.width = rect.right - rect.left; |
| 1669 | + rect.height = rect.bottom - rect.top; |
| 1670 | + } |
1645 | 1671 |
|
1646 | 1672 | if (target) { |
1647 | 1673 | playLottieAnimation(target, WARM['smallFireworkAnimation'], { |
1648 | 1674 | loop: false, |
1649 | 1675 | autoplay: true, |
1650 | 1676 | renderer: 'svg', |
1651 | 1677 | size: { width: rect.height * 3, height: rect.height }, |
1652 | | - opacity: 0.5 |
| 1678 | + opacity: 0.5, |
| 1679 | + alignTop: true |
1653 | 1680 | }); |
1654 | 1681 | playLottieAnimation(target, WARM['bigFireworkAnimation'], { |
1655 | 1682 | loop: false, |
1656 | 1683 | autoplay: true, |
1657 | 1684 | renderer: 'svg', |
1658 | 1685 | size: { width: rect.height * 3, height: rect.height }, |
1659 | | - opacity: 0.5 |
| 1686 | + opacity: 0.5, |
| 1687 | + alignTop: true |
1660 | 1688 | }); |
1661 | 1689 |
|
1662 | 1690 | // const html = document.querySelector('html'); |
|
1810 | 1838 | if (USER_SETTINGS.enableButtonSound()) { |
1811 | 1839 | playSound(CONFIG.soundUrlReveal); |
1812 | 1840 | } |
1813 | | - const rect = target.getBoundingClientRect(); |
| 1841 | + let rect = target.getBoundingClientRect(); |
| 1842 | + |
| 1843 | + if (target.querySelector('img')) { |
| 1844 | + const elements = Array.from(target.children).filter((child) => child.tagName !== 'IMG'); |
| 1845 | + rect = elements.reduce( |
| 1846 | + (acc, el) => { |
| 1847 | + const elRect = el.getBoundingClientRect(); |
| 1848 | + return { |
| 1849 | + top: Math.min(acc.top, elRect.top), |
| 1850 | + left: Math.min(acc.left, elRect.left), |
| 1851 | + right: Math.max(acc.right, elRect.right), |
| 1852 | + bottom: Math.max(acc.bottom, elRect.bottom) |
| 1853 | + }; |
| 1854 | + }, |
| 1855 | + { top: Infinity, left: Infinity, right: -Infinity, bottom: -Infinity } |
| 1856 | + ); |
| 1857 | + |
| 1858 | + rect.width = rect.right - rect.left; |
| 1859 | + rect.height = rect.bottom - rect.top; |
| 1860 | + } |
| 1861 | + |
1814 | 1862 | playLottieAnimation(target, WARM['explosionAnimation'], { |
1815 | 1863 | loop: false, |
1816 | 1864 | autoplay: true, |
1817 | 1865 | renderer: 'svg', |
1818 | 1866 | speed: 1.5, |
1819 | 1867 | size: { width: rect.width, height: rect.height }, |
1820 | | - opacity: 0.5 |
| 1868 | + opacity: 0.5, |
| 1869 | + alignTop: true |
1821 | 1870 | }); |
1822 | 1871 | playLottieAnimation(target, WARM['bigFireworkAnimation'], { |
1823 | 1872 | loop: false, |
1824 | 1873 | autoplay: true, |
1825 | 1874 | renderer: 'svg', |
1826 | 1875 | speed: 1.5, |
1827 | 1876 | size: { width: rect.width, height: rect.height }, |
1828 | | - opacity: 0.5 |
| 1877 | + opacity: 0.5, |
| 1878 | + alignTop: true |
1829 | 1879 | }); |
1830 | 1880 | return true; |
1831 | 1881 | } |
|
0 commit comments