From 06d270363ade32c6b1e579f11dfc605c1974c361 Mon Sep 17 00:00:00 2001 From: Coding Zhang <2291200076@qq.com> Date: Sat, 5 Feb 2022 17:44:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=A6=E6=9C=AF=E8=AE=BA?= =?UTF-8?q?=E6=96=87=E6=90=9C=E7=B4=A2=E6=A8=A1=E5=BC=8F=EF=BC=9B=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E5=B7=B2=E6=9C=89=E6=90=9C=E7=B4=A2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=8E=A8=E8=8D=90=EF=BC=9Bomnibox=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E5=85=B3=E9=94=AE=E5=AD=97=E6=97=B6=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/js/advanced-search/background.js | 139 ++++++++++++++---- .../content-helper/fanyi.youdao.com.js | 2 +- .../content-helper/qikan.cqvip.com.js | 27 ++++ .../content-helper/www.cnki.net.js | 27 ++++ packages/shell-chrome/manifest.json | 21 +++ 5 files changed, 184 insertions(+), 32 deletions(-) create mode 100644 packages/shell-chrome/assets/js/advanced-search/content-helper/qikan.cqvip.com.js create mode 100644 packages/shell-chrome/assets/js/advanced-search/content-helper/www.cnki.net.js diff --git a/packages/shell-chrome/assets/js/advanced-search/background.js b/packages/shell-chrome/assets/js/advanced-search/background.js index a9cc0e7..44a63e8 100644 --- a/packages/shell-chrome/assets/js/advanced-search/background.js +++ b/packages/shell-chrome/assets/js/advanced-search/background.js @@ -338,11 +338,11 @@ var omniboxSearchModes = [ showText: "图片", // 搜索模式匹配 match: function (text) { - return /^img( |:|\uff1a)?/.test(text) + return /^img( |:|\uff1a)?/i.test(text) }, // 获取输入文字 getInputText: function (text, encodeText = true) { - let returnText = /^img(:| |\uff1a)?(.*)$/.exec(text)[2].trim() + let returnText = /^img(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() return encodeText ? encodeXML(returnText) : returnText }, // 搜索建议 @@ -405,11 +405,11 @@ var omniboxSearchModes = [ showText: "视频", // 搜索模式匹配 match: function (text) { - return /^video( |:|\uff1a)?/.test(text) + return /^video( |:|\uff1a)?/i.test(text) }, // 获取输入文字 getInputText: function (text, encodeText = true) { - let returnText = /^video(:| |\uff1a)?(.*)$/.exec(text)[2].trim() + let returnText = /^video(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() return encodeText ? encodeXML(returnText) : returnText }, // 搜索建议 @@ -423,10 +423,11 @@ var omniboxSearchModes = [ { content: "video: [优酷] " + text, description: "使用 [优酷] 搜索 " + text + "", deletable: false }, { content: "video: [百度] " + text, description: "使用 [百度视频] 搜索 " + text + "", deletable: false }, { content: "video: [搜狗] " + text, description: "使用 [搜狗视频] 搜索 " + text + "", deletable: false }, - { content: "video: [360] " + text, description: "使用 [360视频] 搜索 " + text + "", deletable: false }, { content: "video: [微博] " + text, description: "使用 [微博视频] 搜索 " + text + "", deletable: false }, { content: "video: [抖音] " + text, description: "使用 [抖音] 搜索 " + text + "", deletable: false }, + { content: "video: [必应] " + text, description: "使用 [必应视频] 搜索 " + text + "", deletable: false }, // 以下内容超出9个不被显示 + { content: "video: [360] " + text, description: "使用 [360视频] 搜索 " + text + "", deletable: false }, { content: "video: [今日头条] " + text, description: "使用 [今日头条] 搜索 " + text + "", deletable: false }, { content: "video: [快手] " + text, description: "使用 [快手] 搜索 " + text + "", deletable: false }, { content: "video: [知乎] " + text, description: "使用 [知乎] 搜索 " + text + "", deletable: false }, @@ -475,6 +476,9 @@ var omniboxSearchModes = [ case "[抖音]": navigate("https://www.douyin.com/search/" + encodeURIComponent(searchText) + "?type=video", true); break; + case "[必应]": + navigate("https://cn.bing.com/videos/search?q=" + encodeURIComponent(searchText), true); + break; case "[今日头条]": navigate("https://so.toutiao.com/search?pd=video&dvpf=pc&keyword=" + encodeURIComponent(searchText), true); break; @@ -504,11 +508,11 @@ var omniboxSearchModes = [ showText: "新闻", // 搜索模式匹配 match: function (text) { - return /^news( |:|\uff1a)?/.test(text) + return /^news( |:|\uff1a)?/i.test(text) }, // 获取输入文字 getInputText: function (text, encodeText = true) { - let returnText = /^news(:| |\uff1a)?(.*)$/.exec(text)[2].trim() + let returnText = /^news(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() return encodeText ? encodeXML(returnText) : returnText }, // 搜索建议 @@ -570,11 +574,11 @@ var omniboxSearchModes = [ showText: "翻译", // 搜索模式匹配 match: function (text) { - return /^fanyi( |:|\uff1a)?/.test(text) + return /^fanyi( |:|\uff1a)?/i.test(text) }, // 获取输入文字 getInputText: function (text, encodeText = true) { - let returnText = /^fanyi(:| |\uff1a)?(.*)$/.exec(text)[2].trim() + let returnText = /^fanyi(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() return encodeText ? encodeXML(returnText) : returnText }, // 搜索建议 @@ -584,12 +588,14 @@ var omniboxSearchModes = [ suggest([ { content: "fanyi: [百度] " + text, description: "使用 [百度翻译] 翻译 " + text + "", deletable: false }, { content: "fanyi: [有道翻译] " + text, description: "使用 [有道翻译] 翻译 " + text + "", deletable: false }, - { content: "fanyi: [有道] " + text, description: "使用 [有道] 查词 " + text + "", deletable: false }, - { content: "fanyi: [金山词霸] " + text, description: "使用 [金山词霸] 查词 " + text + "", deletable: false }, - { content: "fanyi: [360] " + text, description: "使用 [360翻译] 翻译 " + text + "", deletable: false }, - { content: "fanyi: [DeepL] " + text, description: "使用 [DeepL翻译] 翻译 " + text + "", deletable: false }, + { content: "fanyi: [必应] " + text, description: "使用 [必应词典] 查词 " + text + "", deletable: false }, { content: "fanyi: [腾讯] " + text, description: "使用 [腾讯翻译君] 翻译 " + text + "", deletable: false }, + { content: "fanyi: [DeepL] " + text, description: "使用 [DeepL翻译] 翻译 " + text + "", deletable: false }, + { content: "fanyi: [金山词霸] " + text, description: "使用 [金山词霸] 查词 " + text + "", deletable: false }, + { content: "fanyi: [有道] " + text, description: "使用 [有道] 查词 " + text + "", deletable: false }, + { content: "fanyi: [360] " + text, description: "使用 [360翻译] 翻译 " + text + "", deletable: false }, { content: "fanyi: [翻译狗] " + text, description: "使用 [翻译狗] 翻译 " + text + "", deletable: false }, + // 以下内容超出9个不被显示 { content: "fanyi: [Google] " + text, description: "使用 [Google翻译] 翻译 " + text + " (Google翻译在中国大陆无法使用)", deletable: false }, ]); return; @@ -611,25 +617,28 @@ var omniboxSearchModes = [ navigate("https://fanyi.baidu.com/#en/zh/" + encodeURIComponent(searchText), true); break; case "[有道翻译]": - // 后面参数通过注入的js代码获取并在网页加载完后填入到翻译框中,点击搜索按钮 + // 后面参数通过注入的js代码获取并在网页加载完后填入到翻译框中,点击翻译按钮 navigate("https://fanyi.youdao.com/?__bitdance_extension__=" + encodeURIComponent(searchText), true); break; - case "[有道]": - navigate("https://www.youdao.com/w/" + encodeURIComponent(searchText), true); + case "[必应]": + navigate("https://cn.bing.com/dict/search?q=" + 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); + case "[腾讯]": + // 网页加载好后自动点击翻译按钮 + navigate("https://fanyi.qq.com/?text=" + 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/?text=" + encodeURIComponent(searchText), true); + case "[金山词霸]": + navigate("https://www.iciba.com/word?w=" + encodeURIComponent(searchText), true); + break; + case "[有道]": + navigate("https://www.youdao.com/w/" + encodeURIComponent(searchText), true); + break; + case "[360]": + navigate("https://fanyi.so.com/#" + encodeURIComponent(searchText), true); break; case "[翻译狗]": navigate("https://www.fanyigou.com/trans/totran/tranText.html?text=" + encodeURIComponent(searchText), true); @@ -642,17 +651,85 @@ var omniboxSearchModes = [ } }, // ############################################################################################################# + { + key: "paper", + // 显示文字 + showText: "学术论文", + // 搜索模式匹配 + match: function (text) { + return /^paper( |:|\uff1a)?/i.test(text) + }, + // 获取输入文字 + getInputText: function (text, encodeText = true) { + let returnText = /^paper(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() + return encodeText ? encodeXML(returnText) : returnText + }, + // 搜索建议 + getSuggestions: async function (text, suggest) { + // 如果前面已经有了 【[xx] 】,则先去掉 + text = text.replace(/^\[.*?\]\s*/, ""); + suggest([ + { content: "paper: [知网] " + text, description: "使用 [中国知网] 搜索 " + text + "", deletable: false }, + { content: "paper: [万方] " + text, description: "使用 [万方数据] 搜索 " + text + "", deletable: false }, + { content: "paper: [维普] " + text, description: "使用 [维普期刊] 搜索 " + text + "", deletable: false }, + { content: "paper: [百度] " + text, description: "使用 [百度学术] 搜索 " + text + "", deletable: false }, + { content: "paper: [必应] " + text, description: "使用 [必应学术] 搜索 " + text + "", deletable: false }, + { content: "paper: [搜狗] " + text, description: "使用 [搜狗学术] 搜索 " + text + "", deletable: false }, + { content: "paper: [谷歌] " + text, description: "使用 [谷歌学术] 搜索 " + text + " (谷歌学术在中国大陆无法使用)", 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 "[知网]": + // 后面参数通过注入的js代码获取并在网页加载完后填入到搜索框中,点击搜索按钮 + navigate("https://www.cnki.net/?__bitdance_extension__=" + encodeURIComponent(searchText), true); + break; + case "[万方]": + navigate("https://s.wanfangdata.com.cn/paper?q=" + encodeURIComponent(searchText), true); + break; + case "[维普]": + // 后面参数通过注入的js代码获取并在网页加载完后填入到搜索框中,点击搜索按钮 + navigate("http://qikan.cqvip.com/?__bitdance_extension__=" + encodeURIComponent(searchText), true); + break; + case "[百度]": + navigate("https://xueshu.baidu.com/s?wd=" + encodeURIComponent(searchText), true); + break; + case "[必应]": + navigate("https://cn.bing.com/academic/search?q=" + encodeURIComponent(searchText), true); + break; + case "[搜狗]": + navigate("https://scholar.sogou.com/xueshu?query=" + encodeURIComponent(searchText), true); + break; + case "[Google]": + navigate("https://scholar.google.com/scholar?q=" + encodeURIComponent(searchText), true); + break; + } + console.log("[学术论文搜索结束]"); + } + }, + // ############################################################################################################# // { // key: "yn", // // 显示文字 // showText: "网页内搜索(Todo)", // // 搜索模式匹配 // match: function (text) { - // return /^yn( |:|\uff1a)?/.test(text) + // return /^yn( |:|\uff1a)?/i.test(text) // }, // // 获取输入文字 // getInputText: function (text, encodeText = true) { - // let returnText = /^yn(:| |\uff1a)?(.*)$/.exec(text)[2].trim() + // let returnText = /^yn(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() // return encodeText ? encodeXML(returnText) : returnText // }, // // 搜索建议 @@ -671,11 +748,11 @@ var omniboxSearchModes = [ // showText: "网页内正则表达式搜索(Todo)", // // 搜索模式匹配 // match: function (text) { - // return /^re( |:|\uff1a)?/.test(text) + // return /^re( |:|\uff1a)?/i.test(text) // }, // // 获取输入文字 // getInputText: function (text, encodeText = true) { - // let returnText = /^re(:| |\uff1a)?(.*)$/.exec(text)[2].trim() + // let returnText = /^re(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() // return encodeText ? encodeXML(returnText) : returnText // }, // // 搜索建议 @@ -694,11 +771,11 @@ var omniboxSearchModes = [ // showText: "历史记录(Todo)", // // 搜索模式匹配 // match: function (text) { - // return /^ls( |:|\uff1a)?/.test(text) + // return /^ls( |:|\uff1a)?/i.test(text) // }, // // 获取输入文字 // getInputText: function (text, encodeText = true) { - // let returnText = /^ls(:| |\uff1a)?(.*)$/.exec(text)[2].trim() + // let returnText = /^ls(:| |\uff1a)?(.*)$/i.exec(text)[2].trim() // return encodeText ? encodeXML(returnText) : returnText // }, // // 搜索建议 @@ -727,7 +804,7 @@ var omniboxSearchModes = [ // // 搜索模式匹配 // match: function (text) { // // return text.trim() == "boss" - // return /^boss( |:|\uff1a)?$/.test(text) + // return /^boss( |:|\uff1a)?$/i.test(text) // }, // // 获取输入文字 // getInputText: (text) => "回车执行", diff --git a/packages/shell-chrome/assets/js/advanced-search/content-helper/fanyi.youdao.com.js b/packages/shell-chrome/assets/js/advanced-search/content-helper/fanyi.youdao.com.js index c30b289..be45e43 100644 --- a/packages/shell-chrome/assets/js/advanced-search/content-helper/fanyi.youdao.com.js +++ b/packages/shell-chrome/assets/js/advanced-search/content-helper/fanyi.youdao.com.js @@ -20,8 +20,8 @@ $.extend({ 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() diff --git a/packages/shell-chrome/assets/js/advanced-search/content-helper/qikan.cqvip.com.js b/packages/shell-chrome/assets/js/advanced-search/content-helper/qikan.cqvip.com.js new file mode 100644 index 0000000..0187e2d --- /dev/null +++ b/packages/shell-chrome/assets/js/advanced-search/content-helper/qikan.cqvip.com.js @@ -0,0 +1,27 @@ +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 + console.log("[BitDance extension] 学生助手插件 - 维普期刊自动搜索模块 - 模块文本为:", transText); + + document.getElementById("searchKeywords").value = decodeURIComponent(transText) + document.getElementById("btnSearch").click() +} diff --git a/packages/shell-chrome/assets/js/advanced-search/content-helper/www.cnki.net.js b/packages/shell-chrome/assets/js/advanced-search/content-helper/www.cnki.net.js new file mode 100644 index 0000000..b25895f --- /dev/null +++ b/packages/shell-chrome/assets/js/advanced-search/content-helper/www.cnki.net.js @@ -0,0 +1,27 @@ +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 + console.log("[BitDance extension] 学生助手插件 - 中国知网自动搜索模块 - 模块文本为:", transText); + + document.getElementById("txt_SearchText").value = decodeURIComponent(transText) + document.querySelector(".search-btn").click() +} diff --git a/packages/shell-chrome/manifest.json b/packages/shell-chrome/manifest.json index a4bd37c..db3320b 100644 --- a/packages/shell-chrome/manifest.json +++ b/packages/shell-chrome/manifest.json @@ -63,6 +63,27 @@ "assets/js/advanced-search/content-helper/fanyi.youdao.com.js" ], "run_at": "document_start" + }, + { + "matches": [ + "*://www.cnki.net/*" + ], + "js": [ + "assets/js/lib/jquery.min.js", + "assets/js/advanced-search/content-helper/www.cnki.net.js" + ], + "run_at": "document_start" + }, + { + "matches": [ + "*://qikan.cqvip.com/*", + "*://lib.cqvip.com/*" + ], + "js": [ + "assets/js/lib/jquery.min.js", + "assets/js/advanced-search/content-helper/qikan.cqvip.com.js" + ], + "run_at": "document_start" } ], "browser_action": {