Mokuro.moe Better Chrome's Translate

Better translation for mokuro.moe's html manga, also rotated vertical japanese text to horizontal when translating to other languages

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Mokuro.moe Better Chrome's Translate
// @namespace    PlanetXX2
// @version      2025-04-26
// @description  Better translation for mokuro.moe's html manga, also rotated vertical japanese text to horizontal when translating to other languages
// @author       You
// @match        https://mokuro.moe/*.html
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mokuro.moe
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // replace all .textBox p with .textBox span
    // so that Google Translate can inline the text
    // which in result, provides better translation
    document.querySelectorAll('.textBox p').forEach(p => {
        const span = document.createElement('span');
        span.innerHTML = p.innerHTML;
        p.parentNode.replaceChild(span, p);
    });

    GM_addStyle(`
    .textBox:hover:has(font) {
    writing-mode: horizontal-tb !important;
    }

    .textBox:hover span {
    opacity: 100%;
    display: table;
    }

    .textBox:hover span:has(font) {
    background-color: white;
    width: fit-content;
    }

    .textBox span {
    opacity: 0%;
    white-space: nowrap;
    letter-spacing: 0.1em;
    line-height: 1.1em;
    margin: 0;
    background-color: rgb(255, 255, 255);
    }
    `)

})();