Zum übersetzen von markiertem Text oder ganzen Seiten gibt es ja schon reichlich sehr gute Extensions oder auch hier im Board ein einfaches aber funktionales Google-Bookmarklet.
Als Grundlage zum weiteren Verarbeiten von markiertem Text habe ich trotzdem versucht ContextTranslate aus der Sammlung wieder zum laufen zu bringen. Wer mag, kann es gerne nutzen.
Code
(function () {
if (location != 'chrome://browser/content/browser.xul')
return;
let translate = function () {
let browserMM = gBrowser.selectedBrowser.messageManager;
browserMM.addMessageListener('getSelection', function listener(message) {
let t = (message.data !== '');
let e = (document.charset || document.characterSet);
if (t) {
gBrowser.loadOneTab('http://translate.google.com/translate_t?hl=de-DE#auto|de-DE|' + message.data, null, null, null, false, false);
} else {
gBrowser.loadOneTab('http://translate.google.com/translate?u=' + gBrowser.currentURI.spec + '&hl=de-DE&ie=' + e + '&sl=auto&tl=de-DE', null, null, null, false, false);
};
browserMM.removeMessageListener('getSelection', listener, true);
});
browserMM.loadFrameScript('data:,sendAsyncMessage("getSelection", content.document.getSelection().toString())', true);
}
let menuitem = document.createElement('menuitem');
menuitem.id = 'context-googletranslate';
menuitem.setAttribute('label', 'GoogleTranslate');
menuitem.setAttribute('tooltiptext', 'GoogleTranslate');
menuitem.setAttribute('oncommand', '(' + translate.toString() + ')()');
menuitem.classList.add('menuitem-iconic');
//Wer kein Icon möchte kann die nächsten beiden Zeilen auskommentieren/löschen
//menuitem.style.listStyleImage = 'url("https://translate.google.com/favicon.ico")';
menuitem.style.listStyleImage = ' url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAwCAYAAABT9ym6AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjHxIGmVAAAHYklEQVRoQ+2Y6U+UVxSH9Xs/NGnSv6et1h1REWOrUEaomiZt2tQqRQFFcNiRImg1rnVBbZUoorhRYNhGZweGfYcBoQ6bn0/Pue+9w7vc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u0rJrU1djcA0ocTS7BhoabWC10kjRV6nKlxEUXi2jFlF3hT8+cpWc/OST1bEPUUBhVUwVpKNEY5MdXrxwMglPaxu0tyvdEOhF9OPFHx/ZSvjh8SSNEkmkqTpht+Pndg+NFHXDy9CL6LtCIti5Mf7oyFZK5rNU0QlLw0toaaHvgHEv3B4cqTYUoY4oMmoR8aoXefS4ycQfHdmi8UozP4Ha2mawWFpQ5CW+Z9BuOHHJ6dsUHC8PSbUaUEvi7/uqHjXswUeuVJ78od7HWrHiXwQB769LvTEjAAAAAElFTkSuQmCC")';
let refItem = document.getElementById('context-inspect');
refItem.parentNode.insertBefore(menuitem, refItem);
})();
Alles anzeigen