7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

個人用:翻訳ブックマークレット

Last updated at Posted at 2016-04-22

選択範囲だけを簡単に翻訳したかったので、作りました。選択していない場合、エラーにならないように新規タブでページごと翻訳。

##ブックマークレット保存用

google_translate.js(COMPRESSED)
javascript:var%20t='https://translate.google.co.jp/#auto/ja/';var%20u='http://translate.google.com/translate?hl=ja&sl=auto&tl=ja&u=';var%20s=document.getSelection().toString();var%20q=location.href;if(s.length%3E0)%7Bvar%20e=encodeURIComponent(s);var%20w=window.open(t+e,'_blank','width=1280,height=800,scrollbars=yes')%7Delse%7Bvar%20e=encodeURIComponent(q);var%20w=window.open(u+e,'_tab')%7Dvoid(0);

##展開ソース

google_translate.js(UNCOMPRESSED)
javascript:
    //日本語ではなく他の言語に翻訳したい場合は、「ja」の部分を変更(ex. 英語の場合は「en」)
    var t = 'https://translate.google.co.jp/#auto/ja/';
    var u = 'http://translate.google.com/translate?hl=ja&sl=auto&tl=ja&u=';
    var s = document.getSelection().toString();
    var q = location.href;
    if (s.length > 0) {
        //テキストを選択している場合、Google翻訳をポップアップで表示
        var e = encodeURIComponent(s);
    var w = window.open(t + e, '_blank', 'width=1280,height=800,scrollbars=yes');
    } else {
        //テキストを選択していない場合、新規タブでページ翻訳
        var e = encodeURIComponent(q);
        var w = window.open(u + e, '_tab');
    }
    void(0);

##参考サイト
iPhone_User_Now!
http://ameblo.jp/keitaxxx1/entry-11499922175.html

7
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?