mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-10-07 16:35:15 +08:00
Merge branch 'feat-advanced-search' into develop
This commit is contained in:
@@ -260,34 +260,36 @@ var omniboxSearchModes = [
|
||||
{ content: "[必应] " + text, description: "使用 <url>[必应]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "[360] " + text, description: "使用 <url>[360]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "[微博] " + text, description: "使用 <url>[微博]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "[知乎] " + text, description: "使用 <url>[知乎]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "[今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "[中国搜索] " + text, description: "使用 <url>[中国搜索]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
]);
|
||||
return;
|
||||
|
||||
var url = "https://code.google.com/p/chromium/codesearch#search/&type=cs&q=" + query +
|
||||
"&exact_package=chromium&type=cs";
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", url, true);
|
||||
req.setRequestHeader("GData-Version", "2");
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState == 4) callback(req.responseXML);
|
||||
}
|
||||
req.send(null);
|
||||
// return req;
|
||||
// var url = "https://code.google.com/p/chromium/codesearch#search/&type=cs&q=" + query +
|
||||
// "&exact_package=chromium&type=cs";
|
||||
// var req = new XMLHttpRequest();
|
||||
// req.open("GET", url, true);
|
||||
// req.setRequestHeader("GData-Version", "2");
|
||||
// req.onreadystatechange = function () {
|
||||
// if (req.readyState == 4) callback(req.responseXML);
|
||||
// }
|
||||
// req.send(null);
|
||||
// // return req;
|
||||
|
||||
|
||||
suggestions.forEach((suggestion) => { suggestion.deletable = false /* 用户不可删除 */ });
|
||||
/**
|
||||
* SuggestResult
|
||||
* refer: https://developer.chrome.com/docs/extensions/reference/omnibox/
|
||||
* { content, description[, deletable] }
|
||||
*/
|
||||
suggest(suggestions);
|
||||
// suggestions.forEach((suggestion) => { suggestion.deletable = false /* 用户不可删除 */ });
|
||||
// /**
|
||||
// * SuggestResult
|
||||
// * refer: https://developer.chrome.com/docs/extensions/reference/omnibox/
|
||||
// * { content, description[, deletable] }
|
||||
// */
|
||||
// suggest(suggestions);
|
||||
|
||||
// suggest([
|
||||
// { content: "one", description: "the <match>aaa</match><url>www</url>first one", deletable: false },
|
||||
// { content: "number two", description: "the second entry", deletable: false }
|
||||
// ]);
|
||||
// // suggest([
|
||||
// // { content: "one", description: "the <match>aaa</match><url>www</url>first one", deletable: false },
|
||||
// // { content: "number two", description: "the second entry", deletable: false }
|
||||
// // ]);
|
||||
},
|
||||
// 执行搜索
|
||||
search: function (text) {
|
||||
@@ -316,6 +318,12 @@ var omniboxSearchModes = [
|
||||
case "[微博]":
|
||||
navigate("https://s.weibo.com/weibo?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[知乎]":
|
||||
navigate("https://www.zhihu.com/search?type=content&q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[今日头条]":
|
||||
navigate("https://so.toutiao.com/search?dvpf=pc&keyword=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[中国搜索]":
|
||||
navigate("http://www.chinaso.com/newssearch/all/allResults?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
@@ -324,88 +332,10 @@ var omniboxSearchModes = [
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
{
|
||||
key: "yn",
|
||||
// 显示文字
|
||||
showText: "网页内搜索(Todo)",
|
||||
// 搜索模式匹配
|
||||
match: function (text) {
|
||||
return /^yn( |:|\uff1a)?/.test(text)
|
||||
},
|
||||
// 获取输入文字
|
||||
getInputText: function (text, encodeText = true) {
|
||||
let returnText = /^yn(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
return encodeText ? encodeXML(returnText) : returnText
|
||||
},
|
||||
// 搜索建议
|
||||
getSuggestions: async function (text, suggest) {
|
||||
return;
|
||||
},
|
||||
// 执行搜索
|
||||
search: function (text) {
|
||||
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
{
|
||||
key: "re",
|
||||
// 显示文字
|
||||
showText: "网页内正则表达式搜索(Todo)",
|
||||
// 搜索模式匹配
|
||||
match: function (text) {
|
||||
return /^re( |:|\uff1a)?/.test(text)
|
||||
},
|
||||
// 获取输入文字
|
||||
getInputText: function (text, encodeText = true) {
|
||||
let returnText = /^re(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
return encodeText ? encodeXML(returnText) : returnText
|
||||
},
|
||||
// 搜索建议
|
||||
getSuggestions: async function (text, suggest) {
|
||||
return;
|
||||
},
|
||||
// 执行搜索
|
||||
search: function (text) {
|
||||
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
{
|
||||
key: "ls",
|
||||
// 显示文字
|
||||
showText: "历史记录搜索",
|
||||
// 搜索模式匹配
|
||||
match: function (text) {
|
||||
return /^ls( |:|\uff1a)?/.test(text)
|
||||
},
|
||||
// 获取输入文字
|
||||
getInputText: function (text, encodeText = true) {
|
||||
let returnText = /^ls(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
return encodeText ? encodeXML(returnText) : returnText
|
||||
},
|
||||
// 搜索建议
|
||||
getSuggestions: async function (text, suggest) {
|
||||
return;
|
||||
},
|
||||
// 执行搜索
|
||||
search: function (text) {
|
||||
function onGot(historyItems) {
|
||||
for (item of historyItems) {
|
||||
console.log(item.url);
|
||||
console.log(new Date(item.lastVisitTime));
|
||||
}
|
||||
}
|
||||
|
||||
var searching = browser.history.search({ text: text, startTime: 0 });
|
||||
|
||||
searching.then(onGot);
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
{
|
||||
key: "img",
|
||||
// 显示文字
|
||||
showText: "图片搜索",
|
||||
showText: "图片",
|
||||
// 搜索模式匹配
|
||||
match: function (text) {
|
||||
return /^img( |:|\uff1a)?/.test(text)
|
||||
@@ -425,6 +355,7 @@ var omniboxSearchModes = [
|
||||
{ content: "img: [必应] " + text, description: "使用 <url>[必应图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "img: [360] " + text, description: "使用 <url>[360图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "img: [微博] " + text, description: "使用 <url>[微博图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "img: [今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "img: [中国搜索] " + text, description: "使用 <url>[中国搜索图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
]);
|
||||
return;
|
||||
@@ -456,6 +387,9 @@ var omniboxSearchModes = [
|
||||
case "[微博]":
|
||||
navigate("https://s.weibo.com/pic?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[今日头条]":
|
||||
navigate("https://so.toutiao.com/search?pd=atlas&dvpf=pc&keyword=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[中国搜索]":
|
||||
navigate("http://www.chinaso.com/newssearch/image?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
@@ -465,90 +399,338 @@ var omniboxSearchModes = [
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
// Todo: 视频搜索
|
||||
// {
|
||||
// key: "video",
|
||||
// // 显示文字
|
||||
// showText: "视频搜索",
|
||||
// // 搜索模式匹配
|
||||
// match: function (text) {
|
||||
// return /^video( |:|\uff1a)?/.test(text)
|
||||
// },
|
||||
// // 获取输入文字
|
||||
// getInputText: function (text, encodeText = true) {
|
||||
// let returnText = /^video(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
// return encodeText ? encodeXML(returnText) : returnText
|
||||
// },
|
||||
// // 搜索建议
|
||||
// getSuggestions: async function (text, suggest) {
|
||||
// // 如果前面已经有了 【[xx] 】,则先去掉
|
||||
// text = text.replace(/^\[.*?\]\s*/, "");
|
||||
// suggest([
|
||||
// { content: "video: [百度] " + text, description: "使用 <url>[百度视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
// { content: "video: [搜狗] " + text, description: "使用 <url>[搜狗视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
// { content: "video: [必应] " + text, description: "使用 <url>[必应视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
// { content: "video: [360] " + text, description: "使用 <url>[360视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
// { content: "video: [微博] " + text, description: "使用 <url>[微博视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
// { content: "video: [中国搜索] " + text, description: "使用 <url>[中国搜索视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
// ]);
|
||||
// return;
|
||||
// },
|
||||
// // 执行搜索
|
||||
// search: function (text) {
|
||||
// let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
|
||||
// let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[百度]"/* 默认百度视频搜索 */).trim())[0].trim()
|
||||
// let searchText = searchInput[3].trim()
|
||||
// console.log("[视频搜索开始]");
|
||||
// console.log(" 传入参数为:", text);
|
||||
// console.log(" searchInput为:", searchInput);
|
||||
// console.log(" searchType为:", searchType);
|
||||
// console.log(" searchText为:", searchText);
|
||||
// switch (searchType) {
|
||||
// default:
|
||||
// case "[百度]":
|
||||
// navigate("https://v.baidu.com/v?word=" + encodeURIComponent(searchText), true);
|
||||
// break;
|
||||
// case "[搜狗]":
|
||||
// navigate("https://pic.sogou.com/pics?query=" + encodeURIComponent(searchText), true);
|
||||
// break;
|
||||
// case "[必应]":
|
||||
// navigate("https://cn.bing.com/images/search?q=" + encodeURIComponent(searchText), true);
|
||||
// break;
|
||||
// case "[360]":
|
||||
// navigate("https://image.so.com/i?q=" + encodeURIComponent(searchText), true);
|
||||
// break;
|
||||
// case "[微博]":
|
||||
// navigate("https://s.weibo.com/pic?q=" + encodeURIComponent(searchText), true);
|
||||
// break;
|
||||
// case "[中国搜索]":
|
||||
// navigate("http://www.chinaso.com/newssearch/image?q=" + encodeURIComponent(searchText), true);
|
||||
// break;
|
||||
|
||||
// }
|
||||
// console.log("[图片搜索结束]");
|
||||
// }
|
||||
// },
|
||||
// #############################################################################################################
|
||||
{
|
||||
key: "boss",
|
||||
key: "video",
|
||||
// 显示文字
|
||||
showText: "召唤“学生助手”",
|
||||
showText: "视频",
|
||||
// 搜索模式匹配
|
||||
match: function (text) {
|
||||
// return text.trim() == "boss"
|
||||
return /^boss( |:|\uff1a)?$/.test(text)
|
||||
return /^video( |:|\uff1a)?/.test(text)
|
||||
},
|
||||
// 获取输入文字
|
||||
getInputText: (text) => "回车执行",
|
||||
getInputText: function (text, encodeText = true) {
|
||||
let returnText = /^video(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
return encodeText ? encodeXML(returnText) : returnText
|
||||
},
|
||||
// 搜索建议
|
||||
getSuggestions: async function (text, suggest) {
|
||||
// 如果前面已经有了 【[xx] 】,则先去掉
|
||||
text = text.replace(/^\[.*?\]\s*/, "");
|
||||
suggest([
|
||||
{ content: "video: [B站] " + text, description: "使用 <url>[哔哩哔哩动画]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [爱奇艺] " + text, description: "使用 <url>[爱奇艺]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [腾讯视频] " + text, description: "使用 <url>[腾讯视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [优酷] " + text, description: "使用 <url>[优酷]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [百度] " + text, description: "使用 <url>[百度视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [搜狗] " + text, description: "使用 <url>[搜狗视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [360] " + text, description: "使用 <url>[360视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [微博] " + text, description: "使用 <url>[微博视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [抖音] " + text, description: "使用 <url>[抖音]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
// 以下内容超出9个不被显示
|
||||
{ content: "video: [今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [快手] " + text, description: "使用 <url>[快手]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [知乎] " + text, description: "使用 <url>[知乎]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [搜狐] " + text, description: "使用 <url>[搜狐视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [央视网] " + text, description: "使用 <url>[央视网]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "video: [中国搜索] " + text, description: "使用 <url>[中国搜索视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
]);
|
||||
return;
|
||||
},
|
||||
// 执行搜索
|
||||
search: function (text) {
|
||||
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
|
||||
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[B站]"/* 默认爱奇艺搜索 */).trim())[0].trim()
|
||||
let searchText = searchInput[3].trim()
|
||||
console.log("[视频搜索开始]");
|
||||
console.log(" 传入参数为:", text);
|
||||
console.log(" searchInput为:", searchInput);
|
||||
console.log(" searchType为:", searchType);
|
||||
console.log(" searchText为:", searchText);
|
||||
switch (searchType) {
|
||||
default:
|
||||
case "[B站]":
|
||||
navigate("https://search.bilibili.com/all?keyword=" + searchText);
|
||||
break;
|
||||
case "[爱奇艺]":
|
||||
navigate("https://so.iqiyi.com/so/q_" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[腾讯视频]":
|
||||
navigate("https://v.qq.com/x/search/?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[优酷]":
|
||||
navigate("https://so.youku.com/search_video/q_" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[百度]":
|
||||
navigate("https://v.baidu.com/v?word=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[搜狗]":
|
||||
navigate("https://v.so.com/s?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[360]":
|
||||
navigate("https://tv.360kan.com/s?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[微博]":
|
||||
navigate("https://s.weibo.com/video?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[抖音]":
|
||||
navigate("https://www.douyin.com/search/" + encodeURIComponent(searchText) + "?type=video", true);
|
||||
break;
|
||||
case "[今日头条]":
|
||||
navigate("https://so.toutiao.com/search?pd=video&dvpf=pc&keyword=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[知乎]":
|
||||
navigate("https://www.zhihu.com/search?type=zvideo&q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[快手]":
|
||||
navigate("https://www.kuaishou.com/search/video?searchKey=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[搜狐]":
|
||||
navigate("https://so.tv.sohu.com/mts?wd=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[央视网]":
|
||||
navigate("https://search.cctv.com/search.php?type=video&qtext=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[中国搜索]":
|
||||
navigate("http://www.chinaso.com/newssearch/video?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
}
|
||||
console.log("[视频搜索结束]");
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
{
|
||||
key: "news",
|
||||
// 显示文字
|
||||
showText: "新闻",
|
||||
// 搜索模式匹配
|
||||
match: function (text) {
|
||||
return /^news( |:|\uff1a)?/.test(text)
|
||||
},
|
||||
// 获取输入文字
|
||||
getInputText: function (text, encodeText = true) {
|
||||
let returnText = /^news(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
return encodeText ? encodeXML(returnText) : returnText
|
||||
},
|
||||
// 搜索建议
|
||||
getSuggestions: async function (text, suggest) {
|
||||
// 如果前面已经有了 【[xx] 】,则先去掉
|
||||
text = text.replace(/^\[.*?\]\s*/, "");
|
||||
suggest([
|
||||
{ content: "news: [今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "news: [百度] " + text, description: "使用 <url>[百度资讯]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "news: [360] " + text, description: "使用 <url>[360资讯]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "news: [微博] " + text, description: "使用 <url>[微博]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "news: [人民网] " + text, description: "使用 <url>[人民网]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "news: [中国搜索] " + text, description: "使用 <url>[中国搜索]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
{ content: "news: [快资讯] " + text, description: "使用 <url>[快资讯]</url> 搜索 <match>" + text + "</match>", deletable: false },
|
||||
]);
|
||||
return;
|
||||
},
|
||||
// 执行搜索
|
||||
search: function (text) {
|
||||
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
|
||||
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[今日头条]"/* 默认今日头条搜索 */).trim())[0].trim()
|
||||
let searchText = searchInput[3].trim()
|
||||
console.log("[新闻搜索开始]");
|
||||
console.log(" 传入参数为:", text);
|
||||
console.log(" searchInput为:", searchInput);
|
||||
console.log(" searchType为:", searchType);
|
||||
console.log(" searchText为:", searchText);
|
||||
switch (searchType) {
|
||||
default:
|
||||
case "[今日头条]":
|
||||
navigate("https://www.toutiao.com/search/?keyword=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[百度]":
|
||||
navigate("https://www.baidu.com/s?tn=news&word=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[360]":
|
||||
navigate("https://news.so.com/ns?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[微博]":
|
||||
navigate("https://s.weibo.com/weibo/" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[人民网]":
|
||||
navigate("http://search.people.cn/s?keyword=" + encodeURIComponent(searchText) + "&st=0&_=" + Date.now(), true);
|
||||
break;
|
||||
case "[中国搜索]":
|
||||
navigate("http://www.chinaso.com/newssearch/news?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[快资讯]":
|
||||
navigate("https://www.360kuai.com/search?q=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
}
|
||||
console.log("[新闻搜索结束]");
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
{
|
||||
key: "fanyi",
|
||||
// 显示文字
|
||||
showText: "翻译",
|
||||
// 搜索模式匹配
|
||||
match: function (text) {
|
||||
return /^fanyi( |:|\uff1a)?/.test(text)
|
||||
},
|
||||
// 获取输入文字
|
||||
getInputText: function (text, encodeText = true) {
|
||||
let returnText = /^fanyi(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
return encodeText ? encodeXML(returnText) : returnText
|
||||
},
|
||||
// 搜索建议
|
||||
getSuggestions: async function (text, suggest) {
|
||||
// 如果前面已经有了 【[xx] 】,则先去掉
|
||||
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: [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: [Google] " + text, description: "使用 <url>[Google翻译]</url> 翻译 <match>" + text + "</match> (Google翻译在中国大陆无法使用)", deletable: false },
|
||||
]);
|
||||
return;
|
||||
},
|
||||
// 执行搜索
|
||||
search: function (text) {
|
||||
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
|
||||
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[百度]"/* 默认百度翻译 */).trim())[0].trim()
|
||||
let searchText = searchInput[3].trim()
|
||||
console.log("[翻译搜索开始]");
|
||||
console.log(" 传入参数为:", text);
|
||||
console.log(" searchInput为:", searchInput);
|
||||
console.log(" searchType为:", searchType);
|
||||
console.log(" searchText为:", searchText);
|
||||
switch (searchType) {
|
||||
default:
|
||||
case "[百度]":
|
||||
// 百度翻译中英文会自动识别,所以不需要手动判断
|
||||
navigate("https://fanyi.baidu.com/#en/zh/" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[有道]":
|
||||
navigate("https://www.youdao.com/w/" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[金山词霸]":
|
||||
navigate("https://www.iciba.com/word?w=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[360]":
|
||||
navigate("https://fanyi.so.com/#" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
case "[DeepL]":
|
||||
let hasChineseChar = /.*[\u4e00-\u9fa5]+.*$/.test(searchText)
|
||||
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问价获取到,然后填入到页面中
|
||||
break;
|
||||
case "[Google]":
|
||||
navigate("https://translate.google.cn/?text=" + encodeURIComponent(searchText), true);
|
||||
break;
|
||||
}
|
||||
console.log("[翻译搜索结束]");
|
||||
}
|
||||
},
|
||||
// #############################################################################################################
|
||||
// {
|
||||
// key: "yn",
|
||||
// // 显示文字
|
||||
// showText: "网页内搜索(Todo)",
|
||||
// // 搜索模式匹配
|
||||
// match: function (text) {
|
||||
// return /^yn( |:|\uff1a)?/.test(text)
|
||||
// },
|
||||
// // 获取输入文字
|
||||
// getInputText: function (text, encodeText = true) {
|
||||
// let returnText = /^yn(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
// return encodeText ? encodeXML(returnText) : returnText
|
||||
// },
|
||||
// // 搜索建议
|
||||
// getSuggestions: async function (text, suggest) {
|
||||
// return;
|
||||
// },
|
||||
// // 执行搜索
|
||||
// search: function (text) {
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
// },
|
||||
// #############################################################################################################
|
||||
// {
|
||||
// key: "re",
|
||||
// // 显示文字
|
||||
// showText: "网页内正则表达式搜索(Todo)",
|
||||
// // 搜索模式匹配
|
||||
// match: function (text) {
|
||||
// return /^re( |:|\uff1a)?/.test(text)
|
||||
// },
|
||||
// // 获取输入文字
|
||||
// getInputText: function (text, encodeText = true) {
|
||||
// let returnText = /^re(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
// return encodeText ? encodeXML(returnText) : returnText
|
||||
// },
|
||||
// // 搜索建议
|
||||
// getSuggestions: async function (text, suggest) {
|
||||
// return;
|
||||
// },
|
||||
// // 执行搜索
|
||||
// search: function (text) {
|
||||
|
||||
// }
|
||||
// },
|
||||
// #############################################################################################################
|
||||
// {
|
||||
// key: "ls",
|
||||
// // 显示文字
|
||||
// showText: "历史记录(Todo)",
|
||||
// // 搜索模式匹配
|
||||
// match: function (text) {
|
||||
// return /^ls( |:|\uff1a)?/.test(text)
|
||||
// },
|
||||
// // 获取输入文字
|
||||
// getInputText: function (text, encodeText = true) {
|
||||
// let returnText = /^ls(:| |\uff1a)?(.*)$/.exec(text)[2].trim()
|
||||
// return encodeText ? encodeXML(returnText) : returnText
|
||||
// },
|
||||
// // 搜索建议
|
||||
// getSuggestions: async function (text, suggest) {
|
||||
// return;
|
||||
// },
|
||||
// // 执行搜索
|
||||
// search: function (text) {
|
||||
// function onGot(historyItems) {
|
||||
// for (item of historyItems) {
|
||||
// console.log(item.url);
|
||||
// console.log(new Date(item.lastVisitTime));
|
||||
// }
|
||||
// }
|
||||
|
||||
// var searching = browser.history.search({ text: text, startTime: 0 });
|
||||
|
||||
// searching.then(onGot);
|
||||
// }
|
||||
// },
|
||||
// #############################################################################################################
|
||||
// {
|
||||
// key: "boss",
|
||||
// // 显示文字
|
||||
// showText: "召唤“学生助手”",
|
||||
// // 搜索模式匹配
|
||||
// match: function (text) {
|
||||
// // return text.trim() == "boss"
|
||||
// return /^boss( |:|\uff1a)?$/.test(text)
|
||||
// },
|
||||
// // 获取输入文字
|
||||
// getInputText: (text) => "回车执行",
|
||||
// // 搜索建议
|
||||
// getSuggestions: async function (text, suggest) {
|
||||
// return;
|
||||
// },
|
||||
// // 执行搜索
|
||||
// search: function (text) {
|
||||
|
||||
// }
|
||||
// }
|
||||
]
|
||||
|
||||
|
||||
|
@@ -0,0 +1,28 @@
|
||||
$(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];
|
||||
}
|
||||
});
|
||||
|
||||
window.onload = () => {
|
||||
let transText = $.getUrlVar('__bitdance_extension__');
|
||||
if (transText == "") return
|
||||
// alert(transText)
|
||||
document.getElementsByTagName("textarea")[0].value = decodeURIComponent(transText)
|
||||
$(".language-translate-button")[0].click()
|
||||
}
|
||||
})
|
@@ -44,6 +44,16 @@
|
||||
"assets/js/expand-full-text/expand.js"
|
||||
],
|
||||
"run_at": "document_start"
|
||||
},
|
||||
{
|
||||
"matches": [
|
||||
"*://fanyi.qq.com/*"
|
||||
],
|
||||
"js": [
|
||||
"assets/js/lib/jquery.min.js",
|
||||
"assets/js/advanced-search/content-helper/fanyi.qq.com.js"
|
||||
],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
"browser_action": {
|
||||
|
Reference in New Issue
Block a user