Translate a page on Chrome using bookmarklets

0

Background

On Chrome, I have a bookmarklet called Simplified to Traditional Chinese which translates all the simplified Chinese on the current page to traditional Chinese.

javascript:(
  function() {
    var s = document.getElementById("tongwenlet_tw");
    if (s != null) {
      document.body.removeChild(s);
    }
    var s = document.createElement("script");
    s.language = "javascript";
    s.type = "text/javascript";
    s.src = "http://tongwen.openfoundry.org/NewTongWen/tools/bookmarklet_tw.js";
    s.id = "tongwenlet_tw";
    document.body.appendChild(s);
  }
)();

Note: the actual code is below; I indented and added \n to make it more readable:

javascript:(function(){var s=document.getElementById("tongwenlet_tw");if(s!=null){document.body.removeChild(s);}var s=document.createElement("script");s.language="javascript";s.type="text/javascript";s.src="http://tongwen.openfoundry.org/NewTongWen/tools/bookmarklet_tw.js";s.id="tongwenlet_tw";document.body.appendChild(s); })();

The code is copied from this site.

The Problem

Whenever http://tongwen.openfoundry.org/NewTongWen/tools/bookmarklet_tw.js didn't work (their servers seem to crash frequently), this bookmark becomes useless.

I want to be able to translate a webpage regardless of whether tongwen.openfoundry.org is up.

My Attempted Solution that Failed

I downloaded their bookmarklet_tw.js, saved it to a local directory:

/Users/ABC/Documents/bookmarklet_tw.js

And replaced the HTTP address in the code above with:

s.src = "/Users/ABC/Documents/bookmarklet_tw.js";

But that didn't work. Can anybody help? I'm using a Macbook Pro with Chrome Version 56.0 (64 bit).

Thanks for your time and patience.

Elizabeth Chu

Posted 2017-03-14T10:18:39.483

Reputation: 31

Any ideas, guys? I feel like there is a simple solution relating to JavaScript that I'm not grasping here. – Elizabeth Chu – 2017-03-19T14:41:01.043

Answers

0

I'm not a JavaScript genius, but I changed my Google Translate bookmarklet to use traditional Chinese instead of English:

javascript javascript:var t=((window.getSelection&&window.getSelection())%7C%7C(document.getSelection&&document.getSelection())%7C%7C(document.selection&&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset%7C%7Cdocument.characterSet);if(t!='')%7Blocation.href='http://translate.google.com/?text='+t+'&hl=zh-TW&langpair=auto%7Czh-TW&tbb=1&ie='+e;%7Delse%7Blocation.href='http://translate.google.com/translate?u='+encodeURIComponent(location.href)+'&hl=zh-TW&langpair=auto%7Czh-TW&tbb=1&ie='+e;%7D;

patrick

Posted 2017-03-14T10:18:39.483

Reputation: 950