書籤工具的設計原理

作品

書籍

課程

程式集

小說集

論文集

散文集

影片集

編輯雜誌

程式人

電子書

JavaScript

計算語言學

微積分

Blender 動畫

C# 語言

系統程式

高等 C 語言

Java

Android

Verilog

Wikidot

R 統計軟體

機率統計

計算機數學

組合語言

人工智慧

開放原始碼

網路資源運用

計算機結構

相關訊息

常用工具

友站連結

在家教育

RSS

最新修改

網頁列表

簡體版

English

書籤工具

  1. 翻譯精靈GAE站 , 金技站

書籤檔案

  1. toolbar.htm
  2. main.js
  3. toolbar.js

Google 翻譯的 Bookmarkelet

<a href="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/translate_t?text='+t+'&hl=en&langpair=auto|zh-TW&tbb=1&ie='+e;
} else {
  location.href='http://translate.google.com/translate?u='+escape(location.href)+'&
                        hl=en&langpair=auto|zh-TW&tbb=1&ie='+e;
};">
Google翻譯
</a>

陳鍾誠的書籤翻譯工具

書籤超連結

<a href="javascript:(function(){s=document.createElement('script');s.type='text/javascript';s.src='http://ccc.kmit.edu.tw/bookmarklet/toolbar/toolbar.js';document.body.appendChild(s); })();">翻譯專家</a> -- 翻譯用的書籤工具,可將選取範圍的文章翻譯成中文顯示,這是利用 Google 翻譯 API + JavaScript 所作的書籤小工具。

toolbar.js

(
function() {
  if (!document.getElementById("toolbar")) {
    p = document.createElement("div");
    p.id = "toolbar";
    p.style.cssText = "width:100%;background-color:#eee;border:1px solid #333;z-index:9999;position:fixed;top:0px;left:0px;text-align:left;cursor:move;font-size:12px;font-family:細明體";
    p.innerHTML = "<table width='100%'><tr><td width='30'><div id='msgbar' style='display:none'></div></td><td>原文:"+
    "<input id='sourceText' type='text' size='40'/> <input type='button' onclick='javascript:void(translateSelected())' value='翻譯'/>"+
    "</td><td width='100'><a onclick='hideToolbar();'>隱藏 ↑</a></td></tr></table>";
    document.body.appendChild(p);
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://ccc.kmit.edu.tw/bookmarklet/toolbar/main.js"
    document.getElementsByTagName("head")[0].appendChild(script);
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://www.google.com/jsapi?callback=pageLoaded";
    document.getElementsByTagName("head")[0].appendChild(script);
  } else {
    pageLoaded();
    document.getElementById("toolbar").style.display = "block";
  }
})();

main.js

function hideToolbar(){
  document.getElementById("toolbar").style.display = "none";
}

function transCallback(result) {
    if (result.translation) {
      alert("原文:"+selectText + "\n\n中文:"+result.translation);
    }
}

selectText = "";

function translate(text) {
  google.language.translate(text, "", "zh-TW", transCallback);
}

function translateSelected() {
  selectText=((window.getSelection && window.getSelection())
                ||(document.getSelection && document.getSelection())
                ||(document.selection && document.selection.createRange
                   &&document.selection.createRange().text));
  if (!selectText || selectText == "")
    selectText = document.getElementById("sourceText").value;
  document.getElementById("sourceText").value = selectText;
  document.getElementById("msgbar").innerHTML = selectText; // 奇怪,一定要加這兩行才行。
  selectText = document.getElementById("msgbar").innerHTML; // 奇怪,一定要加這兩行才行。
  google.language.translate(selectText, "", "zh-TW", transCallback);
}

function langLoaded() {
}

function pageLoaded() {
  google.load("language", "1", { "callback": langLoaded });
}

方智誼的書籤翻譯工具

javascript:(function(){s=document.createElement('script');s.type='text/javascript';s.src='http://maxty1.myweb.hinet.net/lang.js';document.body.appendChild(s);})();

檔案:http://maxty1.myweb.hinet.net/lang.js

(
function() {
    if (!document.getElementById("lang")) {
        m = document.createElement("div");
        m.id = "lang";
        m.style.cssText = "width:500px;height: auto;top:120px;left:200px;z-index:99999;text-align:left;position: absolute;background-color:#eee;border:1px solid #333;";
        document.body.appendChild(m);
        d = document.createElement("div");
        d.id = "dragframe";
        d.style.cssText = "width:500px;height:20px;background-color:#eee;border:1px solid #333;z-index:1000;position:absolute;top:100px;left:200px;text-align:center;cursor:move;";
        d.innerHTML = "<div><input type='button' style='cursor: pointer;' value='翻譯' onclick='langLoaded();'>--------Google 翻譯 ------<a style='cursor: pointer;' onclick='mapclose();'>關閉</a></div>";

        document.body.appendChild(d);

        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://maxty1.myweb.hinet.net/ajax_lang.js"
        document.getElementsByTagName("head")[0].appendChild(script);

        var script = document.createElement("script");
        script.src = "http://www.google.com/jsapi?callback=loadLang";
        script.type = "text/javascript";
        document.getElementsByTagName("head")[0].appendChild(script);

    } else {
        langLoaded();
        document.getElementById("dragframe").style.display = "block";
        document.getElementById("lang").style.display = "block";
    }

})();

檔案:http://maxty1.myweb.hinet.net/ajax_lang.js

function langLoaded() {
    var text = ((window.getSelection && window.getSelection())
                || (document.getSelection && document.getSelection())
                || (document.selection && document.selection.createRange
                   && document.selection.createRange().text));

    document.getElementById("lang").innerHTML = '原文:<br />' + text + '<br />翻譯中...';

    google.language.translate(text, "en", "zh-TW",
        function(result) {
            if (!result.error) {
                document.getElementById("lang").innerHTML = result.translation;
            } else {
                document.getElementById("lang").innerHTML = '翻譯失敗..';
            }
        });

}

function loadLang() {

    google.load("language", "1", { "callback": langLoaded });
    dragfun(document.getElementById('dragframe'));

}
function mapclose() {
    document.getElementById("dragframe").style.display = "none";
    document.getElementById("lang").style.display = "none";
}

function dragfun(o) {
    o.onmousedown = function(a) {
        var d = document; if (!a) a = window.event;
        var x = a.layerX ? a.layerX : a.offsetX, y = a.layerY ? a.layerY : a.offsetY;
        if (o.setCapture)
            o.setCapture();
        else if (window.captureEvents)
            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
        d.onmousemove = function(e) {

            if (document.all) e = window.event;
            ele = (document.all) ? e.srcElement : e.target;
            tx = e.clientX;
            ty = e.clientY;
            tx += (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
            ty += (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;

            var f = document.getElementById("lang");
            o.style.left = tx - x;
            o.style.top = ty - y;
            f.style.left = o.style.left;
            f.style.top = parseInt(o.style.top) + parseInt(o.style.height);
        };
        d.onmouseup = function() {
            if (o.releaseCapture)
                o.releaseCapture();
            else if (window.captureEvents)
                window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
            d.onmousemove = null;
            d.onmouseup = null;
        };
    };
}

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License