Last active
September 27, 2019 22:42
-
-
Save noelleleigh/c39dc63fa323694e0c0c753840c71238 to your computer and use it in GitHub Desktop.
Bookmarklet to translate a webpage into English
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function () { | |
const remoteScript = document.createElement('script'); | |
remoteScript.src = 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'; | |
remoteScript.type = 'text/javascript'; | |
document.body.appendChild(remoteScript); | |
const containerElem = document.createElement('div'); | |
containerElem.id = 'google_translate_element'; | |
document.body.insertBefore(containerElem, document.body.firstChild); | |
const localScript = document.createElement('script'); | |
localScript.type = 'text/javascript'; | |
localScript.text = `function googleTranslateElementInit() { | |
new google.translate.TranslateElement({ | |
pageLanguage: '', | |
layout: google.translate.TranslateElement.FloatPosition.TOP_LEFT | |
}, 'google_translate_element'); | |
}`; | |
document.body.appendChild(localScript); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're using uBlock Origin's medium mode, make sure to set these rules to allow the bookmarklet to load the necessary Javascript: