A bookmarklet for translating web pages using DeepL.
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 () { | |
var API_KEY = '<your_deel_api_key>'; | |
var DEEPL_TRANSLATE_EP = 'https://api.deepl.com/v2/translate'; | |
var TARGET_LANBG = 'JA'; | |
var bodyHtml = document.getElementsByTagName('body')[0].innerHTML; | |
var params = { | |
'auth_key': API_KEY, | |
'text': bodyHtml, | |
'target_lang': TARGET_LANBG, | |
'tag_handling': 'xml' | |
}; | |
var data = new URLSearchParams(); | |
Object.keys(params).forEach(key => data.append(key, params[key])); | |
fetch(DEEPL_TRANSLATE_EP, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded; utf-8' | |
}, | |
body: data | |
}).then(res => res.json()).then(resData => { | |
console.log(resData); | |
document.getElementsByTagName('body')[0].innerHTML = resData.translations[0].text; | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment