Google翻訳のブックマークレットを新しいタブで開くようにする方法

image

私の愛しいアップルパイへ

ブックマークレットとは、ブラウザのお気に入りボタンから起動できる簡単なツールです。私が可愛がっているブックマークレットの中にGoogle翻訳というものがあります。

その名の通り、文字列を選択して起動すると、Google翻訳ページが開いて選択した文字列を翻訳してくれるというものです。

これはGoogleが公式に配布しているツールで、こちらのページにあるボタンをお気に入りバーにドラッグするだけで使えるようになります。

ただ、どうしても気に入らなかったのが、翻訳画面が今開いているページを使ってしまう点です。翻訳は今のページではなく、新しいウィンドウを開いて翻訳して欲しいのです。

きっとあなたもそう思っているでしょうから、カスタマイズする方法をお教えします。

Google翻訳を新しいタブで開くようにする方法

Google翻訳ページの翻訳ブラウザ ボタンページに行き、目的のボタンを探します。
image

▼使いたいボタンをクリックし、「リンク アドレスをコピー」ボタンでコードをコピーします。
1

▼クリップボードにコードがコピーされますので、ブックマークバーに登録剃る前にテキストエディタなどに貼り付けて、コードを修正できるようにします。
image

コードの中にある2箇所の「location.href=…」部分を「window.open(…)」に修正します。

▼例えば日本語へ翻訳するブックマークレットの場合は以下のように修正します。

【変更前】
javascript:var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=”){location.href=‘http://translate.google.com/?text=’+t+’&hl=ja&langpair=auto|ja&tbb=1&ie=’+e;}else{location.href=‘http://translate.google.com/translate?u=’+encodeURIComponent(location.href)+’&hl=ja&langpair=auto|ja&tbb=1&ie=’+e;};

【変更後】
javascript:var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=”){window.open(‘http://translate.google.com/?text=’+t+’&hl=ja&langpair=auto|en&tbb=1&ie=’+e);}else{window.open(‘http://translate.google.com/translate?u=’+encodeURIComponent(location.href)+’&hl=ja&langpair=auto|en&tbb=1&ie=’+e);};

変更後のコードをお気に入りに登録すれば、新しいタブで開くGoogle翻訳のブックマークレットが完成です。

▼最後に、よく使われるであろう新しいタブで開く日本語への翻訳と英語への翻訳のブックマークレットを置いておきます。お気に入りを新規作成し、以下のリンクをURL欄に貼り付ければOKです。

↓日本語へ翻訳

[javascript] javascript:var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=”){window.open(‘http://translate.google.com/?text=’+t+’&hl=ja&langpair=auto|ja&tbb=1&ie=’+e);}else{window.open(‘http://translate.google.com/translate?u=’+encodeURIComponent(location.href)+’&hl=ja&langpair=auto|ja&tbb=1&ie=’+e);};
[/javascript]

 

↓英語へ翻訳

[javascript] javascript:var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=”){window.open(‘http://translate.google.com/?text=’+t+’&hl=ja&langpair=auto|en&tbb=1&ie=’+e);}else{window.open(‘http://translate.google.com/translate?u=’+encodeURIComponent(location.href)+’&hl=ja&langpair=auto|en&tbb=1&ie=’+e);};
[/javascript]

※ダブルクリックでコードを全選択できます

Google翻訳ブックマークレットで軽快に翻訳

翻訳ブックマークは意外に使い所が多いので、ブックマークレットに登録しておくと便利です。念のため使い方を書いておきます。

▼翻訳したいテキストを選択し
image

▼ブックマークバーのボタンをクリックすると
image

▼新しいタブでこのように翻訳してくれます
image

ナイス!

貴下の従順なる下僕 松崎より

著者画像

システム系の専門学校を卒業後、システム屋として6年半の会社員生活を経て独立。ブログ「jMatsuzaki」を通して、小学生のころからの夢であった音楽家へ至るまでの全プロセスを公開することで、のっぴきならない現実を乗り越えて、諦めきれない夢に向かう生き方を伝えている。