tt-Google-Translate

highlight keywords and double tap 't' key

目前為 2016-09-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        tt-Google-Translate
// @namespace   tt-Google-Translate
// @description highlight keywords and double tap 't' key
// @version     1
// @grant       none
// @include     *
// ==/UserScript==
var reset_function;
var current_key_state = 0;
var translate_string;
var google_translate_final_url;
var google_translate_api = "https://translate.google.com.hk/?hl=en&tab=wT#en/zh-TW/";
/*
var query_specials_map = {};
query_specials_map["%"] = "%25";    
query_specials_map["&"] = "%26";
*/
function translate_query_parser(text){
    /*
for (var key in query_specials_map) {
text = text.split(key).join(query_specials_map[key]);
} 
*/
return text;
} 
function translate(){  
    translate_string = translate_query_parser(window.getSelection().toString()); 
    if (""===translate_string) return; 
    google_translate_final_url = google_translate_api
    + translate_string;
    window.open(google_translate_final_url, "Powered By tt-Google-Translate",
        "toolbar=yes,menubar=yes,resizable=yes,titlebar=yes.location=yes,scrollbars=yes,status=yes,width=" + 
        screen.width + ",height=" + screen.height); 
}
document.addEventListener('keydown', function(event) {  
//alert(event.keyCode.toString()); 
    if (event.keyCode == 84) {  
    if(current_key_state == 0){
    current_key_state = 1;
    //clearTimeout(reset_function);
    reset_function = setTimeout(function(){ 
     current_key_state = 0;
     }, 300); 
     return;
    }
    if(current_key_state == 1){ 
    current_key_state = 0;
    clearTimeout(reset_function);    
    translate();
    return;
    } 
    }
    current_key_state = 0;
    clearTimeout(reset_function);
}, true);