// ==UserScript== // @name 语言切换快捷键|适配大部分在线翻译网站 // @namespace https://github.com/CandyTek // @version 1.1 // @license MIT // @description 语言切换快捷键 Ctrl + Shift + S // @author CandyTek // @match *://translate.yandex.com/?* // @match *://zh.pons.com/* // @match *://fanyi.so.com/* // @match *://fanyi.xfyun.cn/console/trans/* // @match *://translate.volcengine.com/* // @match *://translation.imtranslator.net/* // @match *://www.iciba.com/translate* // @match *://fanyi.baidu.com/* // @match *://dictionary.cambridge.org/* // @match *://www.baidu.com/s?* // @match *://fanyi.youdao.com/* // @match *://www.deepl.com/* // @match *://translation2.paralink.com/* // @match *://cn.bing.com/search?* // @match *://cn.bing.com/translator?* // @match *://fanyi.sogou.com/text?* // @match *://www.amz123.com/tools-translate/sougou // @match *://fanyi.caiyunapp.com/* // @match *://niutrans.com/trans?* // @match *://translate.alibaba.com/* // @match *://dict.eudic.net/home/translation // @match *://www.fanyi1234.com/lang/* // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iIzAwMDAwMCI+PHBhdGggZD0iTTAgMGgyNHYyNEgweiIgZmlsbD0ibm9uZSIvPjxwYXRoIGQ9Ik02Ljk5IDExTDMgMTVsMy45OSA0di0zSDE0di0ySDYuOTl2LTN6TTIxIDlsLTMuOTktNHYzSDEwdjJoNy4wMXYzTDIxIDl6Ii8+PC9zdmc+ // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @run-at document-end // @downloadURL https://update.greasyfork.icu/scripts/452326/%E8%AF%AD%E8%A8%80%E5%88%87%E6%8D%A2%E5%BF%AB%E6%8D%B7%E9%94%AE%EF%BD%9C%E9%80%82%E9%85%8D%E5%A4%A7%E9%83%A8%E5%88%86%E5%9C%A8%E7%BA%BF%E7%BF%BB%E8%AF%91%E7%BD%91%E7%AB%99.user.js // @updateURL https://update.greasyfork.icu/scripts/452326/%E8%AF%AD%E8%A8%80%E5%88%87%E6%8D%A2%E5%BF%AB%E6%8D%B7%E9%94%AE%EF%BD%9C%E9%80%82%E9%85%8D%E5%A4%A7%E9%83%A8%E5%88%86%E5%9C%A8%E7%BA%BF%E7%BF%BB%E8%AF%91%E7%BD%91%E7%AB%99.meta.js // ==/UserScript== // 网站规则列表 const myMatchWebsites = [ { // https://translate.yandex.com/?source_lang=en&target_lang=zh match: ["*://translate.yandex.com/?*"], button:"[aria-label=\"Switch direction\"]", }, { // https://zh.pons.com/%E7%BF%BB%E8%AF%91/ match: ["*://zh.pons.com/*"], button:"[data-e2e=\"switch-language\"]", }, { // https://fanyi.so.com/# match: ["*://fanyi.so.com/*"], button:".exchange", }, { // https://fanyi.xfyun.cn/console/trans/text match: ["*://fanyi.xfyun.cn/console/trans/*"], button:".anticon-swap", }, { // https://translate.volcengine.com/ match: ["*://translate.volcengine.com/*"], button:".reverse-img", }, { // https://translation.imtranslator.net/ match: ["*://translation.imtranslator.net/*"], button:"[title=\"Change translation direction of a selected language pair\"]", }, { // https://www.iciba.com/translate match: ["*://www.iciba.com/translate*"], button:".select_exchange__AfzH4", }, { // fanyi.baidu.com match: ["*://fanyi.baidu.com/*"], button:"svg.mg3bUrpQ", }, { // https://dictionary.cambridge.org/zhs/%E8%AF%8D%E5%85%B8/%E8%8B%B1%E8%AF%AD-%E6%B1%89%E8%AF%AD-%E7%B9%81%E4%BD%93/exchange match: ["*://dictionary.cambridge.org/*"], button:".i-exchange", }, { // https://www.baidu.com/s?tn=68018901_3_dg&ie=UTF-8&wd=%E7%BF%BB%E8%AF%91%E7%BD%91%E7%AB%99 match: ["*://www.baidu.com/s?*"], button:".op_translation_exchange_img", }, { // https://fanyi.youdao.com/#/ match: ["*://fanyi.youdao.com/*"], button:".ic_language_exchange", }, { // https://fanyi.sogou.com/text?keyword=&transfrom=en&transto=zh-CHS&model=general&exchange=true match: ["*://fanyi.sogou.com/*"], button:".btn-switch", }, { // https://www.deepl.com/zh/translator match: ["*://www.deepl.com/*"], button:"[data-testid=\"lmt_language_switch\"]", }, { // https://translation2.paralink.com/ match: ["*://translation2.paralink.com/*"], button:"#switch", }, { // https://cn.bing.com/search?q=%E4%BD%A0%E5%A5%BD%20%E8%8B%B1%E8%AF%AD%E7%BF%BB%E8%AF%91 match: ["*://cn.bing.com/search?*","*://cn.bing.com/translator?*"], button:"#tta_revIcon", }, // { // // https://www.amz123.com/tools-translate/sougou // match: ["*://www.amz123.com/tools-translate/sougou"], // button:".btn-switch", // iframe:"#translate", // }, { // https://fanyi.caiyunapp.com/ match: ["*://fanyi.caiyunapp.com/*"], button:".changeImg", }, { // https://niutrans.com/trans?type=text match: ["*://niutrans.com/trans?*"], button:".nt-icon-qiehuan", }, { // https://translate.alibaba.com/ match: ["*://translate.alibaba.com/*"], button:".anticon-swap", }, { // https://dict.eudic.net/home/translation match: ["*://dict.eudic.net/home/translation"], button:".switchBtn", }, { // https://www.fanyi1234.com/lang/ match: ["*://www.fanyi1234.com/lang/*"], button:"[alt=\"转换\"]", }, ]; /** 设置工具类 */ class CandyTekPreferenceUtil { /** 是否已向网页添加过设置面板了 */ isAlreadyAddSettingPanel = false; /** 设置面板根元素 */ rootShadow = null; /** 存放设置值的地方。获取 prefValues[key] */ prefValues; /** 源 pref 配置数组 */ preferenceList; constructor(preferenceList) { this.preferenceList = preferenceList; this.refreshPrefValues(); } /** 刷新设置值 */ refreshPrefValues() { this.prefValues = this.preferenceList.reduce((list, curr) => { list[curr.preference] = GM_getValue(curr.preference, curr.defaultValue); return list; }, {}); } /** 获取设置值 */ get(key) { return this.prefValues.hasOwnProperty(key) ? this.prefValues[key] : GM_getValue(key, ""); } /** 写入设置值,未适配 boolean */ set(key, value) { GM_setValue(key, value); this.prefValues[key] = value; } /** 显示设置面板在网页右上角 */ show() { if (this.isAlreadyAddSettingPanel) { this.rootShadow.querySelector(".setting_panel").style.display = "block"; return; } if (!document.body.createShadowRoot) { console.warn("可能不能创建 ShadowRoot"); //return; } // 创建设置面板 const host = document.createElement('div'); host.id = "simplify_article_settings_panel"; document.body.appendChild(host); const root = host.attachShadow({ mode: 'open' }); this.rootShadow = root; this.isAlreadyAddSettingPanel = true; root.innerHTML = `
设置