移除必应大小写翻译
This commit is contained in:
parent
b48debd84c
commit
5ecd5befb8
|
@ -1,7 +1,7 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name 划词翻译:多词典查询
|
// @name 划词翻译:多词典查询
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 3.9
|
// @version 4.0
|
||||||
// @description 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、剑桥高阶、沪江小D、谷歌翻译”
|
// @description 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、剑桥高阶、沪江小D、谷歌翻译”
|
||||||
// @author https://github.com/barrer
|
// @author https://github.com/barrer
|
||||||
// @match http://*/*
|
// @match http://*/*
|
||||||
|
@ -131,29 +131,31 @@
|
||||||
var audioCache = {}; // {'mp3 download url': blob}
|
var audioCache = {}; // {'mp3 download url': blob}
|
||||||
// 翻译引擎结果集
|
// 翻译引擎结果集
|
||||||
var engineResult = {}; // id: DOM
|
var engineResult = {}; // id: DOM
|
||||||
// ID 类别
|
// 唯一 ID
|
||||||
var ids = {
|
var ids = {
|
||||||
ICIBA: 'iciba',
|
ICIBA: 'iciba',
|
||||||
ICIBA_LOWER_CASE: 'icibaLowerCase',
|
ICIBA_LOWER_CASE: 'icibaLowerCase',
|
||||||
YOUDAO: 'youdao',
|
YOUDAO: 'youdao',
|
||||||
YOUDAO_LOWER_CASE: 'youdaoLowerCase',
|
YOUDAO_LOWER_CASE: 'youdaoLowerCase',
|
||||||
BING: 'bing',
|
BING: 'bing',
|
||||||
BING_LOWER_CASE: 'bingLowerCase',
|
|
||||||
HJENGLISH: 'hjenglish',
|
HJENGLISH: 'hjenglish',
|
||||||
GOOGLE: 'google',
|
GOOGLE: 'google',
|
||||||
CAMBRIDGE: 'cambridge'
|
CAMBRIDGE: 'cambridge'
|
||||||
};
|
};
|
||||||
|
// 唯一 ID 扩展
|
||||||
var idsExtension = {
|
var idsExtension = {
|
||||||
|
// ID 组
|
||||||
LIST_DICT: [ids.ICIBA, ids.YOUDAO, ids.BING, ids.HJENGLISH, ids.CAMBRIDGE],
|
LIST_DICT: [ids.ICIBA, ids.YOUDAO, ids.BING, ids.HJENGLISH, ids.CAMBRIDGE],
|
||||||
LIST_DICT_LOWER_CASE: [ids.ICIBA, ids.ICIBA_LOWER_CASE, ids.YOUDAO, ids.YOUDAO_LOWER_CASE, ids.BING, ids.BING_LOWER_CASE, ids.HJENGLISH, ids.CAMBRIDGE],
|
LIST_DICT_LOWER_CASE: [ids.ICIBA, ids.ICIBA_LOWER_CASE, ids.YOUDAO, ids.YOUDAO_LOWER_CASE, ids.BING, ids.HJENGLISH, ids.CAMBRIDGE],
|
||||||
LIST_GOOGLE: [ids.GOOGLE],
|
LIST_GOOGLE: [ids.GOOGLE],
|
||||||
|
// 去重比对(大小写翻译可能一样)
|
||||||
lowerCaseMap: (function () {
|
lowerCaseMap: (function () {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[ids.ICIBA_LOWER_CASE] = ids.ICIBA;
|
obj[ids.ICIBA_LOWER_CASE] = ids.ICIBA;
|
||||||
obj[ids.YOUDAO_LOWER_CASE] = ids.YOUDAO;
|
obj[ids.YOUDAO_LOWER_CASE] = ids.YOUDAO;
|
||||||
obj[ids.BING_LOWER_CASE] = ids.BING;
|
|
||||||
return obj;
|
return obj;
|
||||||
})(),
|
})(),
|
||||||
|
// 标题
|
||||||
names: (function () {
|
names: (function () {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[ids.ICIBA] = '《金山词霸》';
|
obj[ids.ICIBA] = '《金山词霸》';
|
||||||
|
@ -161,12 +163,12 @@
|
||||||
obj[ids.YOUDAO] = '《有道词典》';
|
obj[ids.YOUDAO] = '《有道词典》';
|
||||||
obj[ids.YOUDAO_LOWER_CASE] = '';
|
obj[ids.YOUDAO_LOWER_CASE] = '';
|
||||||
obj[ids.BING] = '《Bing 词典》';
|
obj[ids.BING] = '《Bing 词典》';
|
||||||
obj[ids.BING_LOWER_CASE] = '';
|
|
||||||
obj[ids.HJENGLISH] = '《沪江小D》';
|
obj[ids.HJENGLISH] = '《沪江小D》';
|
||||||
obj[ids.GOOGLE] = '《谷歌翻译》';
|
obj[ids.GOOGLE] = '《谷歌翻译》';
|
||||||
obj[ids.CAMBRIDGE] = '《剑桥高阶》';
|
obj[ids.CAMBRIDGE] = '《剑桥高阶》';
|
||||||
return obj;
|
return obj;
|
||||||
})(),
|
})(),
|
||||||
|
// 跳转到网站(“%q%”占位符或者 function text -> return URL)
|
||||||
links: (function () {
|
links: (function () {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[ids.ICIBA] = 'http://www.iciba.com/%q%';
|
obj[ids.ICIBA] = 'http://www.iciba.com/%q%';
|
||||||
|
@ -174,7 +176,6 @@
|
||||||
obj[ids.YOUDAO] = 'https://dict.youdao.com/w/eng/%q%';
|
obj[ids.YOUDAO] = 'https://dict.youdao.com/w/eng/%q%';
|
||||||
obj[ids.YOUDAO_LOWER_CASE] = '';
|
obj[ids.YOUDAO_LOWER_CASE] = '';
|
||||||
obj[ids.BING] = 'https://cn.bing.com/dict/search?q=%q%';
|
obj[ids.BING] = 'https://cn.bing.com/dict/search?q=%q%';
|
||||||
obj[ids.BING_LOWER_CASE] = '';
|
|
||||||
obj[ids.HJENGLISH] = 'https://dict.hjenglish.com/w/%q%';
|
obj[ids.HJENGLISH] = 'https://dict.hjenglish.com/w/%q%';
|
||||||
obj[ids.GOOGLE] = function (text) {
|
obj[ids.GOOGLE] = function (text) {
|
||||||
var rst = '';
|
var rst = '';
|
||||||
|
@ -188,6 +189,7 @@
|
||||||
obj[ids.CAMBRIDGE] = 'https://dictionary.cambridge.org/dictionary/english-chinese-simplified/%q%';
|
obj[ids.CAMBRIDGE] = 'https://dictionary.cambridge.org/dictionary/english-chinese-simplified/%q%';
|
||||||
return obj;
|
return obj;
|
||||||
})(),
|
})(),
|
||||||
|
// 翻译引擎
|
||||||
engines: (function () {
|
engines: (function () {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[ids.ICIBA] = function (text, time) {
|
obj[ids.ICIBA] = function (text, time) {
|
||||||
|
@ -235,15 +237,6 @@
|
||||||
showContent();
|
showContent();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
obj[ids.BING_LOWER_CASE] = function (text, time) {
|
|
||||||
ajax('https://cn.bing.com/dict/search?q=' + encodeURIComponent(text.toLowerCase()), function (rst) {
|
|
||||||
putEngineResult(ids.BING_LOWER_CASE, parseBing(rst), time);
|
|
||||||
showContent();
|
|
||||||
}, function (rst) {
|
|
||||||
putEngineResult(ids.BING_LOWER_CASE, htmlToDom('error: 无法连接翻译服务'), time);
|
|
||||||
showContent();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
obj[ids.HJENGLISH] = function (text, time) {
|
obj[ids.HJENGLISH] = function (text, time) {
|
||||||
ajax('https://dict.hjenglish.com/w/' + encodeURIComponent(text), function (rst) {
|
ajax('https://dict.hjenglish.com/w/' + encodeURIComponent(text), function (rst) {
|
||||||
putEngineResult(ids.HJENGLISH, parseHjenglish(rst), time);
|
putEngineResult(ids.HJENGLISH, parseHjenglish(rst), time);
|
||||||
|
@ -296,7 +289,7 @@
|
||||||
trigger: function (text, time) {
|
trigger: function (text, time) {
|
||||||
idsType = idsExtension.LIST_DICT;
|
idsType = idsExtension.LIST_DICT;
|
||||||
if (text != text.toLowerCase()) {
|
if (text != text.toLowerCase()) {
|
||||||
idsType = idsExtension.LIST_DICT_LOWER_CASE; // 大小写各请求一次
|
idsType = idsExtension.LIST_DICT_LOWER_CASE; // 改为大小写 ID 组(大小写各请求一次)
|
||||||
}
|
}
|
||||||
idsType.forEach(function (id) {
|
idsType.forEach(function (id) {
|
||||||
idsExtension.engines[id](text, time);
|
idsExtension.engines[id](text, time);
|
||||||
|
@ -322,8 +315,8 @@
|
||||||
img.setAttribute('icon-id', obj.id);
|
img.setAttribute('icon-id', obj.id);
|
||||||
img.addEventListener('mouseup', function () {
|
img.addEventListener('mouseup', function () {
|
||||||
if (engineId == obj.id) {
|
if (engineId == obj.id) {
|
||||||
return; // 已经是当前翻译引擎
|
// 已经是当前翻译引擎,不做任何处理
|
||||||
}
|
} else {
|
||||||
icon.setAttribute('activate', 'activate'); // 标注面板展开
|
icon.setAttribute('activate', 'activate'); // 标注面板展开
|
||||||
contentList.innerHTML = ''; // 清空翻译内容列表
|
contentList.innerHTML = ''; // 清空翻译内容列表
|
||||||
displayContent(); // 立马显示翻译面板
|
displayContent(); // 立马显示翻译面板
|
||||||
|
@ -336,6 +329,7 @@
|
||||||
audioCache = {}; // 清空发音缓存
|
audioCache = {}; // 清空发音缓存
|
||||||
engineResult = {}; // 清空翻译引擎结果集
|
engineResult = {}; // 清空翻译引擎结果集
|
||||||
obj.trigger(selected, engineTriggerTime); // 启动翻译引擎
|
obj.trigger(selected, engineTriggerTime); // 启动翻译引擎
|
||||||
|
}
|
||||||
});
|
});
|
||||||
icon.appendChild(img);
|
icon.appendChild(img);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user