-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.translate.en.baidu.user.js
64 lines (56 loc) · 2.04 KB
/
plugin.translate.en.baidu.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ==UserScript==
// @name 细声百度翻译(英语)
// @namespace http://www.xlwmin.pub
// @version 1.0.1
// @description 1.0.0 选中文字跳转百度翻译 1.0.1 对选中文本编码
// @author 细声工作室
// @license MIT
// @match *://www.quora.com/*
// @match *://www.youtube.com/*
// @match *://www.imdb.com/*
// @match *://www.reddit.com/*
// @match *://www.resetera.com/*
// @match *://www.ign.com/*
// @match *://*.cnn.com/*
// @match *://*.steamcommunity.com/*
// @grant GM_addStyle
// ==/UserScript==
//测试同步
var Page = {
text:null,
entry:function(){
//创建按钮
var text = document.createTextNode("EN");
//创建按钮
var div = document.createElement("div");
div.setAttribute("title","跳转翻译");
div.setAttribute("class","whisper-translate");
//注册事件
div.addEventListener("click",this.onClick);
window.addEventListener("mouseup",this.onWindowMouseUp);
//添加到页面
div.appendChild(text);
document.body.appendChild(div);
},
onWindowMouseUp:function(){
var text = window.getSelection().toString();
if(text!=''){
Page.text = text;
}
},
onClick:function(){
var form = document.createElement("form");
form.setAttribute("method","get");
form.setAttribute("action","https://fanyi.baidu.com/#en/zh/"+encodeURIComponent(Page.text));
form.setAttribute("target","_blank");
form.style.display="none";
document.body.appendChild(form);
//console.log(Page.text);
form.submit();
}
};
(function() {
'use strict';
GM_addStyle(".whisper-translate{position:fixed;left:0;top:150px;color:#fff;z-index:9999;width:18px;line-height:30px;text-align:center;border-radius:0px 5px 5px 0px;background:#666;cursor:default;font-size:15px;}.whisper-translate:hover{color:white;background:#880000;cursor:pointer;}");
Page.entry();
})();