├── .gitignore
├── CNAME
├── .eslintignore
├── src
├── img
│ ├── icon-16.png
│ ├── icon-48.png
│ ├── icon-128.png
│ └── coande-200.png
├── css
│ ├── iconfont
│ │ ├── iconfont.eot
│ │ ├── iconfont.ttf
│ │ ├── iconfont.woff
│ │ ├── iconfont.woff2
│ │ ├── iconfont.css
│ │ ├── demo.css
│ │ ├── demo_index.html
│ │ ├── iconfont.svg
│ │ └── iconfont.js
│ ├── base.css
│ ├── options.css
│ ├── youdao.css
│ ├── baidu.css
│ ├── google.css
│ ├── kingsoft.css
│ ├── sogou.css
│ └── extension.css
├── lib
│ ├── youdao-web-translate
│ │ └── web2
│ │ │ ├── styles
│ │ │ ├── cover.css
│ │ │ └── all-packed.css
│ │ │ ├── images
│ │ │ ├── bar-sp.png
│ │ │ ├── swipe_hr.png
│ │ │ ├── ydd_tip.png
│ │ │ ├── switch_button.png
│ │ │ ├── bar-sp-repeat-x.png
│ │ │ ├── switch_button_hover.png
│ │ │ ├── trans_tip_submit_bg.png
│ │ │ └── trans_tip_submit_bg_hover.png
│ │ │ ├── seed.js
│ │ │ ├── JTRAssist.swf
│ │ │ └── conn.html
│ ├── hot-reload.js
│ └── loadCSS.js
├── js
│ ├── popup-ga.js
│ ├── options-ga.js
│ ├── trans-css.js
│ ├── iframe-messager.js
│ ├── utils.js
│ ├── ext-data.js
│ ├── ga.js
│ ├── fake-navigator.js
│ ├── options.js
│ ├── popup.js
│ ├── background.js
│ └── content-script.js
├── background.html
├── options.html
└── popup.html
├── .editorconfig
├── .eslintrc.js
├── package.json
├── README.md
├── manifest.json
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/CNAME:
--------------------------------------------------------------------------------
1 | co-trans-ext.e12e.com
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | lib
2 | iconfont
3 |
--------------------------------------------------------------------------------
/src/img/icon-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/img/icon-16.png
--------------------------------------------------------------------------------
/src/img/icon-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/img/icon-48.png
--------------------------------------------------------------------------------
/src/img/icon-128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/img/icon-128.png
--------------------------------------------------------------------------------
/src/img/coande-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/img/coande-200.png
--------------------------------------------------------------------------------
/src/css/iconfont/iconfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/css/iconfont/iconfont.eot
--------------------------------------------------------------------------------
/src/css/iconfont/iconfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/css/iconfont/iconfont.ttf
--------------------------------------------------------------------------------
/src/css/iconfont/iconfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/css/iconfont/iconfont.woff
--------------------------------------------------------------------------------
/src/css/iconfont/iconfont.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/css/iconfont/iconfont.woff2
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/styles/cover.css:
--------------------------------------------------------------------------------
1 | /* 部分网页把iframe隐藏掉了,如Google */
2 | iframe.OUTFOX_JTR_BAR {
3 | display: block !important;
4 | }
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/bar-sp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/bar-sp.png
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/swipe_hr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/swipe_hr.png
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/ydd_tip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/ydd_tip.png
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/switch_button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/switch_button.png
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/bar-sp-repeat-x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/bar-sp-repeat-x.png
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/switch_button_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/switch_button_hover.png
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/trans_tip_submit_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/trans_tip_submit_bg.png
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/images/trans_tip_submit_bg_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Coande/co-trans-ext/HEAD/src/lib/youdao-web-translate/web2/images/trans_tip_submit_bg_hover.png
--------------------------------------------------------------------------------
/src/js/popup-ga.js:
--------------------------------------------------------------------------------
1 | // 谷歌分析
2 | function ga(...args) {
3 | args.push({
4 | page: '/popup.html'
5 | });
6 | const bg = chrome.extension.getBackgroundPage();
7 | bg.ga(...args);
8 | }
9 |
10 | ga('send', 'pageview');
11 |
--------------------------------------------------------------------------------
/src/js/options-ga.js:
--------------------------------------------------------------------------------
1 | // 谷歌分析
2 | function ga(...args) {
3 | args.push({
4 | page: '/options.html'
5 | });
6 | const bg = chrome.extension.getBackgroundPage();
7 | bg.ga(...args);
8 | }
9 |
10 | ga('send', 'pageview');
11 |
--------------------------------------------------------------------------------
/src/css/base.css:
--------------------------------------------------------------------------------
1 | ::-webkit-scrollbar {/*滚动条整体样式*/
2 | width: 10px; /*高宽分别对应横竖滚动条的尺寸*/
3 | height: 10px;
4 | }
5 | ::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
6 | background: rgba(3, 169, 244, 0.9);
7 | }
8 | ::-webkit-scrollbar-track {/*滚动条里面轨道*/
9 | background: #B3E5FC;
10 | }
11 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: https://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Unix-style newlines with a newline ending every file
7 | [*]
8 | end_of_line = lf
9 | insert_final_newline = true
10 | charset = utf-8
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: true,
4 | es6: true
5 | },
6 | extends: 'airbnb-base',
7 | globals: {
8 | Atomics: 'readonly',
9 | SharedArrayBuffer: 'readonly'
10 | },
11 | parserOptions: {
12 | ecmaVersion: 2018
13 | },
14 | rules: {
15 | 'no-undef': 'off',
16 | 'comma-dangle': ['error', { functions: 'ignore' }],
17 | 'no-plusplus': 'off',
18 | 'no-prototype-builtins': 'off',
19 | 'prefer-destructuring': 'off'
20 | }
21 | };
22 |
--------------------------------------------------------------------------------
/src/background.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | 背景页 - co-trans-ext
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "co-trans-ext",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "directories": {
7 | "lib": "lib"
8 | },
9 | "scripts": {
10 | "test": "echo \"Error: no test specified\" && exit 1",
11 | "lint": "eslint ."
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "git+https://github.com/Coande/co-trans-ext.git"
16 | },
17 | "author": "",
18 | "license": "GPL-3.0",
19 | "bugs": {
20 | "url": "https://github.com/Coande/co-trans-ext/issues"
21 | },
22 | "homepage": "https://github.com/Coande/co-trans-ext#readme",
23 | "devDependencies": {
24 | "eslint": "^5.16.0",
25 | "eslint-config-airbnb-base": "^13.1.0",
26 | "eslint-plugin-import": "^2.17.3"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/js/trans-css.js:
--------------------------------------------------------------------------------
1 | (function loadCustomCss() {
2 | const url = new URL(window.location.href);
3 | const origin = url.origin;
4 | switch (origin) {
5 | case 'https://fanyi.sogou.com':
6 | loadCSS('https://cdn.jsdelivr.net/gh/Coande/co-trans-ext@master/src/css/sogou.css');
7 | break;
8 | case 'https://fanyi.baidu.com':
9 | loadCSS('https://cdn.jsdelivr.net/gh/Coande/co-trans-ext@master/src/css/baidu.css');
10 | break;
11 | case 'https://translate.google.cn':
12 | loadCSS('https://cdn.jsdelivr.net/gh/Coande/co-trans-ext@master/src/css/google.css');
13 | break;
14 | case 'https://m.youdao.com':
15 | loadCSS('https://cdn.jsdelivr.net/gh/Coande/co-trans-ext@master/src/css/youdao.css');
16 | break;
17 | case 'https://m.iciba.com':
18 | loadCSS('https://cdn.jsdelivr.net/gh/Coande/co-trans-ext@master/src/css/kingsoft.css');
19 | break;
20 |
21 | default:
22 | break;
23 | }
24 | }());
25 |
--------------------------------------------------------------------------------
/src/js/iframe-messager.js:
--------------------------------------------------------------------------------
1 | // iframe页面通讯
2 | // https://www.cnblogs.com/syll/p/8640329.html
3 | // 接收iframe外部通过postMessage传递过来的数据
4 | window.addEventListener('message', (event) => {
5 | if (event.data.op === 'showDetail') {
6 | document.body.classList.add('trans-ext-detail');
7 | } else if (event.data.op === 'hideDetail') {
8 | document.body.classList.remove('trans-ext-detail');
9 | }
10 | });
11 |
12 | window.addEventListener('message', (event) => {
13 | if (event.data.changeTransTool) {
14 | const keyword = $('#textarea-source').val() || $('#j-textarea').val()
15 | || $('#source').val() || $('#index-input-main').val() || $('#formInput').val() || $('#trans-input').val();
16 | window.parent.postMessage({ changeTransTool: event.data.changeTransTool, keyword: keyword || '' }, '*');
17 | }
18 | });
19 |
20 | // 接收query上的数据并判断是否需要显示输入内容和语言切换等
21 | const isShowDetail = getQueryVariable(window.location.href, 'showDetail');
22 | if (isShowDetail === 'true') {
23 | document.body.classList.add('trans-ext-detail');
24 | } else {
25 | document.body.classList.remove('trans-ext-detail');
26 | }
27 |
--------------------------------------------------------------------------------
/src/css/options.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-size: 14px;
3 | font-family: "lucida sans unicode", lucida, helvetica, "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
4 | -webkit-font-smoothing: antialiased;
5 | color: #555555;
6 | margin: 0;
7 | }
8 |
9 | input[type='checkbox'] {
10 | vertical-align: top;
11 | }
12 |
13 | a {
14 | text-decoration: none;
15 | color: #03a9f4;
16 | }
17 |
18 | .page-wrapper {
19 | padding: 20px;
20 | width: 600px;
21 | margin: 0 auto;
22 | }
23 |
24 | .para + .para {
25 | margin-top: 30px;
26 | }
27 |
28 | .para__title {
29 | font-size: 20px;
30 | color: #333333;
31 | margin-bottom: 10px;
32 | }
33 |
34 | .reward__button {
35 | display: inline-block;
36 | height: 24px;
37 | line-height: 24px;
38 | margin-left: 10px;
39 | background: #03a9f4;
40 | padding: 0 6px;
41 | color: #ffffff;
42 | }
43 | .reward__list {
44 | width: 600px;
45 | height: 101px;
46 | margin-top: 10px;
47 | }
48 |
49 | .reward__list-iframe {
50 | display: block;
51 | width: 100%;
52 | height: 100%;
53 | border: none;
54 | }
55 |
56 | .already-latest,
57 | .not-latest {
58 | display: none;
59 | }
--------------------------------------------------------------------------------
/src/css/youdao.css:
--------------------------------------------------------------------------------
1 | /* 有时候顶部会出现app广告 */
2 | div[style="position: absolute; top: 0px; left: 0px; z-index: 201;"] {
3 | display: none !important;
4 | }
5 |
6 | /* 出现顶部app广告时会有个margin-top */
7 | .p-dict {
8 | margin-top: 0 !important;
9 | }
10 |
11 | /* 页面头部,分词典和翻译,但是翻译不能用了,一律隐藏掉 */
12 | .nav-label {
13 | display: none !important;
14 | }
15 |
16 | /* 搜索内容输入框 */
17 | body:not(.trans-ext-detail) .search-area {
18 | display: none;
19 | }
20 |
21 | /* 基本释义右上角纠错按钮 */
22 | .ec h2 .amend {
23 | display: none;
24 | }
25 |
26 | /* 底部App广告 */
27 | .dict-dl {
28 | display: none !important;
29 | }
30 |
31 | /* 脚本备案信息 */
32 | #ft {
33 | display: none;
34 | }
35 |
36 | /* 发音喇叭下面的音频大小 */
37 | .speech-size {
38 | display: none;
39 | }
40 |
41 | /* 没有keyword时的页面 */
42 | /* 顶部App广告 */
43 | div[style*="position: fixed; top: 0px; left: 0px;"] {
44 | display: none;
45 | }
46 |
47 | .logo {
48 | display: none;
49 | }
50 |
51 | body {
52 | margin-top: 0 !important;
53 | }
54 |
55 | .other-links {
56 | display: none;
57 | }
58 |
59 | /* 有时候会有全屏广告 */
60 | div[style*="position: absolute; width: 100%; height: 100%; z-index: 201; top: 0px; left: 0px;"] {
61 | display: none !important;
62 | }
--------------------------------------------------------------------------------
/src/css/baidu.css:
--------------------------------------------------------------------------------
1 | /* 网页头部 */
2 | .fanyi-sfr-container .header#shoubai-header {
3 | display: none !important;
4 | }
5 | .fanyi-sfr-container #new-header {
6 | display: none !important;
7 | }
8 |
9 | .fanyi-sfr-container .topnav-new {
10 | top: 0 !important;
11 | }
12 | /* 底部广告 */
13 | .jifeng-container {
14 | display: none !important;
15 | }
16 |
17 | /* 语言选择栏 */
18 | body:not(.trans-ext-detail) .fanyi-sfr-container .translang {
19 | /* 自动检测语言(如检测为中文)时,语言栏切换动画依赖该元素的可见性,
20 | display 隐藏后会导致页面无法正常加载,所以设置 height 为 0 来隐藏元素 */
21 | /* display: none !important; */
22 | height: 0px;
23 | overflow: hidden;
24 | }
25 |
26 | /* 内容输入框 */
27 | body:not(.trans-ext-detail) .fanyi-sfr-container .trans-input {
28 | display: none;
29 | }
30 |
31 | /* 页面底部百度翻译app广告 */
32 | .fanyi-sfr-container .bottom-intro {
33 | display: none !important;
34 | }
35 |
36 | /* 翻译结果下面的百度翻译app广告 */
37 | .fanyi-sfr-container .app-bar {
38 | display: none !important;
39 | }
40 |
41 | /* 翻译来源条(如结果来自金山词霸) */
42 | .fanyi-sfr-container .concise-dict .dict-origin-wrap {
43 | display: none !important;
44 | }
45 |
46 | /* 如果关键字为空时,会在底部显示英文文章 */
47 | .fanyi-sfr-container .article {
48 | display: none !important;
49 | }
50 |
--------------------------------------------------------------------------------
/src/js/utils.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-unused-vars */
2 | // 动态加载css
3 | function loadCSS(file, id) {
4 | const linkObj = document.getElementById(id);
5 | if (linkObj) {
6 | return;
7 | }
8 | const link = document.createElement('link');
9 | link.href = file;
10 | link.id = id;
11 | link.type = 'text/css';
12 | link.rel = 'stylesheet';
13 | document.getElementsByTagName('head')[0].appendChild(link);
14 | }
15 |
16 | // 移除css
17 | function unloadCSS(id) {
18 | const cssNode = document.getElementById(id);
19 | if (cssNode) {
20 | cssNode.parentNode.removeChild(cssNode);
21 | }
22 | }
23 |
24 | // 获取 query 参数
25 | function getQueryVariable(url, variable) {
26 | const strArr = new URL(url).search.split('?');
27 | if (strArr[1]) {
28 | const query = strArr[1];
29 | const vars = query.split('&');
30 | for (let i = 0; i < vars.length; i++) {
31 | const pair = vars[i].split('=');
32 | if (pair[0] === variable) {
33 | return pair[1];
34 | }
35 | }
36 | }
37 | return undefined;
38 | }
39 |
40 | // iframe 异步加载
41 | function loadIframeSrc(iframeObj, src) {
42 | const iframe = iframeObj[0] || iframeObj;
43 | setTimeout(() => {
44 | iframe.setAttribute('src', src);
45 | }, 0);
46 | }
47 |
--------------------------------------------------------------------------------
/src/js/ext-data.js:
--------------------------------------------------------------------------------
1 | // 数据存储操作对象
2 | function ExtData() {}
3 |
4 | ExtData.prototype.set = (key, value, callback) => {
5 | chrome.storage.sync.set({ [key]: value }, () => {
6 | if (callback) callback();
7 | });
8 | this[key] = value;
9 | };
10 |
11 | ExtData.prototype.get = (key, callback) => {
12 | const defaultOptions = {
13 | transTool: 'sogou',
14 | sogou:
15 | 'https://fanyi.sogou.com/?keyword=KEYWORD&transfrom=auto&transto=zh-CHS&x-from=co-translate-extension&showDetail=SHOWDETAIL',
16 | baidu:
17 | 'https://fanyi.baidu.com/?x-from=co-translate-extension&showDetail=SHOWDETAIL#en/zh/KEYWORD',
18 | // Google 如果不用 https,会自动跳转到 https ,导致 query 数据丢失
19 | google:
20 | 'https://translate.google.cn/?x-from=co-translate-extension&showDetail=SHOWDETAIL#view=home&op=translate&sl=auto&tl=zh-CN&text=KEYWORD',
21 | youdao:
22 | 'https://m.youdao.com/dict?le=eng&q=KEYWORD&x-from=co-translate-extension&showDetail=SHOWDETAIL',
23 | kingsoft:
24 | 'https://m.iciba.com/KEYWORD?flag=searchBack&x-from=co-translate-extension&showDetail=SHOWDETAIL',
25 | isEnabledAnalytics: true
26 | };
27 | chrome.storage.sync.get([key], (result) => {
28 | if (result[key] === undefined) {
29 | callback(defaultOptions[key]);
30 | return;
31 | }
32 | callback(result[key]);
33 | });
34 | };
35 |
--------------------------------------------------------------------------------
/src/js/ga.js:
--------------------------------------------------------------------------------
1 | window.ga = window.ga
2 | // eslint-disable-next-line func-names
3 | || function () {
4 | // eslint-disable-next-line prefer-rest-params
5 | (ga.q = ga.q || []).push(arguments);
6 | };
7 | ga.l = +new Date();
8 |
9 | /** ************************* 初始化内容 ********************** */
10 | const propertyID = 'UA-65836121-2';
11 | ga('create', propertyID, 'auto');
12 | // 以下必须设置,否则会检查协议,默认只支持http和https
13 | ga('set', 'checkProtocolTask', null);
14 |
15 | // 只要设置 appVersion,Google Analytics 就接收不到数据,是一个bug。只要自定义一个维度。
16 | // https://stackoverflow.com/questions/36508241/how-do-i-set-appversion-for-google-analytics-event-tracking
17 | // ga('set', 'appVersion', chrome.runtime.getManifest().version);
18 | ga('set', 'dimension1', chrome.runtime.getManifest().version);
19 |
20 | // 设置是否停用
21 | function setIsDisableGA(isDisable) {
22 | window[`ga-disable-${propertyID}`] = isDisable;
23 | }
24 |
25 | // 判断是否需要禁用
26 | const data = new ExtData();
27 | data.get('isEnabledAnalytics', (isEnable) => {
28 | setIsDisableGA(!isEnable);
29 | });
30 |
31 | /** ************************* 功能函数 *********************** */
32 |
33 | // 运行时记录
34 | // 必须设置路径,否则谷歌分析拒绝接收 chrome-extension 协议路径
35 | ga('send', 'pageview', '/background.html');
36 |
37 | // 监听从 content-script 传递过来的事件
38 | chrome.extension.onRequest.addListener((request) => {
39 | if (request.ga) {
40 | ga(...request.ga);
41 | }
42 | });
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # co-trans-ext
2 | 
3 |
4 | **co-trans-ext** 是一个集搜狗翻译、百度翻译、有道翻译、金山词霸、谷歌翻译于一体的翻译扩展。各平台可随时切换,取长补短,更适合于阅读各领域的文档。不止于翻译,解析详细,更利于对各门语言的深入学习与理解。支持划词翻译和网页翻译。项目地址:[https://github.com/Coande/co-trans-ext](https://github.com/Coande/co-trans-ext)
5 |
6 |
7 | 
8 |
9 | 
10 |
11 | 
12 |
13 |
14 | ## 下载
15 |
16 | [**进入下载页**](https://github.com/Coande/co-trans-ext/releases/)
17 |
18 | ## 安装
19 |
20 | #### 方法一
21 | 适用于 Chrome 第三方浏览器,如 [360极速浏览器](https://browser.360.cn/ee/)。直接拖拽 crx 文件到浏览器窗口即可安装。另外,360极速浏览器还可以直接从[360极速浏览器扩展中心](https://ext.chrome.360.cn/webstore/detail/keigenoolicjcehlbpjcfhdjdmaochie)进行安装。
22 |
23 | #### 方法二
24 | 适用于 Google Chrome 及 Chrome 第三方浏览器,可以从[chrome 网上应用店
25 | ](https://chrome.google.com/webstore/detail/co-trans-ext-%E7%BF%BB%E8%AF%91%E5%B7%A5%E5%85%B7/ncfklglegjceemdfaiblepihhlkoafge?utm_source=chrome-ntp-icon)(需自备梯子)进行安装。
26 |
27 | #### 方法三
28 | 适用于 Google Chrome,由于新版本 Google Chrome 限制了非 Chrome 应用商店内扩展的安装,而当前翻译扩展由于个人原因暂未上架 Chrome 应用商店,所以安装起来略麻烦,并不推荐。操作如下:
29 |
30 | - clone 本项目到本地
31 | - 地址栏输入 `chrome://extensions/` 打开扩展管理页面
32 | - 开启 `开发者模式` / `Developer mode`
33 | - `加载已解压的扩展程序` / `Load unpacked`,选择本项目以加载扩展
34 |
35 |
36 | ## 致谢
37 |
38 | 感谢以下朋友的 PR:
39 | [Teemwu](https://github.com/Teemwu)
40 |
41 | 欢迎大家提 PR 和反馈 issue
42 |
--------------------------------------------------------------------------------
/src/css/google.css:
--------------------------------------------------------------------------------
1 | /* 页面头部 */
2 | header.gb_sa {
3 | display: none !important;
4 | }
5 |
6 | /* 页面内容高度调整(原来是页面高度减去了页头高度) */
7 | .frame {
8 | height: 100% !important;
9 | }
10 |
11 | /* 语言选择区 */
12 | body:not(.trans-ext-detail) .ls-wrap {
13 | display: none;
14 | }
15 |
16 | /* 内容输入区 */
17 | body:not(.trans-ext-detail) #input-wrap {
18 | display: none;
19 | }
20 |
21 | /* 内容输入区工具条 */
22 | body:not(.trans-ext-detail) .source-header {
23 | display: none;
24 | }
25 |
26 | /* 包裹内容输入区和发音区的元素 */
27 | body:not(.trans-ext-detail) .source-input {
28 | padding: 0 !important;
29 | }
30 |
31 | /* 内容输入区下语音工具栏定位 */
32 | body:not(.trans-ext-detail) .source-or-target-footer {
33 | position: relative !important;
34 | bottom: auto !important;
35 | left: auto !important;
36 | }
37 |
38 | /* 音标 */
39 | body:not(.trans-ext-detail) .transliteration-container {
40 | margin-top: 0 !important;
41 | }
42 |
43 | /* 语音输入按钮 */
44 | body:not(.trans-ext-detail) .source-or-target-footer-button.speech-wrap {
45 | display: none !important;
46 | }
47 |
48 | /* 输入内容框右下方手写输入按钮 */
49 | .source-input-tools {
50 | display: none !important;
51 | }
52 |
53 | /* 翻译结果右下角更多按钮(包含反馈和分享) */
54 | .more-wrapper {
55 | display: none;
56 | }
57 |
58 | /* 底部反馈按钮 */
59 | .feedback-link {
60 | display: none;
61 | }
62 |
63 | /* 底部历史记录按钮 */
64 | .gp-footer {
65 | display: none;
66 | }
67 |
68 | /* 历史记录即将停用的通知 */
69 | .notification-area {
70 | display: none;
71 | }
72 |
73 | /* 顶部菜单 */
74 | #gb > div.gb_1d.gb_je.gb_ae.gb_9d {
75 | display: none !important;
76 | }
77 |
--------------------------------------------------------------------------------
/src/lib/hot-reload.js:
--------------------------------------------------------------------------------
1 | // Chrome Extension Hot Reloader
2 | // https://github.com/xpl/crx-hotreload
3 |
4 | const filesInDirectory = dir =>
5 | new Promise(resolve =>
6 | dir.createReader().readEntries(entries =>
7 | Promise.all(
8 | entries
9 | .filter(e => e.name[0] !== '.')
10 | .map(e =>
11 | e.isDirectory
12 | ? filesInDirectory(e)
13 | : new Promise(resolve => e.file(resolve))
14 | )
15 | )
16 | .then(files => [].concat(...files))
17 | .then(resolve)
18 | )
19 | );
20 |
21 | const timestampForFilesInDirectory = dir =>
22 | filesInDirectory(dir).then(files =>
23 | files.map(f => f.name + f.lastModifiedDate).join()
24 | );
25 |
26 | const reload = () => {
27 | chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
28 | // NB: see https://github.com/xpl/crx-hotreload/issues/5
29 |
30 | if (tabs[0]) {
31 | chrome.tabs.reload(tabs[0].id);
32 | }
33 |
34 | chrome.runtime.reload();
35 | });
36 | };
37 |
38 | const watchChanges = (dir, lastTimestamp) => {
39 | timestampForFilesInDirectory(dir).then(timestamp => {
40 | if (!lastTimestamp || lastTimestamp === timestamp) {
41 | setTimeout(() => watchChanges(dir, timestamp), 1000); // retry after 1s
42 | } else {
43 | reload();
44 | }
45 | });
46 | };
47 |
48 | chrome.management.getSelf(self => {
49 | if (self.installType === 'development') {
50 | chrome.runtime.getPackageDirectoryEntry(dir => watchChanges(dir));
51 | }
52 | });
53 |
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/seed.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | var b = function() {
3 | var l = new Image();
4 | l.src =
5 | '//fanyi.youdao.com/web2/rl.do?keyfrom=chromeext&action=w_try&' +
6 | new Date().getTime();
7 | };
8 | var c = 'fanyi.youdao.com',
9 | i = '/web2/';
10 | if (window.location.host === c && window.location.pathname === i) {
11 | b();
12 | alert('请在浏览英文网页时使用有道网页翻译2.0');
13 | return;
14 | }
15 | if (
16 | !(
17 | window.location.protocol == 'http:' ||
18 | window.location.protocol == 'https:'
19 | )
20 | ) {
21 | alert('请在浏览网页时使用有道网页翻译2.0');
22 | return;
23 | }
24 | var h = '//fanyi.youdao.com/web2';
25 | if (!window.OUTFOX_JavascriptTranslatoR) {
26 | var e = document.createElement('script');
27 | e.setAttribute(
28 | 'src',
29 | // h + '/scripts/all-packed-utf-8.js?242748M&' + Date.parse(new Date())
30 | // 需要使用本地文件,本地的文件添加了https的支持
31 | chrome.extension.getURL(
32 | 'src/lib/youdao-web-translate/web2/scripts/all-packed-utf-8.js'
33 | )
34 | );
35 | e.setAttribute('type', 'text/javascript');
36 | e.setAttribute('charset', 'utf-8');
37 | document.body.appendChild(e);
38 | } else {
39 | var j = '//fanyi.youdao.com';
40 | var a = '/web2/conn.html';
41 | var k = h + '/index.do';
42 | var g = j + '/jtr';
43 | var d = h + '/rl.do';
44 | var f = h + '/styles/all-packed.css';
45 | J.loadCSS(document, f);
46 | window.OUTFOX_JavascriptTranslatoR = new J.TR.UI(document.body, {
47 | domain: j,
48 | update: false,
49 | updateTipMsg: '增加关闭按钮',
50 | updateDate: '2011-3-15',
51 | cssURL: f,
52 | tipsURL: k,
53 | transURL: g,
54 | logURL: d,
55 | connFilePath: a,
56 | reqSize: 20
57 | });
58 | }
59 | })();
60 |
--------------------------------------------------------------------------------
/src/js/fake-navigator.js:
--------------------------------------------------------------------------------
1 | // 欺骗js获取的 navigator.userAgent(有道中有个判断,不欺骗会跳转网页)
2 | // https://stackoverflow.com/questions/23202136/changing-navigator-useragent-using-chrome-extension
3 |
4 | const actualCode = `(${
5 | () => {
6 | const navigator = window.navigator;
7 | let modifiedNavigator;
8 | if ('userAgent' in Navigator.prototype) {
9 | // Chrome 43+ moved all properties from navigator to the prototype,
10 | // so we have to modify the prototype instead of navigator.
11 | modifiedNavigator = Navigator.prototype;
12 | } else {
13 | // Chrome 42- defined the property on navigator.
14 | modifiedNavigator = Object.create(navigator);
15 | Object.defineProperty(window, 'navigator', {
16 | value: modifiedNavigator,
17 | configurable: false,
18 | enumerable: false,
19 | writable: false
20 | });
21 | }
22 | // Pretend to be Windows XP
23 | Object.defineProperties(modifiedNavigator, {
24 | userAgent: {
25 | value:
26 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
27 | configurable: false,
28 | enumerable: true,
29 | writable: false
30 | },
31 | appVersion: {
32 | value:
33 | '5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
34 | configurable: false,
35 | enumerable: true,
36 | writable: false
37 | },
38 | platform: {
39 | value: 'Win32',
40 | configurable: false,
41 | enumerable: true,
42 | writable: false
43 | }
44 | });
45 | }
46 | })();`;
47 |
48 | const s = document.createElement('script');
49 | s.textContent = actualCode;
50 | document.documentElement.appendChild(s);
51 | s.remove();
52 |
--------------------------------------------------------------------------------
/src/options.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | 选项页 - co-trans-ext
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | 选项
16 |
17 |
18 |
19 |
20 |
21 | 版本
22 |
23 |
当前版本:
,
24 | 最新版本:
获取中...
25 |
,已经是最新版
26 |
,可更新
27 |
28 |
29 |
30 |
31 | 关于
32 |
33 |
co-trans-ext 是一个集搜狗翻译、百度翻译、谷歌翻译、有道翻译、金山词霸于一体的浏览器翻译扩展。有任何问题或建议,欢迎随时发送到我邮箱 e12e#qq.com (#替换为@)。
34 |
35 | 如果您觉得不错,
赞赏 一下我吧。以下为该项目赞赏记录:
36 |
37 |
38 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/popup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | popup 页 - co-trans-ext
8 |
9 |
11 |
24 |
25 |
26 |
30 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/css/kingsoft.css:
--------------------------------------------------------------------------------
1 | /* 顶部导航 */
2 | .body-week-up .nav {
3 | display: none;
4 | }
5 |
6 | /* 输入区域 */
7 | .index-main {
8 | top: 0 !important;
9 | }
10 |
11 | /* 修正输入框文字不垂直居中问题 */
12 | .index-input-main {
13 | padding: 0 6px 0 0.3611111111rem !important;
14 | }
15 |
16 | .index-top .index-main {
17 | top: 0 !important;
18 | }
19 | body:not(.trans-ext-detail) .index-top .index-main {
20 | display: none !important;
21 | }
22 |
23 | /* 翻译结果有margin-top */
24 | body.trans-ext-detail {
25 | margin-top: 0;
26 | }
27 |
28 | body.trans-ext-detail .index .result {
29 | margin-top: 59px !important;
30 | }
31 |
32 | body:not(.trans-ext-detail) .index .result {
33 | margin-top: 0 !important;
34 | }
35 |
36 | /* 底部悬浮App广告 */
37 | .dic-follow {
38 | display: none !important;
39 | }
40 | /* 去掉广告后的空白 */
41 | #dic {
42 | padding-bottom: 0 !important;
43 | }
44 |
45 | /* 打开app查看全部按钮 */
46 | .dic-more {
47 | display: none !important;
48 | }
49 |
50 | /* 牛津词典,需要app中才能用 */
51 | .dic-nav li:nth-child(2) {
52 | display: none;
53 | }
54 | .dic-nav-tab li:nth-child(2) {
55 | display: none;
56 | }
57 |
58 |
59 | /* 柯林斯 词典 */
60 | /* app广告 */
61 | .download-text {
62 | display: none !important;
63 | }
64 | /* 去掉广告后的空白 */
65 | .dic-collins {
66 | padding-bottom: .6944444444rem !important;
67 | }
68 |
69 |
70 | /* 当没有关键词时 */
71 | /* 页头padding */
72 | .index-bg {
73 | padding-top: 0 !important;
74 | }
75 |
76 | /* 底部广告 */
77 | .index-bg {
78 | display: none;
79 | }
80 |
81 | /* 网站备案号 */
82 | .record {
83 | display: none;
84 | }
85 |
86 | /* 偶尔会弹出全屏的App广告 */
87 | .download-swiper {
88 | display: none !important;
89 | }
90 |
91 | /* 输入时智能提示 */
92 | .index-cover-list-result {
93 | margin-top: 58px !important;
94 | }
95 |
96 | /* 跟读按钮(APP广告) */
97 | .dic-basic-voice img {
98 | display: none;
99 | }
100 |
101 | /* 音标下的 APP 广告 */
102 | .dic-recommend {
103 | display: none;
104 | }
105 |
106 | /* 页脚 app 广告 */
107 | .dic-info {
108 | display: none;
109 | }
110 |
111 | .dic-bottom-list {
112 | display: none !important;
113 | }
114 |
115 | .dic-bottom-btn {
116 | display: none;
117 | }
118 |
119 | /* 高考讲解tab底部广告 */
120 | .dic-echart-mask {
121 | display: none;
122 | }
123 |
--------------------------------------------------------------------------------
/src/lib/youdao-web-translate/web2/JTRAssist.swf:
--------------------------------------------------------------------------------
1 | CWSi x�W�S������[`li$X�`/e�B�){� [���)j�z,Œ�̌���c*���=�c�{�I��R�������������Ww�~���^#�3Bѿ"��(C�!���}�do���j�ۄ�ge�?��dNOOӧ�i�}��nlld�\&�[���[�W�ލ���@�{E�r�W�zJ�������B�j��3z�p���R1ë��뾗ɦ�`�Tܴ�f�[��q�R�������_�Z'|ŮZ^�~�BP���ʷ�K�O��uj-�}�H�E�p��[}״�v���2ǮSj�L6�
2 | ��U����Q�╹�ը��;��@�*d�.�|�D�&�U���a��[;�ڽupF��[��zju9�3���)�~F8���
3 | ����c�?[y����峽8�V�?f�J;'aO���]9Xur�����N������������NqKz�TJ�=��;�}�֭*� �ל~i�x��b�U���exGM�N�J�:�r��X%�"� r��Æ�;�/��< ��ʁ��%.N���B�/4c=/>���U:�Ep�l�JO ��r��)�5zx��9�������̫�����z6���ڗ(U��u���+ώ~Nj�`��<�,�I2 � ���GXE�r����!��+w'��)�;Qn� ��Ր�uY��=���~�m�I�ƈʈ�p��0�F��Ę<��0SFe�8cL�bd���L���������%�ށX���X�8I��s7���
4 | ��PB���6�D^`���������(�j�����@Ӏ���&��R��bk�3'0��Ԧ�D�V�Y��b,ӄ���f�ڴ�"-�F��D�zF'�F�M�0~:� 4њ4��a�2#v���s����xLJ����n�fk�ma-�Rfl7��Z�?�9��<]����aK"��6�l����
s�1L��
s�5̤�4̄���BS��<
5 | �n�^� ��E�"㣠��H���]r��&�G��"��L��F*�5q]�]��&Lv��p�d�5�cU��&2ÔI�-����.�"���b-c h���m��v��<`�OL���Z̤��P���`�˯ K���}*��ݏz�+z�:������>�i�^tJ����%˷H�����=$�4R��F�:����`�����O��J��e�� ?
#��e~}u��5\t��a�g���_�S�������Ovv��A�블�Xո_v��T���v���qσ�E��)�[����*}�l����s���/��^^�N�Pv�����X����J�����ܡ�5#w�Ƒ�F6���Ҩ��CrR�Ա$�Dń2U��:�$Y@<�1��ad@@�cJ�) ����qF&�dp�0�b�.�7��)`����H�d��ղtE����I]��'��<����"u�p ԃe���a��ᙤ�ST�
6 | ��6""a��gD��a��T*�r�R{�ښU����/ ��IlbRS�e[)P\` �s�)�C� �7�/���q��T�
7 | @M?����5��ۚ��5����s<��s��5��Do�r\��|3�g�7ɱ�
A �ɭ1X�s7����8,Q���V�5!(0$KiM�/�^U
8 | �P-����l͎=����ǽ�5�#��-�%�N
���7�<å*���]��V�tJUZ���_���ߡ�*#��(����"�