GitHubやAdobeフォーラムでコード以外の箇所だけ日本語翻訳する方法
Webサイト上で外国語の文章を読む際は、コンテクストメニューからGoogle日本語翻訳を行っています。
素のままのChromeでこれを行うと、コードブロック内も翻訳されてしまうという難点があります。
「ScriptAutoRunner」というChrome拡張で解決できるので手順を記録しておきます。
ScriptAutoRunnerとは
Chromeの拡張機能。
指定したサイトを開くたびに任意のjavascriptを実行します。
設定
①部分をクリックします。
②実行内容のタイトルを入力します。
③実行内容を入力します。
・Adobeフォーラム、GitHub、Indiscriptsの場合
Array.prototype.forEach.call(document.getElementsByTagName('pre'), x => x.classList.add('notranslate'))
・Gistの場合
Array.prototype.forEach.call(document.getElementsByClassName('js-gist-file-update-container js-task-list-container file-box'), x => x.classList.add('notranslate'))
④実行するサイトのホストを入力します。
・Adobeフォーラム、GitHub、Indiscriptsの場合
community.adobe.com, github.com, indiscripts.com
・Gistの場合
gist.github.com
⑤プラグをクリックし、有効にします。
参考
- 【JavaScript】要素の取得方法(getElement、querySelector) - Qiita
コードブロックの部分を特定する処理を書く際に参考にしました。