Ich habe auf der Seite über die CDU-Politik etliche englische Zitate aus einer Quelle eingefügt. Dabei kam mir die Idee, dass ich nach den Zitaten automatisch einen Verweis zu Deepl mit der Übersetzung einbauen kann. Schwierig war es am Ende nicht:

/* {{{ auto-deepl */
function autoDeepl() {
    const docLang = document.documentElement.lang.substr(0, 2).toLowerCase();
    if (docLang.length === 0)
        return;

    document.body.querySelectorAll("*[lang]").forEach(el => {
        const blockLang = el.lang.substr(0, 2).toLowerCase();
        if (docLang === blockLang)
            return;

        const span = document.createElement('span');
        span.classList.add('deepl-translation');
        // without the   Firefox allows a line-break before the span.
        span.innerHTML = '&nbsp;(<a target=_blank>Deepl-Übersetzung</a>)';
        span.firstElementChild.href = 'https://www.deepl.com/translator#'
            + blockLang + '/' + docLang + '/' + encodeURI(el.innerText);

        el.insertAdjacentElement('afterend', span);
    });
}
/* }}} auto-deepl */

Diese Funktion autoDeepl rufe ich bei DOMContentLoaded auf.

Anwendungsbeispiel

<q lang=en>Science is the game we play with God to find out what
his rules are.</q>

<blockquote lang=en>
Computer games don't affect kids. If Pacman would have affected us as
children, we would now run around in darkened rooms, munching yellow
pills and listening to repetetive music.
</blockquote>

George Burns, Life magazine, 1979: <q lang=en>Too bad that all the
people who know how to run the country are busy driving taxicabs
and cutting hair.</q>

Science is the game we play with God to find out what his rules are.

Computer games don't affect kids. If Pacman would have affected us as children, we would now run around in darkened rooms, munching yellow pills and listening to repetetive music.

George Burns, Life magazine, 1979: Too bad that all the people who know how to run the country are busy driving taxicabs and cutting hair.