// ==UserScript== // @name DeepL - Auto VN Translation Extension Helper // @version 1.2.3 // @grant GM.setClipboard // @match https://www.deepl.com/translator // @description Watch for target language element class change, copy new value of textarea to clipboard each time change has been detected. // @author Zero_G // @icon https://www.deepl.com/img/logo/deepl-logo-blue.svg // @namespace Zero_G.autovntranslation // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Filters to apply to translated text // These were originally here, so leaving them as is for compatibility to previous caches (as filtering should be done in setClipboardText) const filters = { // '' : /\"+|\'\'+/g, // Remove " or '' // '...' : /\.\.\.\.+/g // Change multiple dots (when there are more than 3 to '...' only) } const mutationObserver = new MutationObserver(callback) // Observe the text div that contain the translation // But as the translated text appears in a

in a ::before css we need to watch // for added nodes mutationObserver.observe( document.querySelector('#translation-target-heading').parentNode, { childList: true, subtree: true } ) function callback(mutationsList) { mutationsList.forEach(mutation => { if (mutation.type === 'childList' && // Irrelevant as we are already watching for childList only but meh mutation.addedNodes.length !== 0 && // Looking for a mutation with an added node mutation.removedNodes.length !== 0 && // This condition is to prevent a repeat !mutation.addedNodes[0].innerHTML.includes(' (get as value doesn't work) // Will only work with the first line of text translated, as the previous code is eliminating linebraks anyway, doesn't matter let text = ''; if (mutation.addedNodes[0].firstChild) { text = mutation.addedNodes[0].firstChild.innerHTML; } else { text = mutation.addedNodes[0].innerHTML; } // Apply filters for (const [key, value] of Object.entries(filters)) { text = text.replace(value, key); } // Copy to memory with GreaseMonkey special function (needs @grant) GM.setClipboard(text); } }) } })();