Qidian Force Translate (Permanent)

Fix translation on all Qidian subdomains automatically

// ==UserScript==
// @name         Qidian Force Translate (Permanent)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Fix translation on all Qidian subdomains automatically
// @match        *://*.qidian.com/*
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    function fixHtml() {
        let html = document.querySelector("html");
        if (html) {
            html.setAttribute("translate", "yes");
            html.removeAttribute("class"); // removes 'notranslate'
            console.log('Qidian translate fix applied.');
        }
    }

    // Delay 3 seconds to let page fully load
    setTimeout(fixHtml, 3000);

    // Watch for dynamic rewrites
    setTimeout(() => {
        new MutationObserver(fixHtml).observe(document.documentElement, {
            attributes: true,
            childList: true,
            subtree: true
        });
    }, 3000);
})();