整合查询结果,优化使用体验
This commit is contained in:
parent
f27e56b1cb
commit
3e921f03e5
18
README.md
18
README.md
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
### translate.js
|
### translate.js
|
||||||
|
|
||||||
![translate](translate/translate.png)
|
![translate.jpg](translate/translate.jpg)
|
||||||
|
|
||||||
特色:
|
特色:
|
||||||
* 划词翻译调用“金山词霸、有道词典(有道翻译)、Google Translate(谷歌翻译)、沪江小D、搜狗翻译、必应词典(必应翻译)、Microsoft Translator(必应在线翻译)、海词词典、百度翻译、Oxford Learner's Dictionaries、Oxford Dictionaries、Merriam-Webster、汉典”网页翻译
|
* 划词翻译调用“金山词霸、有道词典(有道翻译)、Google Translate(谷歌翻译)、沪江小D、搜狗翻译、必应词典(必应翻译)、Microsoft Translator(必应在线翻译)、海词词典、百度翻译、Oxford Learner's Dictionaries、Oxford Dictionaries、Merriam-Webster、汉典”网页翻译
|
||||||
|
@ -15,24 +15,22 @@
|
||||||
|
|
||||||
### translate-dictionary.js
|
### translate-dictionary.js
|
||||||
|
|
||||||
![translate-dictionary.png](translate/translate-dictionary.png)
|
![translate-dictionary.jpg](translate/translate-dictionary.jpg)
|
||||||
|
|
||||||
特色:
|
特色:
|
||||||
* 金山词霸查询
|
* 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、沪江小D、谷歌翻译”
|
||||||
* 有道词典查询
|
|
||||||
* 谷歌翻译查询
|
|
||||||
* 支持发音
|
* 支持发音
|
||||||
* 支持显示当前翻译引擎
|
* 支持显示当前翻译引擎
|
||||||
* 支持面板拖动
|
* 支持面板拖动
|
||||||
|
|
||||||
### translate.js *and* translate-dictionary.js
|
### translate.js *and* translate-dictionary.js
|
||||||
|
|
||||||
![translate-bundle.png](translate/translate-bundle.png)
|
![translate-bundle.jpg](translate/translate-bundle.jpg)
|
||||||
|
|
||||||
同时安装:
|
同时安装:
|
||||||
|
|
||||||
① 划词翻译:有道词典,金山词霸,谷歌翻译
|
① 划词翻译:多词典查询
|
||||||
https://greasyfork.org/zh-CN/scripts/376313-%E5%88%92%E8%AF%8D%E7%BF%BB%E8%AF%91-%E6%9C%89%E9%81%93%E8%AF%8D%E5%85%B8-%E9%87%91%E5%B1%B1%E8%AF%8D%E9%9C%B8-%E8%B0%B7%E6%AD%8C%E7%BF%BB%E8%AF%91
|
https://greasyfork.org/zh-CN/scripts/376313-%E5%88%92%E8%AF%8D%E7%BF%BB%E8%AF%91-%E5%A4%9A%E8%AF%8D%E5%85%B8%E6%9F%A5%E8%AF%A2
|
||||||
|
|
||||||
② Translate
|
② Translate
|
||||||
https://greasyfork.org/zh-CN/scripts/34921-translate
|
https://greasyfork.org/zh-CN/scripts/34921-translate
|
||||||
|
@ -54,5 +52,5 @@ Tampermonkey 是一款免费的浏览器扩展和最为流行的用户脚本管
|
||||||
|
|
||||||
脚本名 | 用途
|
脚本名 | 用途
|
||||||
-|-
|
-|-
|
||||||
translate.js|划词翻译调用“金山词霸、有道词典(有道翻译)、Google Translate(谷歌翻译)、搜狗翻译、必应词典(必应翻译)、Microsoft Translator(必应在线翻译)、海词词典、百度翻译、Oxford Learner's Dictionaries、Oxford Dictionaries、Merriam-Webster”网页翻译
|
translate.js|划词翻译调用“金山词霸、有道词典(有道翻译)、Google Translate(谷歌翻译)、沪江小D、搜狗翻译、必应词典(必应翻译)、Microsoft Translator(必应在线翻译)、海词词典、百度翻译、Oxford Learner's Dictionaries、Oxford Dictionaries、Merriam-Webster、汉典”网页翻译
|
||||||
translate-dictionary.js|划词翻译调用“有道词典(有道翻译)、金山词霸、谷歌翻译”
|
translate-dictionary.js|划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、沪江小D、谷歌翻译”
|
||||||
|
|
|
@ -1,297 +0,0 @@
|
||||||
// ==UserScript==
|
|
||||||
// @name Translate
|
|
||||||
// @namespace http://tampermonkey.net/
|
|
||||||
// @version 1.4
|
|
||||||
// @description 划词翻译调用“必应翻译(必应词典)、谷歌翻译、有道词典(有道翻译)、百度翻译”网页翻译
|
|
||||||
// @author barrer
|
|
||||||
// @match http://*/*
|
|
||||||
// @include https://*/*
|
|
||||||
// @include file:///*
|
|
||||||
// @run-at document-end
|
|
||||||
// @connect dict.youdao.com
|
|
||||||
// @connect cn.bing.com
|
|
||||||
// @connect translate.googleapis.com
|
|
||||||
// @connect fanyi.baidu.com
|
|
||||||
// @grant GM_xmlhttpRequest
|
|
||||||
// ==/UserScript==
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Your code here...
|
|
||||||
/**日志输出*/
|
|
||||||
function log() {
|
|
||||||
var debug = false;
|
|
||||||
if (!debug)
|
|
||||||
return;
|
|
||||||
if (arguments) {
|
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
|
||||||
console.log(arguments[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log('url:' + window.location.href);
|
|
||||||
// 翻译图标
|
|
||||||
var icon = document.createElement('div'), style = '' +
|
|
||||||
'font-family:Arial,sans-serif!important;' +
|
|
||||||
'font-weight:normal!important;' +
|
|
||||||
'background:#f60!important;' +
|
|
||||||
'color:#fff!important;' +
|
|
||||||
'border-radius:3px!important;' +
|
|
||||||
'font-size:13px!important;' +
|
|
||||||
'line-height:100%!important;' +
|
|
||||||
'padding:2px 4px!important;' +
|
|
||||||
'margin:0 4px!important;' +
|
|
||||||
'display:inline-block!important;' +
|
|
||||||
'text-decoration:none!important;' +
|
|
||||||
'';
|
|
||||||
icon.innerHTML = '' +
|
|
||||||
'<a href="javascript:void(0)" style="' + style + '" type="bing">必应</a>' +
|
|
||||||
'<a href="javascript:void(0)" style="' + style + '" type="google">谷歌</a>' +
|
|
||||||
'<a href="javascript:void(0)" style="' + style + '" type="youdao">有道</a>' +
|
|
||||||
'<a href="javascript:void(0)" style="' + style + '" type="baidu_translator">百度</a>' +
|
|
||||||
'';
|
|
||||||
icon.setAttribute('style', '' +
|
|
||||||
'display:none!important;' +
|
|
||||||
'position:absolute!important;' +
|
|
||||||
'font-size:13px!important;' +
|
|
||||||
'text-align:left!important;' +
|
|
||||||
'z-index:2147483647!important;' +
|
|
||||||
'');
|
|
||||||
// 添加翻译图标到 DOM
|
|
||||||
document.documentElement.appendChild(icon);
|
|
||||||
// 鼠标事件:防止选中的文本消失
|
|
||||||
document.addEventListener('mousedown', function (e) {
|
|
||||||
if (e.target == icon || (e.target.parentNode && e.target.parentNode == icon)) {// 点击了翻译图标
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 选中变化事件:当点击已经选中的文本的时候,隐藏翻译图标和翻译面板(此时浏览器动作是:选中的文本已经取消选中了)
|
|
||||||
document.addEventListener("selectionchange", function () {
|
|
||||||
log('selectionchange:' + window.getSelection().toString());
|
|
||||||
if (!window.getSelection().toString().trim()) {
|
|
||||||
icon.style.display = 'none';
|
|
||||||
server.containerDestroy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 鼠标事件:防止选中的文本消失;显示、隐藏翻译图标
|
|
||||||
document.addEventListener('mouseup', function (e) {
|
|
||||||
if (e.target == icon || (e.target.parentNode && e.target.parentNode == icon)) {// 点击了翻译图标
|
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < server.rendered.length; i++) {// 点击了翻译内容面板
|
|
||||||
if (e.target == server.rendered[i])
|
|
||||||
return;// 不再创建翻译图标
|
|
||||||
}
|
|
||||||
var text = window.getSelection().toString().trim();
|
|
||||||
log('text:' + text);
|
|
||||||
if (text && icon.style.display == 'none') {
|
|
||||||
log('show icon');
|
|
||||||
log(text + '|' + e.pageX + '|' + e.pageY);
|
|
||||||
icon.style.top = e.pageY + 10 + 'px';
|
|
||||||
icon.style.left = e.pageX + 10 + 'px';
|
|
||||||
icon.style.display = 'block';
|
|
||||||
} else if (!text) {
|
|
||||||
log('hide icon');
|
|
||||||
icon.style.display = 'none';
|
|
||||||
server.containerDestroy();// 销毁翻译内容面板
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 翻译图标点击事件
|
|
||||||
icon.addEventListener('click', function (e) {
|
|
||||||
var text = window.getSelection().toString().trim();
|
|
||||||
if (text) {
|
|
||||||
log('click:' + text);
|
|
||||||
server.containerDestroy();// 销毁翻译内容面板
|
|
||||||
// 新建翻译内容面板
|
|
||||||
var container = server.container();
|
|
||||||
container.style.top = e.pageY + 16 + 'px';
|
|
||||||
if (e.pageX + 250 + 16 <= document.body.clientWidth)// container 面板css最大宽度为250px
|
|
||||||
container.style.left = e.pageX + 16 + 'px';
|
|
||||||
else
|
|
||||||
container.style.left = document.body.clientWidth - 250 + 'px';
|
|
||||||
document.body.appendChild(container);
|
|
||||||
server.rendered.push(container);
|
|
||||||
// 判断用户选择的翻译引擎
|
|
||||||
var engine = e.target.hasAttribute('type') ? e.target.getAttribute('type') : '';
|
|
||||||
log('engine:' + engine);
|
|
||||||
switch (engine) {
|
|
||||||
case 'bing':
|
|
||||||
server.bing(text, container);
|
|
||||||
break;
|
|
||||||
case 'google':
|
|
||||||
server.google(text, container);
|
|
||||||
break;
|
|
||||||
case 'baidu_translator':
|
|
||||||
server.baidu_translator(text, container);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
server.youdao(text, container);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 翻译server
|
|
||||||
var server = {
|
|
||||||
// 存放已经生成的翻译内容面板(销毁的时候用)
|
|
||||||
rendered: [],
|
|
||||||
// 有道翻译 引擎
|
|
||||||
youdao: function (text, element) {
|
|
||||||
this.ajax('http://dict.youdao.com/w/eng/' + encodeURIComponent(text), function (rst, ele) {
|
|
||||||
var parser = new DOMParser(), doc = parser.parseFromString(rst, 'text/html'), html = '';
|
|
||||||
var word = doc.querySelector('#phrsListTab .wordbook-js .keyword'),
|
|
||||||
pronounce = doc.querySelector('#phrsListTab .wordbook-js .baav'),
|
|
||||||
trans = doc.querySelector('#phrsListTab .trans-container'),
|
|
||||||
webTrans = doc.querySelectorAll('#tWebTrans .wt-container .title');
|
|
||||||
if (!!!pronounce) // 中文拼音
|
|
||||||
pronounce = doc.querySelector('#phrsListTab .wordbook-js .phonetic');
|
|
||||||
// 排版
|
|
||||||
var pos = trans && trans.querySelectorAll('ul li,ul .wordGroup');
|
|
||||||
for (var i = 0; pos && i < pos.length; i++) {
|
|
||||||
pos[i].innerHTML = pos[i].innerHTML + '▓';
|
|
||||||
}
|
|
||||||
html += word ? word.innerText.trim() : '';
|
|
||||||
html += pronounce ? ' ' + pronounce.innerText.replace(/(\s)+/g, ' ').trim() : '';
|
|
||||||
html += trans && trans.querySelector('ul') ? '\n' +
|
|
||||||
trans.querySelector('ul').innerText
|
|
||||||
.replace(/(\s)+/g, ' ')
|
|
||||||
.replace(/(▓)+/g, '\n').trim()
|
|
||||||
: '';
|
|
||||||
html += trans && trans.querySelector('.additional') ?
|
|
||||||
'\n' + trans.querySelector('.additional').innerText.trim().replace(/\n/g, '') : '';
|
|
||||||
if (!!webTrans.length) {
|
|
||||||
html += '\n网络释义:\n';
|
|
||||||
for (var j = 0; j < webTrans.length; j++) {
|
|
||||||
if (j !== 0)
|
|
||||||
html += ';';
|
|
||||||
html += webTrans[j].innerText.replace(/\n/g, '').trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ele.innerText = html;
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
}, function (rst, ele) {
|
|
||||||
ele.innerText = '有道翻译 无法连接!';
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
}, element);
|
|
||||||
},
|
|
||||||
// Bing词典 引擎
|
|
||||||
bing: function (text, element) {
|
|
||||||
this.ajax('http://cn.bing.com/dict/search?q=' + encodeURIComponent(text), function (rst, ele) {
|
|
||||||
var parser = new DOMParser(), doc = parser.parseFromString(rst, 'text/html'), html = '';
|
|
||||||
var word = doc.querySelector('.hd_area'),
|
|
||||||
trans = doc.querySelector('.qdef ul'),
|
|
||||||
forms = doc.querySelector('.qdef .hd_if');
|
|
||||||
// 排版
|
|
||||||
var headword = doc.querySelector('#headword');
|
|
||||||
if (headword)
|
|
||||||
headword.innerHTML = headword.innerHTML + '<br>';
|
|
||||||
var pos = doc.querySelectorAll('.qdef ul li .pos');
|
|
||||||
for (var i = 0; i < pos.length; i++) {
|
|
||||||
pos[i].innerText = '\n【' + pos[i].innerText + '】';
|
|
||||||
}
|
|
||||||
html += word ? word.innerText.replace(/\n/g, ' ').trim() : '';
|
|
||||||
html += trans ? '\n' + trans.innerText.trim() : '';
|
|
||||||
html += forms ? '\n' + forms.innerText.trim() : '';
|
|
||||||
ele.innerText = html;
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
}, function (rst, ele) {
|
|
||||||
ele.innerText = 'Bing词典 无法连接!';
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
}, element);
|
|
||||||
},
|
|
||||||
// 谷歌翻译 引擎
|
|
||||||
google: function (text, element) {
|
|
||||||
var apiUrl = 'https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&dt=bd&dj=1&source=input&sl=en&tl=zh-CN&hl=en&q=';
|
|
||||||
this.ajax(apiUrl + encodeURIComponent(text), function (rst, ele) {
|
|
||||||
var json = JSON.parse(rst), html = '';
|
|
||||||
for (var i = 0; i < json.sentences.length; i++) {
|
|
||||||
html += json.sentences[i].orig + '\n';
|
|
||||||
html += json.sentences[i].trans + '\n';
|
|
||||||
}
|
|
||||||
ele.innerText = html;
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
}, function (rst, ele) {
|
|
||||||
ele.innerText = '谷歌翻译 无法连接!';
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
}, element);
|
|
||||||
},
|
|
||||||
// 百度翻译 引擎
|
|
||||||
baidu_translator: function (text, element) {
|
|
||||||
var data = new FormData();
|
|
||||||
data.set('from', 'en');
|
|
||||||
data.set('to', 'zh');
|
|
||||||
data.set('query', text);
|
|
||||||
this.ajax('http://fanyi.baidu.com/v2transapi', function (rst, ele) {
|
|
||||||
var json = JSON.parse(rst), html = '';
|
|
||||||
for (var i = 0; i < json.trans_result.data.length; i++) {
|
|
||||||
html += json.trans_result.data[i].src + '\n';
|
|
||||||
html += json.trans_result.data[i].dst + '\n';
|
|
||||||
}
|
|
||||||
ele.innerText = html;
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
}, function (rst, ele) {
|
|
||||||
ele.innerText = '百度翻译 无法连接!';
|
|
||||||
ele.style.display = 'block';// 显示结果
|
|
||||||
},
|
|
||||||
element,
|
|
||||||
'POST',
|
|
||||||
data
|
|
||||||
);
|
|
||||||
},
|
|
||||||
// ajax 跨域访问公共方法
|
|
||||||
ajax: function (url, success, error, element, method, data, headers) {
|
|
||||||
if (!!!method)
|
|
||||||
method = 'GET';
|
|
||||||
// >>>因为Tampermonkey跨域访问(a.com)时会自动携带对应域名(a.com)的对应cookie
|
|
||||||
// 不会携带当前域名的cookie
|
|
||||||
// 所以,GM_xmlhttpRequest【不存在】cookie跨域访问安全性问题
|
|
||||||
// 以下设置默认headers不起作用<<<
|
|
||||||
if (!!!headers)
|
|
||||||
headers = {'cookie': ''};
|
|
||||||
GM_xmlhttpRequest({
|
|
||||||
method: method,
|
|
||||||
url: url,
|
|
||||||
headers: headers,
|
|
||||||
data: data,
|
|
||||||
onload: function (res) {
|
|
||||||
success(res.responseText, element);
|
|
||||||
},
|
|
||||||
onerror: function (res) {
|
|
||||||
error(res.responseText, element);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
// 销毁已经生成的翻译内容面板
|
|
||||||
containerDestroy: function () {
|
|
||||||
for (var i = this.rendered.length - 1; i >= 0; i--) {
|
|
||||||
if (this.rendered[i] && this.rendered[i].parentNode) {
|
|
||||||
this.rendered[i].parentNode.removeChild(this.rendered[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 生成翻译结果面板 DOM (此时还未添加到页面)
|
|
||||||
container: function () {
|
|
||||||
var div = document.createElement('div');
|
|
||||||
div.setAttribute('style', '' +
|
|
||||||
'display:none!important;' +
|
|
||||||
'position:absolute!important;' +
|
|
||||||
'font-size:13px!important;' +
|
|
||||||
'overflow:auto!important;' +
|
|
||||||
'background:#fefee6!important;' +
|
|
||||||
'font-family:Arial,sans-serif!important;' +
|
|
||||||
'font-weight:normal!important;' +
|
|
||||||
'text-align:left!important;' +
|
|
||||||
'color:#000!important;' +
|
|
||||||
'padding:0.5em 1em!important;' +
|
|
||||||
'line-height:1.5em!important;' +
|
|
||||||
'border-radius:5px!important;' +
|
|
||||||
'border:1px solid #ccc!important;' +
|
|
||||||
'max-width:250px!important;' +
|
|
||||||
'max-height:150px!important;' +
|
|
||||||
'z-index:2147483647!important;' +
|
|
||||||
'');
|
|
||||||
return div;
|
|
||||||
}
|
|
||||||
};// 翻译server结束
|
|
||||||
})();
|
|
Binary file not shown.
BIN
translate/translate-bundle.jpg
Normal file
BIN
translate/translate-bundle.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 177 KiB |
Binary file not shown.
Before Width: | Height: | Size: 166 KiB |
BIN
translate/translate-dictionary.jpg
Normal file
BIN
translate/translate-dictionary.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 162 KiB |
|
@ -1,8 +1,8 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name 划词翻译:有道词典,金山词霸,谷歌翻译
|
// @name 划词翻译:多词典查询
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 1.5
|
// @version 1.6
|
||||||
// @description 划词翻译调用“有道词典(有道翻译)、金山词霸、谷歌翻译”
|
// @description 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、沪江小D、谷歌翻译”
|
||||||
// @author https://github.com/barrer
|
// @author https://github.com/barrer
|
||||||
// @match http://*/*
|
// @match http://*/*
|
||||||
// @include https://*/*
|
// @include https://*/*
|
||||||
|
@ -11,6 +11,10 @@
|
||||||
// @connect dict.youdao.com
|
// @connect dict.youdao.com
|
||||||
// @connect open.iciba.com
|
// @connect open.iciba.com
|
||||||
// @connect translate.google.cn
|
// @connect translate.google.cn
|
||||||
|
// @connect hjenglish.com
|
||||||
|
// @connect hjapi.com
|
||||||
|
// @connect hjfile.cn
|
||||||
|
// @connect cn.bing.com
|
||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
|
@ -25,6 +29,16 @@
|
||||||
word-wrap: break-word !important
|
word-wrap: break-word !important
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #36f;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -52,8 +66,8 @@
|
||||||
|
|
||||||
img[activate] {
|
img[activate] {
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
-webkit-box-shadow: 0px 0px 0px 1px #fc6;
|
-webkit-box-shadow: 0px 0px 0px 1px #f90;
|
||||||
box-shadow: 0px 0px 0px 1px #fc6;
|
box-shadow: 0px 0px 0px 1px #f90;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr-icon {
|
tr-icon {
|
||||||
|
@ -107,6 +121,34 @@
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.audio-button{
|
||||||
|
color: #36f;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.audio-button:last-of-type {
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.audio-button:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.br {
|
||||||
|
border-top: 1px dashed #777;
|
||||||
|
margin: .5em auto .3em auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-title~.list-title {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-title {
|
||||||
|
color: #00c;
|
||||||
|
}
|
||||||
|
|
||||||
.google .sentences,
|
.google .sentences,
|
||||||
.google .trans,
|
.google .trans,
|
||||||
.google .orig,
|
.google .orig,
|
||||||
|
@ -192,6 +234,141 @@
|
||||||
.none {
|
.none {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hjenglish dl,
|
||||||
|
.hjenglish dt,
|
||||||
|
.hjenglish dd,
|
||||||
|
.hjenglish p,
|
||||||
|
.hjenglish ul,
|
||||||
|
.hjenglish li,
|
||||||
|
.hjenglish h3 {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
margin-block-start: 0px;
|
||||||
|
margin-block-end: 0px;
|
||||||
|
margin-inline-start: 0px;
|
||||||
|
margin-inline-end: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hjenglish h3 {
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hjenglish .detail-pron,
|
||||||
|
.hjenglish .pronounces {
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hjenglish ul {
|
||||||
|
margin-left: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*例句*/
|
||||||
|
.hjenglish .def-sentence-from,
|
||||||
|
.hjenglish .def-sentence-to {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hjenglish .detail-groups dd h3:before {
|
||||||
|
counter-increment: eq;
|
||||||
|
content: counter(eq) ".";
|
||||||
|
display: block;
|
||||||
|
width: 22px;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hjenglish .detail-groups dl {
|
||||||
|
counter-reset: eq;
|
||||||
|
margin-bottom: .5em;
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hjenglish ol,
|
||||||
|
.hjenglish ul {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing h1,
|
||||||
|
.bing strong {
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: normal;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .concise ul {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .concise .pos {
|
||||||
|
margin-right: .2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .concise .web {
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .concise .web:after {
|
||||||
|
content: ":"
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .oald {
|
||||||
|
margin-top: .4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .hd_tf_lh div {
|
||||||
|
display: inline;
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing #authid td:first-child {
|
||||||
|
width: 22px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .def_row {
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .bil_dis,
|
||||||
|
.bing .val_dis {
|
||||||
|
padding-right: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*例句*/
|
||||||
|
.bing .li_exs {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .li_id {
|
||||||
|
border: 1px solid #ebebeb;
|
||||||
|
padding: .2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .infor,
|
||||||
|
.bing .sen_com,
|
||||||
|
.bing .com_sep,
|
||||||
|
.bing .bil,
|
||||||
|
.bing .gra {
|
||||||
|
padding-right: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .infor,
|
||||||
|
.bing .label {
|
||||||
|
padding-left: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .each_seg+.each_seg {
|
||||||
|
margin-top: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bing .de_co div {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
var link = document.createElement('link');
|
var link = document.createElement('link');
|
||||||
link.rel = 'stylesheet';
|
link.rel = 'stylesheet';
|
||||||
|
@ -199,61 +376,122 @@
|
||||||
link.href = URL.createObjectURL(new Blob([style.textContent], {
|
link.href = URL.createObjectURL(new Blob([style.textContent], {
|
||||||
type: 'text/css;charset=UTF-8'
|
type: 'text/css;charset=UTF-8'
|
||||||
}));
|
}));
|
||||||
|
// 翻译图标、内容面板、当前选中文本、当前翻译引擎
|
||||||
|
var icon = document.createElement('tr-icon'),
|
||||||
|
content = document.createElement('tr-content'),
|
||||||
|
selected,
|
||||||
|
engineId;
|
||||||
|
// 发音引擎
|
||||||
|
var audioEngines = []; // [{name: 'abc', url: 'http://*.mp3', ...}, ...]
|
||||||
|
// 翻译引擎结果集
|
||||||
|
var engineResult = {}; // id: DOM
|
||||||
|
// ID 类别
|
||||||
|
var ids = {
|
||||||
|
ICIBA: 'iciba',
|
||||||
|
ICIBA_LOWER_CASE: 'icibaLowerCase',
|
||||||
|
YOUDAO: 'youdao',
|
||||||
|
YOUDAO_LOWER_CASE: 'youdaoLowerCase',
|
||||||
|
BING: 'bing',
|
||||||
|
BING_LOWER_CASE: 'bingLowerCase',
|
||||||
|
HJENGLISH: 'hjenglish',
|
||||||
|
GOOGLE: 'google'
|
||||||
|
};
|
||||||
|
var idsExtension = {
|
||||||
|
LIST_DICT: [ids.ICIBA, ids.YOUDAO, ids.BING, ids.HJENGLISH],
|
||||||
|
LIST_DICT_LOWER_CASE: [ids.ICIBA, ids.ICIBA_LOWER_CASE, ids.YOUDAO, ids.YOUDAO_LOWER_CASE, ids.BING, ids.BING_LOWER_CASE, ids.HJENGLISH],
|
||||||
|
LIST_GOOGLE: [ids.GOOGLE],
|
||||||
|
lowerCaseMap: (function () {
|
||||||
|
var obj = {};
|
||||||
|
obj[ids.ICIBA_LOWER_CASE] = ids.ICIBA;
|
||||||
|
obj[ids.YOUDAO_LOWER_CASE] = ids.YOUDAO;
|
||||||
|
obj[ids.BING_LOWER_CASE] = ids.BING;
|
||||||
|
return obj;
|
||||||
|
})(),
|
||||||
|
names: (function () {
|
||||||
|
var obj = {};
|
||||||
|
obj[ids.ICIBA] = '《金山词霸》';
|
||||||
|
obj[ids.ICIBA_LOWER_CASE] = '';
|
||||||
|
obj[ids.YOUDAO] = '《有道词典》';
|
||||||
|
obj[ids.YOUDAO_LOWER_CASE] = '';
|
||||||
|
obj[ids.BING] = '《Bing 词典》';
|
||||||
|
obj[ids.BING_LOWER_CASE] = '';
|
||||||
|
obj[ids.HJENGLISH] = '《沪江小D》';
|
||||||
|
obj[ids.GOOGLE] = '';
|
||||||
|
return obj;
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
// 绑定图标拖动事件
|
||||||
|
var iconDrag = new Drag(icon);
|
||||||
// 图标数组
|
// 图标数组
|
||||||
var iconArray = [{
|
var iconArray = [{
|
||||||
name: '金山词霸',
|
name: '多词典查询',
|
||||||
id: 'iciba',
|
id: 'icon-dict',
|
||||||
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAABgFBMVEX////1AUv2DlT1A0z5ZpP2EVb/+fv2JGT1DFP+7/T//f7+4uv/9vn2HV/+6/H+5u32Gl3//P34ToH1CVH3LGn91eH8q8T4VYb2FVn6hqr/+/z5Y5D8p8H3Pnb4RHr4QXj3MW3+6e/5aZT1B0/3PXX6fqP5c5v7o776g6f4TID7n7v3KWf6iaz7lrX7jK78rMT9ztz2GFv9yNj1BE3+8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EhALahFhnpGCHaRqGaWRcKPOUQNK2bZLEPv8NxL8moA2EZ1P/McT7ScxPCHw7Cght8BUBiK/4tPGBB6DvERrErJ8RiBNYf4z8J2kNBhcFtHWSQVA0MSH8/OVsYso9IxDnvgOqLNn4JIDBJQG//hF+ceDSWOecb0YpjXlKoOreKKWkznwW0i3F5wW0dppB/IOwfvtZY6wFBwM8I0BJ0xDaEW+QwFf4vIB1HPI/ydkZ/Y4xTws0EAk3XdlCETJCzwpAAeQBuk/MLoj7tACwpcS3ZFpeELDWJ4BpH39xAUxIFYdXkkAAOtDvOj/6VhHINz/P4/NN6OQAHahmY9YQ6Lap74HmbAmgAgIEmHF6eYGmoV2V/DoOzwsYaIGeW7uwQPfzTkiLBIXHYSigGQiIpQXyLd6WdZElyLfgW3NewGmGFhbYb9AmSdO0bX34OC18AS4IjMsJhKchiLR56dd/QWDxEtAiy/aw/DbdZ3lRvgXxj5sQBBC3i+0C2PtvlOCyLrewCbo/CN4F4H3EgkH47DasvgVpCKG/IKTBeBdStt8G0eznwCSfGkRZUORPdsfgIon4p4D+dRY9N4rbcnc7uIp9BoImGJUz+mGBOL9DoE6j7wL+MPCz0D2egSgpbo5f5vE3AaiBYRt/HlpnHxaI2mp74/rzJAoEjJMjAgOurP2lAB/1nQJRkhd1ia9UH4bzfhMFAlCEWUwIGIVU8AOtlBTC2PsEQCHNqytkbRJ5jq/l3gA4MC4E52xCh+BaviihgM+BHHv0lUHOf6GA7wMtxuHDoR9G6cxfKAC4WUs+HqZpOoyMSy+1nsC5h+ezs0oqO8/wiTFrChykNsdo/XMHHj1DovniAoMwd6DGxQUQ1OBmtByiFVKg/s4EAJO80UArHq3CwJXWV6NrJcdoJfqRC6kuIwUbon8gL168ePHixYs/AQllYQQ4I2UrAAAAAElFTkSuQmCC',
|
||||||
trigger: function (text) {
|
trigger: function (text) {
|
||||||
ajax('http://open.iciba.com/huaci_v3/dict.php?word=' + text, function (rst) {
|
var idsType = idsExtension.LIST_DICT;
|
||||||
var html = parseIciba(rst);
|
if (text != text.toLowerCase()) {
|
||||||
if (text.toLowerCase() != text) { // 再次翻译一遍小写的
|
idsType = idsExtension.LIST_DICT_LOWER_CASE;
|
||||||
ajax('http://open.iciba.com/huaci_v3/dict.php?word=' + text.toLowerCase(), function (rst) {
|
}
|
||||||
var reHtml = parseIciba(rst);
|
ajax('http://open.iciba.com/huaci_v3/dict.php?word=' + encodeURIComponent(text), function (rst) {
|
||||||
if (html !== reHtml) {
|
engineResult[ids.ICIBA] = parseIciba(rst);
|
||||||
log(html, reHtml);
|
showContent(idsType);
|
||||||
html += '<hr>' + reHtml;
|
|
||||||
}
|
|
||||||
showContent(html);
|
|
||||||
}, function (rst) {
|
|
||||||
showContent(html + '<hr>' + 'error: 无法连接翻译服务');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
showContent(html);
|
|
||||||
}
|
|
||||||
}, function (rst) {
|
}, function (rst) {
|
||||||
showContent('error: 无法连接翻译服务');
|
engineResult[ids.ICIBA] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsType);
|
||||||
});
|
});
|
||||||
}
|
ajax('http://dict.youdao.com/jsonapi?xmlVersion=5.1&jsonversion=2&q=' + encodeURIComponent(text), function (rst) {
|
||||||
}, {
|
engineResult[ids.YOUDAO] = parseYoudao(rst);
|
||||||
name: '有道词典',
|
showContent(idsType);
|
||||||
id: 'youdao',
|
|
||||||
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAABgFBMVEX////99PTpXV3ug4P74uL1uLjfGBjfFhbjMDDuhobpYmLfFRXfFxfiLi785ubiKSniLCzvjIz75OTviYn+9/fjODj86ur1urr86Oj++vroVlbwjo73yMjgGxvkODjqaWn51tbhJCT3wsLwlJTqYGD97+/gHh74ysrxl5fqZmbkOjr51dXyoqL98vLlQUH3xsbzqKj62tr4zs73w8PzpqbsdHTpYGDmSEjlRUX++PjkPT3+9fX74OD63NzwkpLnVFTjMzPiJyfgHB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1oLtkorojEgZcPxi5b7BLNw/IvNGBGsgTUUtR3QHCvHgyUSAUoJl0wEyraMZRktySXLdB9aCUKefNoNltWTeX4r8BTrIyOko61JgsA5eknm6w7pWMuZNKWAT7GRaLCsXUTeVsjItwGWtkWnrgjU8p1Sad7jsCSbUGJnVGYV2UM1SWd7NYOnlKLL1ZNahwgVg8uMFVj7sK2AjaHOTSZ07XGh+lsy66087DC9xbS+TSQ2FtUXkJsiK2MXr0Xixc3/xmkxy7SB/FNg26yWrAp+GF3YdnqscAEjLmvLWcU2otnsJN1Vm6tnxxkJjzvZKVW/u07CfTPrQtrc3Gn008ri9g27LPb6SuFh/3deYnks/o6L+AbDOAQEKjE3tAAAAAElFTkSuQmCC',
|
|
||||||
trigger: function (text) {
|
|
||||||
ajax('http://dict.youdao.com/jsonapi?xmlVersion=5.1&jsonversion=2&q=' + text, function (rst) {
|
|
||||||
var html = parseYoudao(rst);
|
|
||||||
if (text.toLowerCase() != text) { // 再次翻译一遍小写的
|
|
||||||
ajax('http://dict.youdao.com/jsonapi?xmlVersion=5.1&jsonversion=2&q=' + text.toLowerCase(), function (rst) {
|
|
||||||
var reHtml = parseYoudao(rst);
|
|
||||||
if (html !== reHtml && reHtml.trim()) {
|
|
||||||
log(html, reHtml);
|
|
||||||
html += '<hr>' + reHtml;
|
|
||||||
}
|
|
||||||
showContent(html);
|
|
||||||
}, function (rst) {
|
|
||||||
showContent(html + '<hr>' + 'error: 无法连接翻译服务');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
showContent(html);
|
|
||||||
}
|
|
||||||
}, function (rst) {
|
}, function (rst) {
|
||||||
showContent('error: 无法连接翻译服务');
|
engineResult[ids.YOUDAO] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsType);
|
||||||
});
|
});
|
||||||
|
ajax('https://cn.bing.com/dict/search?q=' + encodeURIComponent(text), function (rst) {
|
||||||
|
engineResult[ids.BING] = parseBing(rst);
|
||||||
|
showContent(idsType);
|
||||||
|
}, function (rst) {
|
||||||
|
engineResult[ids.BING] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsType);
|
||||||
|
});
|
||||||
|
ajax('https://dict.hjenglish.com/w/' + encodeURIComponent(text), function (rst) {
|
||||||
|
engineResult[ids.HJENGLISH] = parseHjenglish(rst);
|
||||||
|
showContent(idsType);
|
||||||
|
}, function (rst) {
|
||||||
|
engineResult[ids.HJENGLISH] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsType);
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
'Cookie': 'HJ_SID=' + uuid() + '; HJ_SSID_3=' + uuid() + '; HJ_CST=1; HJ_CSST_3=1; HJ_UID=' + uuid()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (text != text.toLowerCase()) { // 小写再请求一次
|
||||||
|
ajax('http://open.iciba.com/huaci_v3/dict.php?word=' + encodeURIComponent(text.toLowerCase()), function (rst) {
|
||||||
|
engineResult[ids.ICIBA_LOWER_CASE] = parseIciba(rst);
|
||||||
|
showContent(idsType);
|
||||||
|
}, function (rst) {
|
||||||
|
engineResult[ids.ICIBA_LOWER_CASE] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsType);
|
||||||
|
});
|
||||||
|
ajax('http://dict.youdao.com/jsonapi?xmlVersion=5.1&jsonversion=2&q=' + encodeURIComponent(text.toLowerCase()), function (rst) {
|
||||||
|
engineResult[ids.YOUDAO_LOWER_CASE] = parseYoudao(rst);
|
||||||
|
showContent(idsType);
|
||||||
|
}, function (rst) {
|
||||||
|
engineResult[ids.YOUDAO_LOWER_CASE] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsType);
|
||||||
|
});
|
||||||
|
ajax('https://cn.bing.com/dict/search?q=' + encodeURIComponent(text.toLowerCase()), function (rst) {
|
||||||
|
engineResult[ids.BING_LOWER_CASE] = parseBing(rst);
|
||||||
|
showContent(idsType);
|
||||||
|
}, function (rst) {
|
||||||
|
engineResult[ids.BING_LOWER_CASE] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsType);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
name: '谷歌翻译',
|
name: '谷歌翻译',
|
||||||
id: 'google',
|
id: 'icon-google',
|
||||||
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAABgFBMVEX///9SkPVTkPVTkfVVkfVmnfZsofZroPaox/p0pvfA1/vN3/ximvadwPnQ4fzs8/6JtPi70/v9/v/V5P1fmPZalfV2p/dYlPVonvbY5v38/f/7/P/w9f5Xk/Wtyvr+/v/q8f6RuPn4+//2+f74+v/6/P/a5/3P4PyxzfqBrvigwvny9/7w9v6EsPipyPqGsvhdl/Z+rPenxvq0z/vH2/zC2PtWkvVgmfZhmvajxPqXvPmNtvh8q/dwo/fS4vxblvZ/rfhkm/bf6v3k7v30+P55qfeYvfnm7/7W5f1xpPeUuvluovf5+//o8P73+v9SkfXb6P250vvF2vzi7P240fu91fvu9P7d6f1zpffj7f2+1vvK3fzr8v53qPdel/ZwpPebv/m20Pvl7v3g6/2Mtfhcl/alxvqzzvuIsvhclvWPt/iwzPrE2fzD2fyvzPrn8P51pfdclva91PuxzvpalvXz+P7R4vzc6f1XlPWOtfhRj/V4p/e80/tRkPVvpPdUkvUyb8EpAAAAAXRSTlMAQObYZgAABkNJREFUeF7V24WO7DgaBeDzOylkZoZmZmZmZrqMw7j86qtpqe+oZ+2Uk0pytd8LnPNXyY5dpeD/0tl3L2+2Vrcd8dSTN4tOT+9ReT1Uh7VK0ZWY72hTJT7Vv/Zr+2W0BGtEs0uRd+EEaVOcxcP1XBSmy/YcrrkUksEutiLVBkzVqLldKslLbVZiVZhmZ8UdJ936M3smTV8u3pERyvRv3SbEn3/rYmSQ8jHTQEtyl8O8eHmJn3qyMK4WcTJqCSskjxowKHsTUKlljF6cRWFE3esgc1wEG9Cvp1ggk7D0uxB0Kh1MK2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Lz9egYIuXAxY0cHTFUDigXFNgIIeSqBBjoKITd8JQPhtSaYHLtN0l0D6NhOwOUcxjB6HDXnrVcymF/dXR32G0mk1A2wEhD9uuo4enzswHt6r2SQZkt5N9IlSVAcGmAhgIRX4+G0jx6/y+XqSDSNAu9OLvPiasSgEI2lhNcpthIQbah20VUJPM1g6pky6K+LpcxvGYx9/0o3ICJ29wGI9UW/RVOnYupA04mhqgqBwBaUS2gAsxOAKcB6z2+BwmPmSQAfWWRL1XhObtQpFGNieyNCTc/poxfvc00/n+glC7chGP/B3e4FZdZXMgQYflWi32mcRRCClLcF1JcQQGQtYCx1lDIcHEG2VMXhb0JwZHUpLYFatFew/BR6B1QtgJBD+aJQDSjSEateQF2f5om+EBUJrr4DKgNX1c9ztQaY9SIswf1G1S+kMojHYFCxQPt+q34quUt2BsxnUdUd+PkD6o/8gwH0oFqBNloViwEhdG8QUValACB+LTiJop3BUq+DigWa3TmUBIO7nUFEqhVASP/K7GAAhzPGFQoAqD+c6FrE1z24DchnBPr2Ah13wg4GhboVfaoDDXsB5EEGGkwWt3GK2WcEnLa1gThkADCMP7kNh1+wCNqHDADGPjkJe/YtQMJj5yV/UQlM+1+SQXmBUd3aQP+YWlIA6NU96xY0gtICwKjlfrgJbROdmccsBIBa3XW8D/Hzt4E/f4c2EWh6telHaK3/bZ/z79/qEuqXEShB999LVt3J+bgqAbZ5KeBC/coERs7z8lvnfDKuSgC4XD0TWJ/Px1UK0M32af0I6lcnALhPBDYB1K9WYLp6XD/lzO75AyVYP7RgdclxZPEMCttluOrOz9+pz/yvF6htDhsQBkBk/TyeEjj7DJzJ5L36DOp/WwZrNh+/A6Nn30FNj4J1MGHv1udn34ILLdgM36vP8ODsm8Dr7TqdYPYWmPgl8q+AEydOnDhx4sR/q8tILrvoB2AAAAAASUVORK5CYII=',
|
||||||
trigger: function (text) {
|
trigger: function (text) {
|
||||||
var url = 'https://translate.google.cn/translate_a/single?client=gtx&dt=t&dt=bd&dj=1&source=input&hl=zh-CN&sl=auto';
|
var url = 'https://translate.google.cn/translate_a/single?client=gtx&dt=t&dt=bd&dj=1&source=input&hl=zh-CN&sl=auto';
|
||||||
url += '&tk=' + token(text);
|
url += '&tk=' + token(text);
|
||||||
|
@ -262,20 +500,14 @@
|
||||||
else
|
else
|
||||||
url += '&tl=zh-CN&q=' + text;
|
url += '&tl=zh-CN&q=' + text;
|
||||||
ajax(url, function (rst) {
|
ajax(url, function (rst) {
|
||||||
var html = parseGoogle(rst);
|
engineResult[ids.GOOGLE] = parseGoogle(rst);
|
||||||
showContent(html);
|
showContent(idsExtension.LIST_GOOGLE);
|
||||||
}, function (rst) {
|
}, function (rst) {
|
||||||
showContent('error: 无法连接翻译服务');
|
engineResult[ids.GOOGLE] = htmlToDom('error: 无法连接翻译服务');
|
||||||
|
showContent(idsExtension.LIST_GOOGLE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
// 翻译图标、内容面板、当前选中文本、当前翻译引擎
|
|
||||||
var icon = document.createElement('tr-icon'),
|
|
||||||
content = document.createElement('tr-content'),
|
|
||||||
selected,
|
|
||||||
engineId;
|
|
||||||
// 绑定图标拖动事件
|
|
||||||
var iconDrag = new Drag(icon);
|
|
||||||
// 添加翻译引擎图标
|
// 添加翻译引擎图标
|
||||||
iconArray.forEach(function (obj) {
|
iconArray.forEach(function (obj) {
|
||||||
var img = document.createElement('img');
|
var img = document.createElement('img');
|
||||||
|
@ -285,8 +517,12 @@
|
||||||
img.setAttribute('icon-id', obj.id);
|
img.setAttribute('icon-id', obj.id);
|
||||||
img.addEventListener('mouseup', function () {
|
img.addEventListener('mouseup', function () {
|
||||||
if (!isDrag()) { // 没有拖动鼠标抬起的时候触发点击事件
|
if (!isDrag()) { // 没有拖动鼠标抬起的时候触发点击事件
|
||||||
|
if (engineId == obj.id)
|
||||||
|
return; // 已经是当前翻译引擎
|
||||||
engineId = obj.id; // 翻译引擎 ID
|
engineId = obj.id; // 翻译引擎 ID
|
||||||
engineActivateShow(); // 显示翻译引擎指示器
|
engineActivateShow(); // 显示翻译引擎指示器
|
||||||
|
audioEngines = []; // 清空发音引擎
|
||||||
|
engineResult = {}; // 清空翻译引擎结果集
|
||||||
obj.trigger(selected); // 启动翻译引擎
|
obj.trigger(selected); // 启动翻译引擎
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -332,27 +568,34 @@
|
||||||
icon.style.position = 'absolute';
|
icon.style.position = 'absolute';
|
||||||
icon.style.zIndex = '2147483647';
|
icon.style.zIndex = '2147483647';
|
||||||
} else if (!selected) { // 隐藏翻译图标
|
} else if (!selected) { // 隐藏翻译图标
|
||||||
log('hide icon');
|
log('hide icon:mouseup');
|
||||||
icon.style.display = 'none';
|
hideIcon();
|
||||||
content.style.display = 'none';
|
|
||||||
engineActivateHide();
|
|
||||||
forceStopDrag();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 选中变化事件:当点击已经选中的文本的时候,隐藏翻译图标(此时浏览器动作是:选中的文本已经取消选中了)
|
// 选中变化事件:当点击已经选中的文本的时候,隐藏翻译图标(此时浏览器动作是:选中的文本已经取消选中了)
|
||||||
document.addEventListener("selectionchange", function (e) {
|
document.addEventListener('selectionchange', function (e) {
|
||||||
log('selectionchange event:', e);
|
log('selectionchange event:', e);
|
||||||
log('selectionchange:' + window.getSelection().toString());
|
log('selectionchange:' + window.getSelection().toString());
|
||||||
if (!window.getSelection().toString().trim()) {
|
if (!window.getSelection().toString().trim()) {
|
||||||
icon.style.display = 'none';
|
log('hide icon:selectionchange');
|
||||||
content.style.display = 'none';
|
hideIcon();
|
||||||
engineActivateHide();
|
}
|
||||||
forceStopDrag();
|
});
|
||||||
|
// 内容面板滚动事件
|
||||||
|
content.addEventListener('scroll', function (e) {
|
||||||
|
if (content.scrollHeight - content.scrollTop === content.clientHeight) {
|
||||||
|
log('scroll bottom', e);
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
} else if (content.scrollTop === 0) {
|
||||||
|
log('scroll top', e);
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/**日志输出*/
|
/**日志输出*/
|
||||||
function log() {
|
function log() {
|
||||||
var debug = false;
|
var debug = true;
|
||||||
if (!debug)
|
if (!debug)
|
||||||
return;
|
return;
|
||||||
if (arguments) {
|
if (arguments) {
|
||||||
|
@ -429,6 +672,14 @@
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/**uuid*/
|
||||||
|
function uuid() {
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||||
|
var r = Math.random() * 16 | 0,
|
||||||
|
v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
/**对象转 xml*/
|
/**对象转 xml*/
|
||||||
function objToXml(obj) {
|
function objToXml(obj) {
|
||||||
var xml = '';
|
var xml = '';
|
||||||
|
@ -461,6 +712,20 @@
|
||||||
return xml.replace(/<([^/]+?)>/g, '<' + tag + ' class="$1">')
|
return xml.replace(/<([^/]+?)>/g, '<' + tag + ' class="$1">')
|
||||||
.replace(/<\/(.+?)>/g, '</' + tag + '>');
|
.replace(/<\/(.+?)>/g, '</' + tag + '>');
|
||||||
}
|
}
|
||||||
|
// html 字符串转 DOM
|
||||||
|
function htmlToDom(htmlStr) {
|
||||||
|
var div = document.createElement('div');
|
||||||
|
div.innerHTML = htmlStr;
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
/**清理 html*/
|
||||||
|
function cleanHtml(htmlStr) {
|
||||||
|
return htmlStr.replace(/<script[\s\S]*?<\/script>/ig, '')
|
||||||
|
.replace(/<link[\s\S]*?>/ig, '')
|
||||||
|
.replace(/<style[\s\S]*?<\/style>/ig, '')
|
||||||
|
.replace(/<img[\s\S]*?>/ig, '')
|
||||||
|
.replace(/on[a-z]*=".*?"/ig, '');
|
||||||
|
}
|
||||||
/**ajax 跨域访问公共方法*/
|
/**ajax 跨域访问公共方法*/
|
||||||
function ajax(url, success, error, obj) {
|
function ajax(url, success, error, obj) {
|
||||||
if (!!!obj)
|
if (!!!obj)
|
||||||
|
@ -470,7 +735,7 @@
|
||||||
// >>>因为Tampermonkey跨域访问(a.com)时会自动携带对应域名(a.com)的对应cookie
|
// >>>因为Tampermonkey跨域访问(a.com)时会自动携带对应域名(a.com)的对应cookie
|
||||||
// 不会携带当前域名的cookie
|
// 不会携带当前域名的cookie
|
||||||
// 所以,GM_xmlhttpRequest【不存在】cookie跨域访问安全性问题
|
// 所以,GM_xmlhttpRequest【不存在】cookie跨域访问安全性问题
|
||||||
// 以下设置默认headers不起作用<<<
|
// 以下设置的cookie会添加到已有cookie的后面<<<
|
||||||
if (!!!obj.headers)
|
if (!!!obj.headers)
|
||||||
obj.headers = {
|
obj.headers = {
|
||||||
'cookie': ''
|
'cookie': ''
|
||||||
|
@ -486,32 +751,81 @@
|
||||||
},
|
},
|
||||||
onerror: function (res) {
|
onerror: function (res) {
|
||||||
error(res.responseText, res, obj);
|
error(res.responseText, res, obj);
|
||||||
|
},
|
||||||
|
onabort: function (res) {
|
||||||
|
error('the request was aborted', res, obj);
|
||||||
|
},
|
||||||
|
ontimeout: function (res) {
|
||||||
|
error('the request failed due to a timeout', res, obj);
|
||||||
|
},
|
||||||
|
onreadystatechange: function () {
|
||||||
|
log('ajax:', arguments);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**翻译引擎结果集状态判断*/
|
||||||
|
function isAllDone(idsType) {
|
||||||
|
var rst = false;
|
||||||
|
idsType.forEach(function (id, i) {
|
||||||
|
if (i == 0)
|
||||||
|
rst = true;
|
||||||
|
if (!(id in engineResult)) {
|
||||||
|
log('isAllDone(not found):' + id);
|
||||||
|
rst = false;
|
||||||
|
return rst;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return rst;
|
||||||
|
}
|
||||||
/**显示内容面板*/
|
/**显示内容面板*/
|
||||||
function showContent(html) {
|
function showContent(idsType) {
|
||||||
|
log('showContent:', idsType, engineResult);
|
||||||
|
if (!isAllDone(idsType)) {
|
||||||
|
log('showContent return');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log('showContent rendering');
|
||||||
// 发音
|
// 发音
|
||||||
var audio = document.createElement('tr-audio'),
|
audioEngines.push({
|
||||||
us = document.createElement('a'),
|
name: '♪US',
|
||||||
uk = document.createElement('a');
|
url: 'http://dict.youdao.com/dictvoice?audio=' + selected + '&type=2'
|
||||||
|
});
|
||||||
us.innerHTML = '♪US';
|
audioEngines.push({
|
||||||
us.setAttribute('href', 'javascript:void(0)');
|
name: '♪UK',
|
||||||
us.addEventListener('mouseup', playUS);
|
url: 'http://dict.youdao.com/dictvoice?audio=' + selected + '&type=1'
|
||||||
// us.addEventListener('mouseover', playUS);
|
});
|
||||||
uk.innerHTML = '♪UK';
|
var audio = document.createElement('tr-audio');
|
||||||
uk.setAttribute('href', 'javascript:void(0)');
|
audioEngines.forEach(function (obj) {
|
||||||
uk.addEventListener('mouseup', playUK);
|
audio.appendChild(getPlayButton(obj));
|
||||||
// uk.addEventListener('mouseover', playUK);
|
});
|
||||||
audio.appendChild(us);
|
|
||||||
audio.appendChild(uk);
|
|
||||||
// 翻译内容
|
// 翻译内容
|
||||||
content.innerHTML = '<div class="' + engineId + '">' + html + '</div>';
|
content.innerHTML = '';
|
||||||
if (engineId != 'google') { // 谷歌翻译不显示发音图标
|
// 比较大小写内容
|
||||||
|
var needDel = {};
|
||||||
|
for (var key in idsExtension.lowerCaseMap) {
|
||||||
|
if (engineResult[key] &&
|
||||||
|
engineResult[idsExtension.lowerCaseMap[key]] &&
|
||||||
|
engineResult[key].innerHTML == engineResult[idsExtension.lowerCaseMap[key]].innerHTML) {
|
||||||
|
needDel[key] = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
idsType.forEach(function (id) {
|
||||||
|
if (!(id in needDel)) {
|
||||||
|
if (idsExtension.names[id]) {
|
||||||
|
var title = document.createElement('div');
|
||||||
|
title.innerHTML = idsExtension.names[id];
|
||||||
|
title.setAttribute('class', 'list-title');
|
||||||
|
content.appendChild(title);
|
||||||
|
}
|
||||||
|
content.appendChild(engineResult[id]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (engineId != 'icon-google') { // 谷歌翻译不显示发音图标
|
||||||
content.insertBefore(audio, content.childNodes[0]);
|
content.insertBefore(audio, content.childNodes[0]);
|
||||||
}
|
}
|
||||||
content.style.display = 'block';
|
content.style.display = 'block';
|
||||||
|
content.scrollTop = 0;
|
||||||
|
content.scrollLeft = 0;
|
||||||
}
|
}
|
||||||
/**隐藏翻译引擎指示器*/
|
/**隐藏翻译引擎指示器*/
|
||||||
function engineActivateHide() {
|
function engineActivateHide() {
|
||||||
|
@ -524,14 +838,23 @@
|
||||||
engineActivateHide();
|
engineActivateHide();
|
||||||
icon.querySelector('img[icon-id="' + engineId + '"').setAttribute('activate', 'activate');
|
icon.querySelector('img[icon-id="' + engineId + '"').setAttribute('activate', 'activate');
|
||||||
}
|
}
|
||||||
/**美式发音*/
|
/**隐藏 icon*/
|
||||||
function playUS() {
|
function hideIcon() {
|
||||||
|
icon.style.display = 'none';
|
||||||
|
content.style.display = 'none';
|
||||||
|
engineId = '';
|
||||||
|
audioEngines = [];
|
||||||
|
engineResult = {};
|
||||||
|
engineActivateHide();
|
||||||
|
forceStopDrag();
|
||||||
|
}
|
||||||
|
/**发音*/
|
||||||
|
function play(obj) {
|
||||||
if (isDrag()) { // 拖动时候不触发发音
|
if (isDrag()) { // 拖动时候不触发发音
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var url = 'http://dict.youdao.com/dictvoice?audio=' + selected + '&type=2';
|
|
||||||
var audio = new Audio();
|
var audio = new Audio();
|
||||||
ajax(url, function (rst, res) {
|
ajax(obj.url, function (rst, res) {
|
||||||
audio.src = URL.createObjectURL(res.response);
|
audio.src = URL.createObjectURL(res.response);
|
||||||
audio.play();
|
audio.play();
|
||||||
}, function (rst) {
|
}, function (rst) {
|
||||||
|
@ -540,28 +863,22 @@
|
||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**英式发音*/
|
/**得到发音按钮*/
|
||||||
function playUK() {
|
function getPlayButton(obj) {
|
||||||
if (isDrag()) { // 拖动时候不触发发音
|
var type = document.createElement('a');
|
||||||
return;
|
type.innerHTML = obj.name;
|
||||||
}
|
type.setAttribute('href', 'javascript:void(0)');
|
||||||
var url = 'http://dict.youdao.com/dictvoice?audio=' + selected + '&type=1';
|
type.setAttribute('class', 'audio-button');
|
||||||
var audio = new Audio();
|
type.addEventListener('mouseup', function () {
|
||||||
ajax(url, function (rst, res) {
|
play(obj);
|
||||||
audio.src = URL.createObjectURL(res.response);
|
|
||||||
audio.play();
|
|
||||||
}, function (rst) {
|
|
||||||
log(rst);
|
|
||||||
}, {
|
|
||||||
responseType: 'blob'
|
|
||||||
});
|
});
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
/**有道词典排版*/
|
/**有道词典排版*/
|
||||||
function parseYoudao(rst) {
|
function parseYoudao(rst) {
|
||||||
|
var html = '';
|
||||||
try {
|
try {
|
||||||
// if (true) return xmlToHtml(objToXml(JSON.parse(rst)), 'span');
|
|
||||||
var rstJson = JSON.parse(rst),
|
var rstJson = JSON.parse(rst),
|
||||||
html = '',
|
|
||||||
phoneStyle = 'color:#777;';
|
phoneStyle = 'color:#777;';
|
||||||
if (rstJson.ec) {
|
if (rstJson.ec) {
|
||||||
var word = rstJson.ec.word[0],
|
var word = rstJson.ec.word[0],
|
||||||
|
@ -606,14 +923,18 @@
|
||||||
if (rstJson.fanyi && rstJson.fanyi.tran) {
|
if (rstJson.fanyi && rstJson.fanyi.tran) {
|
||||||
html += rstJson.fanyi.tran;
|
html += rstJson.fanyi.tran;
|
||||||
}
|
}
|
||||||
return html;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(error);
|
log(error);
|
||||||
return error;
|
html += error;
|
||||||
}
|
}
|
||||||
|
var dom = document.createElement('div');
|
||||||
|
dom.setAttribute('class', ids.YOUDAO);
|
||||||
|
dom.innerHTML = html;
|
||||||
|
return dom;
|
||||||
}
|
}
|
||||||
/**金山词霸排版*/
|
/**金山词霸排版*/
|
||||||
function parseIciba(rst) {
|
function parseIciba(rst) {
|
||||||
|
var html = '';
|
||||||
try {
|
try {
|
||||||
rst = rst.replace(/class=\\"icIBahyI-prons\\"/g, '__mystyle__') // 音标
|
rst = rst.replace(/class=\\"icIBahyI-prons\\"/g, '__mystyle__') // 音标
|
||||||
.replace(/\\"/g, '"') // 引号
|
.replace(/\\"/g, '"') // 引号
|
||||||
|
@ -630,20 +951,105 @@
|
||||||
// 音标
|
// 音标
|
||||||
.replace(/__mystyle__/g, ' style="color:#777;"');
|
.replace(/__mystyle__/g, ' style="color:#777;"');
|
||||||
var match = /dict.innerHTML='(.*)?';/g.exec(rst);
|
var match = /dict.innerHTML='(.*)?';/g.exec(rst);
|
||||||
return match[1];
|
html += match[1];
|
||||||
|
if (html.indexOf('去爱词霸官网翻译') != -1)
|
||||||
|
html = '';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(error);
|
log(error);
|
||||||
return error;
|
html += error;
|
||||||
}
|
}
|
||||||
|
var dom = document.createElement('div');
|
||||||
|
dom.setAttribute('class', ids.ICIBA);
|
||||||
|
dom.innerHTML = html;
|
||||||
|
return dom;
|
||||||
|
}
|
||||||
|
/**沪江小D排版*/
|
||||||
|
function parseHjenglish(rst) {
|
||||||
|
var dom = document.createElement('div');
|
||||||
|
dom.setAttribute('class', ids.HJENGLISH);
|
||||||
|
try {
|
||||||
|
var doc = htmlToDom(cleanHtml(rst));
|
||||||
|
var entry = doc.querySelector('.word-text h2');
|
||||||
|
var pronounces = doc.querySelector('.pronounces');
|
||||||
|
var collins = doc.querySelector('div[data-id="detail"] .word-details-item-content .detail-groups');
|
||||||
|
if (entry) {
|
||||||
|
var entryDom = document.createElement('div');
|
||||||
|
entryDom.setAttribute('class', 'entry');
|
||||||
|
entryDom.innerHTML = entry.innerHTML;
|
||||||
|
dom.appendChild(entryDom);
|
||||||
|
if (pronounces) {
|
||||||
|
var pronounceDom = document.createElement('div');
|
||||||
|
pronounces.querySelectorAll('.pronounces [class="word-audio"]').forEach(function (ele) {
|
||||||
|
pronounceDom.appendChild(getPlayButton({
|
||||||
|
name: '♪US',
|
||||||
|
url: ele.getAttribute('data-src')
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
pronounces.querySelectorAll('.pronounces [class="word-audio word-audio-en"]').forEach(function (ele) {
|
||||||
|
pronounceDom.appendChild(getPlayButton({
|
||||||
|
name: '♪UK',
|
||||||
|
url: ele.getAttribute('data-src')
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
dom.appendChild(pronounceDom);
|
||||||
|
dom.appendChild(pronounces);
|
||||||
|
}
|
||||||
|
if (collins) {
|
||||||
|
dom.appendChild(htmlToDom('<div>《权威词典》</div>'));
|
||||||
|
dom.appendChild(collins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log(error);
|
||||||
|
dom.appendChild(htmlToDom(error));
|
||||||
|
}
|
||||||
|
return dom;
|
||||||
|
}
|
||||||
|
/**必应词典排版*/
|
||||||
|
function parseBing(rst) {
|
||||||
|
var html = '';
|
||||||
|
try {
|
||||||
|
rst = cleanHtml(rst).replace(/(?:a>)/ig, 'span>')
|
||||||
|
.replace(/(?:<a)/ig, '<span');
|
||||||
|
var doc = htmlToDom(rst);
|
||||||
|
doc.querySelectorAll('.hw_ti').forEach(function (ele) { // 牛津词头(不准)
|
||||||
|
ele.remove();
|
||||||
|
});
|
||||||
|
var entry = doc.querySelector('.qdef .hd_area');
|
||||||
|
var concise = doc.querySelector('.qdef ul');
|
||||||
|
var tense = doc.querySelector('.qdef .hd_div1');
|
||||||
|
var oald = doc.querySelector('#authid');
|
||||||
|
if (entry) {
|
||||||
|
html += '<div class="entry">' + entry.innerHTML + '</div>';
|
||||||
|
if (concise)
|
||||||
|
html += '<div class="concise">' + concise.outerHTML + '</div>';
|
||||||
|
if (tense)
|
||||||
|
html += '<div class="tense">' + tense.outerHTML + '</div>';
|
||||||
|
if (oald)
|
||||||
|
html += '<div class="oald">《牛津高阶英汉双解词典第八版》<br>' + oald.outerHTML + '</div>';
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log(error);
|
||||||
|
html += error;
|
||||||
|
}
|
||||||
|
var dom = document.createElement('div');
|
||||||
|
dom.setAttribute('class', ids.BING);
|
||||||
|
dom.innerHTML = html;
|
||||||
|
return dom;
|
||||||
}
|
}
|
||||||
/**谷歌翻译排版*/
|
/**谷歌翻译排版*/
|
||||||
function parseGoogle(rst) {
|
function parseGoogle(rst) {
|
||||||
|
var dom = document.createElement('div');
|
||||||
|
dom.setAttribute('class', ids.GOOGLE);
|
||||||
try {
|
try {
|
||||||
return xmlToHtml(objToXml(JSON.parse(rst)), 'span');
|
// 发音
|
||||||
|
// 内容
|
||||||
|
dom.appendChild(htmlToDom(xmlToHtml(objToXml(JSON.parse(rst)), 'span')));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(error);
|
log(error);
|
||||||
return error;
|
dom.appendChild(htmlToDom(error));
|
||||||
}
|
}
|
||||||
|
return dom;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 谷歌翻译 token 计算
|
* 谷歌翻译 token 计算
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 158 KiB |
BIN
translate/translate.jpg
Normal file
BIN
translate/translate.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 179 KiB |
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 152 KiB |
Loading…
Reference in New Issue
Block a user