mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-10-08 00:45:13 +08:00
有道翻译、腾讯翻译君相关代码修改完善;一些小改动
This commit is contained in:
@@ -583,11 +583,12 @@ var omniboxSearchModes = [
|
||||
text = text.replace(/^\[.*?\]\s*/, "");
|
||||
suggest([
|
||||
{ content: "fanyi: [百度] " + text, description: "使用 <url>[百度翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "fanyi: [有道] " + text, description: "使用 <url>[有道翻译]</url> 查词 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "fanyi: [有道翻译] " + text, description: "使用 <url>[有道翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "fanyi: [有道] " + text, description: "使用 <url>[有道]</url> 查词 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "fanyi: [金山词霸] " + text, description: "使用 <url>[金山词霸]</url> 查词 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "fanyi: [360] " + text, description: "使用 <url>[360翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "fanyi: [DeepL] " + text, description: "使用 <url>[DeepL翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "fanyi: [腾讯] " + text, description: "使用 <url>[腾讯翻译君]</url> (无法填入翻译文字,请打开页面后输入)", deletable: false },
|
||||
{ content: "fanyi: [腾讯] " + text, description: "使用 <url>[腾讯翻译君]</url>", deletable: false },
|
||||
{ content: "fanyi: [Google] " + text, description: "使用 <url>[Google翻译]</url> 翻译 <match>" + text + "</match> (Google翻译在中国大陆无法使用)", deletable: false },
|
||||
]);
|
||||
return;
|
||||
@@ -608,6 +609,10 @@ var omniboxSearchModes = [
|
||||
// 百度翻译中英文会自动识别,所以不需要手动判断
|
||||
navigate("https://fanyi.baidu.com/#en/zh/" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[有道翻译]":
|
||||
// 后面参数通过注入的js代码获取并在网页加载完后填入到翻译框中,点击搜索按钮
|
||||
navigate("https://fanyi.youdao.com/?__bitdance_extension__=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[有道]":
|
||||
navigate("https://www.youdao.com/w/" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
@@ -622,8 +627,8 @@ var omniboxSearchModes = [
|
||||
navigate("https://www.deepl.com/translator#" + (hasChineseChar ? "zh/en/" : "en/zh/") + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[腾讯]":
|
||||
navigate("https://fanyi.qq.com/?__bitdance_extension__=" + encodeURIComponent(searchText), true);
|
||||
// 参数后面通过注入的js问价获取到,然后填入到页面中
|
||||
// 网页加载好后自动点击翻译按钮
|
||||
navigate("https://fanyi.qq.com/?text=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[Google]":
|
||||
navigate("https://translate.google.cn/?text=" + encodeURIComponent(searchText), true);
|
||||
|
@@ -1,28 +1,4 @@
|
||||
$(function () {
|
||||
console.log("[BitDance extension] 学生助手插件 - 腾讯翻译君自动填入模块加载成功");
|
||||
|
||||
// refer: https://www.cnblogs.com/chen-lhx/p/5198612.html
|
||||
$.extend({
|
||||
getUrlVars: function () {
|
||||
var vars = [], hash;
|
||||
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
||||
for (var i = 0; i < hashes.length; i++) {
|
||||
hash = hashes[i].split('=');
|
||||
vars.push(hash[0]);
|
||||
vars[hash[0]] = hash[1];
|
||||
}
|
||||
return vars;
|
||||
},
|
||||
getUrlVar: function (name) {
|
||||
return $.getUrlVars()[name];
|
||||
}
|
||||
});
|
||||
|
||||
console.log("[BitDance extension] 学生助手插件 - 腾讯翻译君自动点击翻译模块加载成功");
|
||||
window.onload = () => {
|
||||
let transText = $.getUrlVar('__bitdance_extension__');
|
||||
if (transText == "") return
|
||||
// alert(transText)
|
||||
document.getElementsByTagName("textarea")[0].value = decodeURIComponent(transText)
|
||||
$(".language-translate-button")[0].click()
|
||||
}
|
||||
})
|
||||
|
@@ -0,0 +1,31 @@
|
||||
console.log("[BitDance extension] 学生助手插件 - 有道翻译自动填入模块加载成功");
|
||||
|
||||
// refer: https://www.cnblogs.com/chen-lhx/p/5198612.html
|
||||
$.extend({
|
||||
getUrlVars: function () {
|
||||
var vars = [], hash;
|
||||
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
||||
for (var i = 0; i < hashes.length; i++) {
|
||||
hash = hashes[i].split('=');
|
||||
vars.push(hash[0]);
|
||||
vars[hash[0]] = hash[1];
|
||||
}
|
||||
return vars;
|
||||
},
|
||||
getUrlVar: function (name) {
|
||||
return $.getUrlVars()[name];
|
||||
}
|
||||
});
|
||||
|
||||
window.onload = () => {
|
||||
let transText = $.getUrlVar('__bitdance_extension__');
|
||||
if (!transText || transText.trim() == "") return
|
||||
// alert(transText)
|
||||
console.log("[BitDance extension] 学生助手插件 - 有道翻译自动填入模块 - 翻译文本为:", transText);
|
||||
document.getElementsByTagName("textarea")[0].value = decodeURIComponent(transText)
|
||||
document.getElementById("transMachine").click()
|
||||
|
||||
// 参数获取完成后,清除掉页面参数
|
||||
// History.replaceState() refer: https://developer.mozilla.org/zh-CN/docs/Web/API/History/replaceState
|
||||
history.replaceState({}, "", "/");
|
||||
}
|
@@ -36,8 +36,7 @@
|
||||
},
|
||||
{
|
||||
"matches": [
|
||||
"http://blog.csdn.net/*",
|
||||
"https://blog.csdn.net/*"
|
||||
"*://blog.csdn.net/*"
|
||||
],
|
||||
"js": [
|
||||
"assets/js/lib/jquery.min.js",
|
||||
@@ -54,6 +53,16 @@
|
||||
"assets/js/advanced-search/content-helper/fanyi.qq.com.js"
|
||||
],
|
||||
"run_at": "document_start"
|
||||
},
|
||||
{
|
||||
"matches": [
|
||||
"*://fanyi.youdao.com/*"
|
||||
],
|
||||
"js": [
|
||||
"assets/js/lib/jquery.min.js",
|
||||
"assets/js/advanced-search/content-helper/fanyi.youdao.com.js"
|
||||
],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
"browser_action": {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>BitDance</title>
|
||||
<title>学生助手</title>
|
||||
<link href="assets/css/main.css" type="text/css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
|
Reference in New Issue
Block a user