From 621adb19abff2606cc3e7b638d00bedc04e13602 Mon Sep 17 00:00:00 2001 From: ververcpp Date: Wed, 4 Nov 2015 22:37:30 +0800 Subject: [PATCH] update to ver 0.8.19 --- CHANGELOG.md | 12 +++ manifest.json | 6 +- options.html | 10 ++ package.json | 2 +- popup.html | 12 ++- public/css/inPage.min.css | 2 +- public/css/style.min.css | 2 +- public/js/background.min.js | 2 +- public/js/popup.min.js | 2 +- public/js/selection.min.js | 2 +- public/js/utility.min.js | 2 +- src/inPage.css | 21 +++-- src/inPage.css.map | 2 +- src/javascript/background.js | 33 ++++--- src/javascript/popup.js | 29 ++++-- src/javascript/selection.js | 177 ++++++++++++++++------------------- src/javascript/utility.js | 12 ++- src/sass/inPage.scss | 28 +++--- src/style.css | 10 +- 19 files changed, 212 insertions(+), 154 deletions(-) create mode 100644 options.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 835f79c..c143c8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +###ver 0.8.19 ++ 修改边栏显示的查词结果被某些网页导航条遮挡的 bug + +###ver 0.8.18 ++ 由于有道的 https 接口连接不稳定,默认改为 http 接口,添加接口的可选项 + +###ver 0.8.17 ++ 临时版本,暂时修复可能存在的几个 bug + +###ver 0.8.16 ++ 优化划词选词正则规则 + ###ver 0.8.15 + 修改 shift 事件没有绑定动态生成元素的 bug (issue #13) diff --git a/manifest.json b/manifest.json index c4504ad..f6e4ea4 100644 --- a/manifest.json +++ b/manifest.json @@ -2,18 +2,22 @@ "manifest_version": 2, "name": "ChaZD", - "version": "0.8.15", + "version": "0.8.19", "description": "ChaZD 查字典,简洁易用的英汉字典扩展程序,支持划词哦:)", "permissions": [ "https://dict.youdao.com/*", "https://fanyi.youdao.com/*", + "http://dict.youdao.com/*", + "http://fanyi.youdao.com/*", "contextMenus", "tabs", "storage", "notifications" ], + "options_page": "options.html", + "background": { "persistent": true, "scripts": [ "public/js/utility.min.js", "public/js/background.min.js" ] diff --git a/options.html b/options.html new file mode 100644 index 0000000..d458a07 --- /dev/null +++ b/options.html @@ -0,0 +1,10 @@ + + + + + ChaZD Options + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 9adada4..c7b08ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ChaZD", - "version": "0.8.15", + "version": "0.8.19", "description": "A Chinese-English translator extension for Chrome", "main": null, "scripts": { diff --git a/popup.html b/popup.html index 12146ab..a24962a 100644 --- a/popup.html +++ b/popup.html @@ -18,14 +18,20 @@ Tips: 你可以通过“Ctrl+Shift+F”快速启动词典, 也可以在这里自定义快捷键哦:)

+

+ Tips 2: 如出现无法查词的问题,请在设置中关闭使用 HTTPS 接口 +

不再显示Tips
- -
- (鼠标悬停查看说明) + + (鼠标悬停查看说明) +
+
+ + (说明)

diff --git a/public/css/inPage.min.css b/public/css/inPage.min.css index 55b5081..a6d0f79 100644 --- a/public/css/inPage.min.css +++ b/public/css/inPage.min.css @@ -1 +1 @@ -@charset "UTF-8";@-webkit-keyframes fade-in{from{opacity:0}to{opacity:1}}@-moz-keyframes fade-in{from{opacity:0}to{opacity:1}}@-o-keyframes fade-in{from{opacity:0}to{opacity:1}}@keyframes fade-in{from{opacity:0}to{opacity:1}}@-webkit-keyframes fade-out{from{opacity:1}to{opacity:0}}@-moz-keyframes fade-out{from{opacity:1}to{opacity:0}}@-o-keyframes fade-out{from{opacity:1}to{opacity:0}}@keyframes fade-out{from{opacity:1}to{opacity:0}}.ChaZD-result-side{position:fixed!important;right:10px;top:5px}.ChaZD-result-container{width:250px;overflow:auto;text-shadow:none;background-color:#ffd;text-align:left;color:#222;padding:10px;margin:0;opacity:1;border:1px solid #999;border-radius:4px;z-index:999997;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;position:absolute;line-height:normal;box-shadow:0 0 20px rgba(0,0,0,.5);-webkit-box-shadow:0 0 20px rgba(0,0,0,.5);-webkit-animation:fade-in .3s ease;-moz-animation:fade-in .3s ease;-o-animation:fade-in .3s ease;animation:fade-in .3s ease}.ChaZD-result-container #ChaZD-searching{border:none;padding:0;margin:0}.ChaZD-result-container .title-container{background-color:#ffd;border:none;color:#222;display:block;max-width:100%}.ChaZD-result-container .title-container .title-word{position:relative;max-width:100%;text-align:left;font-size:18px}.ChaZD-result-container .title-container .title-word .voice-container{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVQ4y2P4//8/AyUYQhAH3gNxA7IAIQPmo/H3g/QA8XkgFiBkwHyoYnRQABVfj88AmGZcTuuHyjlgMwBZM7IE3NlQGhQe65EN+I8Dw8MLGgYoFpFqADK/YUAMwOsFigORatFIlYRElaRMWmaiBAMAp0n+3U0kqkAAAAAASUVORK5CYII=);background-position:bottom center;background-repeat:no-repeat;cursor:pointer;opacity:.5;width:16px;height:16px;margin-left:8px;display:inline-block;position:relative;top:2px}.ChaZD-result-container .title-container .title-word .voice-container:hover{opacity:1}.ChaZD-result-container .title-container .title-translation{display:none;color:#222;margin-top:10px}.ChaZD-result-container .basic-container{background-color:#ffd;border:none}.ChaZD-result-container .basic-container .phonetic-container div{display:inline-block;color:red;margin-right:5px}.ChaZD-result-container .basic-container .phonetic-container .uk-phonetic-container:before{content:'英';color:#222;font-size:12px;margin-right:2px}.ChaZD-result-container .basic-container .phonetic-container .us-phonetic-container:before{content:'美';color:#222;font-size:12px;margin-right:2px}.ChaZD-result-container .basic-container .explains-container{font-size:14px;margin-top:10px}.ChaZD-result-container .basic-container .explains-container .explains-list{list-style:none;margin:0;padding:0}.ChaZD-result-container .basic-container .explains-container .explains-list li{padding:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;margin:0 0 5px;list-style:none;font-size:14px}.ChaZD-result-container .basic-container .explains-container .explains-list li:before{display:none}.ChaZD-result-container .basic-container .explains-container .explains-list li span{display:block;overflow:hidden}.ChaZD-result-container .basic-container .explains-container .property-container{display:block;float:left;font-weight:700;color:#222;margin-right:5px}.ChaZD-result-container .basic-container .explains-container .voice-container{display:none}.ChaZD-result-container .web-explains-container .web-title{font-weight:700;opacity:.7}.ChaZD-result-container .web-explains-container .web-explains-list{list-style:none;margin:5px 0;padding:0}.ChaZD-result-container .web-explains-container .web-explains-list li .web-value{margin:0 0 0 5px}.ChaZD-result-container .unshow{display:none}.ChaZD-arrow-main{position:absolute;z-index:999997;-webkit-animation:fade-in .3s ease;-moz-animation:fade-in .3s ease;-o-animation:fade-in .3s ease;animation:fade-in .3s ease}.ChaZD-arrow-outer-down,.ChaZD-arrow-outer-up{background:0 0;width:0;border-left:12px solid transparent;border-right:12px solid transparent;position:absolute;left:0}.ChaZD-arrow-outer-up{border-bottom:12px solid #999}.ChaZD-arrow-outer-down{border-top:12px solid #999}.ChaZD-arrow-inner-down,.ChaZD-arrow-inner-up{background:0 0;width:0;border-left:10px solid transparent;border-right:10px solid transparent;position:absolute;left:2px}.ChaZD-arrow-inner-up{border-bottom:10px solid #ffd;top:2px}.ChaZD-arrow-inner-down{border-top:10px solid #ffd}a.ChaZD-link{text-decoration:none!important;cursor:text!important} \ No newline at end of file +@charset "UTF-8";@-webkit-keyframes fade-in{from{opacity:0}to{opacity:1}}@-moz-keyframes fade-in{from{opacity:0}to{opacity:1}}@-o-keyframes fade-in{from{opacity:0}to{opacity:1}}@keyframes fade-in{from{opacity:0}to{opacity:1}}@-webkit-keyframes fade-out{from{opacity:1}to{opacity:0}}@-moz-keyframes fade-out{from{opacity:1}to{opacity:0}}@-o-keyframes fade-out{from{opacity:1}to{opacity:0}}@keyframes fade-out{from{opacity:1}to{opacity:0}}.ChaZD-result-side{position:fixed!important;right:10px;top:80px}.ChaZD-result-container{width:250px;overflow:auto;text-shadow:none;background-color:#ffd;text-align:left;color:#222;padding:10px;margin:0;opacity:1;border:1px solid #999;border-radius:4px;z-index:999997;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:400;font-size:14px;position:absolute;text-decoration:none;line-height:normal;box-shadow:0 0 20px rgba(0,0,0,.5);-webkit-box-shadow:0 0 20px rgba(0,0,0,.5);-webkit-animation:fade-in .3s ease;-moz-animation:fade-in .3s ease;-o-animation:fade-in .3s ease;animation:fade-in .3s ease}.ChaZD-result-container #ChaZD-searching{border:none;padding:0;margin:0}.ChaZD-result-container .title-container{background-color:#ffd;border:none;color:#222;display:block;max-width:100%}.ChaZD-result-container .title-container .title-word{position:relative;max-width:100%;text-align:left;font-size:18px}.ChaZD-result-container .title-container .title-word .voice-container{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVQ4y2P4//8/AyUYQhAH3gNxA7IAIQPmo/H3g/QA8XkgFiBkwHyoYnRQABVfj88AmGZcTuuHyjlgMwBZM7IE3NlQGhQe65EN+I8Dw8MLGgYoFpFqADK/YUAMwOsFigORatFIlYRElaRMWmaiBAMAp0n+3U0kqkAAAAAASUVORK5CYII=);background-position:bottom center;background-repeat:no-repeat;cursor:pointer;opacity:.5;width:16px;height:16px;margin-left:8px;display:inline-block;position:relative;top:2px}.ChaZD-result-container .title-container .title-word .voice-container:hover{opacity:1}.ChaZD-result-container .title-container .title-translation{display:none;color:#222;margin-top:10px}.ChaZD-result-container .basic-container{background-color:#ffd;border:none}.ChaZD-result-container .basic-container .phonetic-container .uk-phonetic-container,.ChaZD-result-container .basic-container .phonetic-container .us-phonetic-container{display:inline-block;color:red;margin-right:5px}.ChaZD-result-container .basic-container .phonetic-container .uk-phonetic-container:before{content:'英';color:#222;font-size:12px;margin-right:2px}.ChaZD-result-container .basic-container .phonetic-container .us-phonetic-container:before{content:'美';color:#222;font-size:12px;margin-right:2px}.ChaZD-result-container .basic-container .explains-container{font-size:14px;margin-top:10px}.ChaZD-result-container .basic-container .explains-container .explains-list{list-style:none;margin:0;padding:0}.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item{padding:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;margin:0 0 5px;list-style:none;font-size:14px;background-color:transparent}.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item:before{display:none}.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item .property-container{display:block;float:left;font-weight:700;color:#222;margin-right:5px}.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item .explains-item-value{display:block;overflow:hidden}.ChaZD-result-container .basic-container .explains-container .voice-container{display:none}.ChaZD-result-container .web-explains-container .web-title{font-weight:700;opacity:.7}.ChaZD-result-container .web-explains-container .web-explains-list{list-style:none;margin:5px 0;padding:0}.ChaZD-result-container .web-explains-container .web-explains-list li .web-value{margin:0 0 0 5px}.ChaZD-result-container .unshow{display:none}.ChaZD-arrow-main{position:absolute;z-index:999997;-webkit-animation:fade-in .3s ease;-moz-animation:fade-in .3s ease;-o-animation:fade-in .3s ease;animation:fade-in .3s ease}.ChaZD-arrow-outer-down,.ChaZD-arrow-outer-up{background:0 0;width:0;border-left:12px solid transparent;border-right:12px solid transparent;position:absolute;left:0}.ChaZD-arrow-outer-up{border-bottom:12px solid #999}.ChaZD-arrow-outer-down{border-top:12px solid #999}.ChaZD-arrow-inner-down,.ChaZD-arrow-inner-up{background:0 0;width:0;border-left:10px solid transparent;border-right:10px solid transparent;position:absolute;left:2px}.ChaZD-arrow-inner-up{border-bottom:10px solid #ffd;top:2px}.ChaZD-arrow-inner-down{border-top:10px solid #ffd}a.ChaZD-link{text-decoration:none!important;cursor:text!important} \ No newline at end of file diff --git a/public/css/style.min.css b/public/css/style.min.css index 1d5f5ff..adc013b 100644 --- a/public/css/style.min.css +++ b/public/css/style.min.css @@ -1 +1 @@ -@font-face{font-family:YDdict-Icon;src:url(fonts/YDdict-Icon-font.eot);src:url(fonts/YDdict-Icon-font.svg) format("svg"),url(fonts/YDdict-Icon-font.woff) format("woff");font-weight:400;font-style:normal}@keyframes slide-down{from{transform:scaleY(0);-webkit-transform:scaleY(0)}to{transform:scaleY(1);-webkit-transform:scaleY(1)}}@-webkit-keyframes slide-down{from{transform:scaleY(0);-webkit-transform:scaleY(0)}to{transform:scaleY(1);-webkit-transform:scaleY(1)}}@keyframes fade-in{from{opacity:0}to{opacity:1}}@-webkit-keyframes fade-in{from{opacity:0}to{opacity:1}}@keyframes fade-out{from{opacity:1}to{opacity:0;visibility:hidden}}@-webkit-keyframes fade-out{from{opacity:1}to{opacity:0;visibility:hidden}}@keyframes slide-up{from{transform:scaleY(1);-webkit-transform:scaleY(1)}to{transform:scaleY(0);-webkit-transform:scaleY(0)}}@-webkit-keyframes slide-up{from{transform:scaleY(1);-webkit-transform:scaleY(1)}to{transform:scaleY(0);-webkit-transform:scaleY(0)}}body{margin:.5em;padding:0;width:300px;background-color:#faf8ef;color:#776e65;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px}ul{list-style:none;margin:0;padding:0}.input-container{position:relative;margin:0;border:1px solid #dbd8e4;box-shadow:-.2px -.2px .2px .2px;border-radius:3px}.input-container:after{content:"";display:block;clear:both}.input-area{display:block;padding:2px;border:none;font-size:1.3em;width:270px;margin:1px 0 0 20px;border-radius:3px}.input-area:focus{outline:0}.query-button{display:block;height:100%;position:absolute;top:0;left:0;border:0;border-radius:1px;margin:0;padding:4px;background-color:transparent;line-height:19px;color:rgba(0,0,0,.2)}.query-button:focus{outline-color:transparent}.query-button:hover{color:rgba(0,0,0,1)}.query-button:active{color:rgba(235,0,0,1)}.query-button::after{content:'\E800';-webkit-transition:color .2s linear;transition:color .2s linear;font-size:.8em;font-family:YDdict-Icon}.result-container{margin-top:10px;padding:4px}.unshow{display:none}.title-container{margin-left:10px;display:flex;min-width:50%;max-width:100%;font-size:22px}.title-container.long-text{font-size:16px}.title-container .title-phonetic{display:none}.title-container .title-word{position:relative;max-width:50%;text-align:left}.title-container .title-word .voice-container{display:inline-block;margin-left:10px}.title-container .title-word .voice-container::after{content:'\E804';font-family:YDdict-Icon;font-size:70%}.title-container .title-translation{flex:1;margin-left:10px;text-align:justify;max-width:50%}.basic-container{margin-top:10px}.phonetic-container{margin-left:10px;font-size:1em}.uk-phonetic-container::before{content:"英 ";color:#776e65}.us-phonetic-container::before{content:"美 ";color:#776e65}.uk-phonetic-container,.us-phonetic-container{display:inline-block;margin-right:10px;color:red}.voice-container{cursor:pointer;display:inline-block;margin-left:10px;color:rgba(119,110,101,.2)}.voice-container::after{content:'\E803';font-family:YDdict-Icon;-webkit-transition:color .2s linear;transition:color .2s linear}.voice-container:hover{color:rgba(119,110,101,1)}.explains-container{font-size:14px;margin-top:10px}.explains-list{border:1px solid #F0EFF0;border-radius:1px;padding:10px}.explains-list li{margin-bottom:5px}.property-container{margin-right:5px}.web-explains-container{font-size:14px;margin-top:20px;position:relative}.web-title{position:absolute;top:-5px;left:10px;background-color:#faf8ef;font-weight:700}.web-title::before{content:'\E802';font-family:YDdict-Icon;margin-right:5px;color:#ccbb1e}.web-explains-list{border:1px solid #F0EFF0;border-radius:1px;padding:20px 10px 10px}.web-explains-list li{margin-bottom:5px}.web-explains-list li .web-key{font-weight:700}.web-explains-list li .web-value{margin-left:5px}.tips-container{position:relative;padding:5px;font-size:.4em;color:rgba(0,0,0,.4)}.tips-container p{margin:10px 0 0;padding:0}.tips-container .link{color:rgba(0,161,194,1);cursor:pointer;-webkit-transition:color .2s linear;transition:color .2s linear}#turn-off-tips{position:absolute;right:5px;bottom:5px;cursor:pointer;text-decoration:underline}footer{font-size:.3em;text-align:center;position:relative;color:rgba(0,0,0,.2)}footer img{position:relative;top:4px;width:50px;opacity:.6}.contact-info{font-size:.3em;font-family:YDdict-Icon;position:absolute;bottom:0;right:0}.link{cursor:pointer;text-decoration:none;color:rgba(0,0,0,.6);opacity:.5}.link:hover{color:rgba(0,0,0,1)}#score::after{content:'\E80B';-webkit-transition:color .2s linear;transition:color .2s linear}#email::after{content:'\E806';-webkit-transition:color .2s linear;transition:color .2s linear}#issue::after{content:'\E805';-webkit-transition:color .2s linear;transition:color .2s linear}#source::after{content:'\E807';-webkit-transition:color .2s linear;transition:color .2s linear}.setting-button{position:absolute;bottom:0;left:0;cursor:pointer;font-size:.3em;font-family:YDdict-Icon}.setting-button-clicked{color:#000}.setting-button::after{content:"\E80A";-webkit-transition:color .2s linear;transition:color .2s linear}.setting-block{margin:5px 0;text-align:justify;border:0 solid #F0EFF0;border-radius:1px;background-color:#f2ecd4;max-height:0;height:0;overflow-y:hidden;color:#6e665e;transition:all .5s cubic-bezier(0,1,.5,1);-webkit-transition:all .5s cubic-bezier(0,1,.5,1)}.active{border:1px solid #F0EFF0;max-height:800px}.setting-slide-up{animation:fade-out .4s ease forwards;-webkit-animation:fade-out .4s ease forwards}.setting-slide-down{display:block;animation:fade-in .4s ease forwards;-webkit-animation:fade-in .4s ease forwards}.setting-block div{margin-top:5px;padding:1px 10px}.setting-block .top-menu{margin-bottom:5px}.setting-block .sub-menu{margin-top:5px}.setting-block .link-query-help{margin-left:18px;cursor:help}.setting-block label{margin-left:5px}.setting-block label.unactive{color:rgba(0,0,0,.5)}.setting-block input{margin:0}.setting-block .sub-title{margin-left:17px;font-size:90%}.setting-block .sub-button{margin-left:5px}.setting-block .sub-label{font-size:90%}#currentDuration{display:inline-block;width:14px;text-align:center}input[type=range]{width:100px;position:relative;top:3px}#save{position:absolute;top:0;right:0}#cancel{position:absolute;top:25px;right:0}hr.carved{clear:both;float:none;width:100%;height:2px;line-height:2px;font-size:0;margin:1.4em 0;border:none;background:#ddd;background:-webkit-gradient(linear,left top,left bottom,color-stop(0.5,#ddd),color-stop(0.5,#fff)) #ddd;background:-webkit-linear-gradient(center top,#ddd 50%,#fff 50%) #ddd;background:-o-linear-gradient(center top,#ddd 50%,#fff 50%) #ddd;background:-moz-linear-gradient(center top,#ddd 50%,#fff 50%) #ddd} \ No newline at end of file +@font-face{font-family:YDdict-Icon;src:url(fonts/YDdict-Icon-font.eot);src:url(fonts/YDdict-Icon-font.svg) format("svg"),url(fonts/YDdict-Icon-font.woff) format("woff");font-weight:400;font-style:normal}@keyframes slide-down{from{transform:scaleY(0);-webkit-transform:scaleY(0)}to{transform:scaleY(1);-webkit-transform:scaleY(1)}}@-webkit-keyframes slide-down{from{transform:scaleY(0);-webkit-transform:scaleY(0)}to{transform:scaleY(1);-webkit-transform:scaleY(1)}}@keyframes fade-in{from{opacity:0}to{opacity:1}}@-webkit-keyframes fade-in{from{opacity:0}to{opacity:1}}@keyframes fade-out{from{opacity:1}to{opacity:0;visibility:hidden}}@-webkit-keyframes fade-out{from{opacity:1}to{opacity:0;visibility:hidden}}@keyframes slide-up{from{transform:scaleY(1);-webkit-transform:scaleY(1)}to{transform:scaleY(0);-webkit-transform:scaleY(0)}}@-webkit-keyframes slide-up{from{transform:scaleY(1);-webkit-transform:scaleY(1)}to{transform:scaleY(0);-webkit-transform:scaleY(0)}}body{margin:.5em;padding:0;width:300px;background-color:#faf8ef;color:#776e65;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px}ul{list-style:none;margin:0;padding:0}.input-container{position:relative;margin:0;border:1px solid #dbd8e4;box-shadow:-.2px -.2px .2px .2px;border-radius:3px}.input-container:after{content:"";display:block;clear:both}.input-area{display:block;padding:2px;border:none;font-size:1.3em;width:270px;margin:1px 0 0 20px;border-radius:3px}.input-area:focus{outline:0}.query-button{display:block;height:100%;position:absolute;top:0;left:0;border:0;border-radius:1px;margin:0;padding:4px;background-color:transparent;line-height:19px;color:rgba(0,0,0,.2)}.query-button:focus{outline-color:transparent}.query-button:hover{color:rgba(0,0,0,1)}.query-button:active{color:rgba(235,0,0,1)}.query-button::after{content:'\E800';-webkit-transition:color .2s linear;transition:color .2s linear;font-size:.8em;font-family:YDdict-Icon}.result-container{margin-top:10px;padding:4px}.unshow{display:none}.title-container{margin-left:10px;display:flex;min-width:50%;max-width:100%;font-size:22px}.title-container.long-text{font-size:16px}.title-container .title-phonetic{display:none}.title-container .title-word{position:relative;max-width:50%;text-align:left}.title-container .title-word .voice-container{display:inline-block;margin-left:10px}.title-container .title-word .voice-container::after{content:'\E804';font-family:YDdict-Icon;font-size:70%}.title-container .title-translation{flex:1;margin-left:10px;text-align:justify;max-width:50%}.basic-container{margin-top:10px}.phonetic-container{margin-left:10px;font-size:1em}.uk-phonetic-container::before{content:"英 ";color:#776e65}.us-phonetic-container::before{content:"美 ";color:#776e65}.uk-phonetic-container,.us-phonetic-container{display:inline-block;margin-right:10px;color:red}.voice-container{cursor:pointer;display:inline-block;margin-left:10px;color:rgba(119,110,101,.2)}.voice-container::after{content:'\E803';font-family:YDdict-Icon;-webkit-transition:color .2s linear;transition:color .2s linear}.voice-container:hover{color:rgba(119,110,101,1)}.explains-container{font-size:14px;margin-top:10px}.explains-list{border:1px solid #F0EFF0;border-radius:1px;padding:10px}.explains-list li{margin-bottom:5px}.property-container{margin-right:5px}.web-explains-container{font-size:14px;margin-top:20px;position:relative}.web-title{position:absolute;top:-5px;left:10px;background-color:#faf8ef;font-weight:700}.web-title::before{content:'\E802';font-family:YDdict-Icon;margin-right:5px;color:#ccbb1e}.web-explains-list{border:1px solid #F0EFF0;border-radius:1px;padding:20px 10px 10px}.web-explains-list li{margin-bottom:5px}.web-explains-list li .web-key{font-weight:700}.web-explains-list li .web-value{margin-left:5px}.tips-container{position:relative;padding:5px;font-size:.4em;color:rgba(0,0,0,.4)}.tips-container p{margin:5px 0 0;padding:0}.tips-container .link{color:rgba(0,161,194,1);cursor:pointer;-webkit-transition:color .2s linear;transition:color .2s linear}#turn-off-tips{position:absolute;right:5px;bottom:5px;cursor:pointer;text-decoration:underline}footer{font-size:.3em;text-align:center;position:relative;color:rgba(0,0,0,.2)}footer img{position:relative;top:4px;width:50px;opacity:.6}.contact-info{font-size:.3em;font-family:YDdict-Icon;position:absolute;bottom:0;right:0}.link{cursor:pointer;text-decoration:none;color:rgba(0,0,0,.6);opacity:.5}.link:hover{color:rgba(0,0,0,1)}#score::after{content:'\E80B';-webkit-transition:color .2s linear;transition:color .2s linear}#email::after{content:'\E806';-webkit-transition:color .2s linear;transition:color .2s linear}#issue::after{content:'\E805';-webkit-transition:color .2s linear;transition:color .2s linear}#source::after{content:'\E807';-webkit-transition:color .2s linear;transition:color .2s linear}.setting-button{position:absolute;bottom:0;left:0;cursor:pointer;font-size:.3em;font-family:YDdict-Icon}.setting-button-clicked{color:#000}.setting-button::after{content:"\E80A";-webkit-transition:color .2s linear;transition:color .2s linear}.setting-block{margin:5px 0;text-align:justify;border:0 solid #F0EFF0;border-radius:1px;background-color:#f2ecd4;max-height:0;height:0;overflow-y:hidden;color:#6e665e;transition:all .5s cubic-bezier(0,1,.5,1);-webkit-transition:all .5s cubic-bezier(0,1,.5,1)}.active{border:1px solid #F0EFF0;max-height:800px}.setting-slide-up{animation:fade-out .4s ease forwards;-webkit-animation:fade-out .4s ease forwards}.setting-slide-down{display:block;animation:fade-in .4s ease forwards;-webkit-animation:fade-in .4s ease forwards}.setting-block div{margin-top:5px;padding:1px 10px}.setting-block .top-menu{margin-bottom:5px}.setting-block .sub-menu{margin-top:5px}.setting-block .link-query{margin-left:5px}.setting-block .help{font-size:12px;cursor:help}.setting-block label{margin-left:5px}.setting-block label.unactive{color:rgba(0,0,0,.5)}.setting-block input{margin:0}.setting-block .sub-title{margin-left:17px;font-size:90%}.setting-block .sub-button{margin-left:5px}.setting-block .sub-label{font-size:90%}#currentDuration{display:inline-block;width:14px;text-align:center}input[type=range]{width:100px;position:relative;top:3px}#save{position:absolute;top:0;right:0}#cancel{position:absolute;top:25px;right:0}hr.carved{clear:both;float:none;width:100%;height:2px;line-height:2px;font-size:0;margin:1.4em 0;border:none;background:#ddd;background:-webkit-gradient(linear,left top,left bottom,color-stop(0.5,#ddd),color-stop(0.5,#fff)) #ddd;background:-webkit-linear-gradient(center top,#ddd 50%,#fff 50%) #ddd;background:-o-linear-gradient(center top,#ddd 50%,#fff 50%) #ddd;background:-moz-linear-gradient(center top,#ddd 50%,#fff 50%) #ddd} \ No newline at end of file diff --git a/public/js/background.min.js b/public/js/background.min.js index 4d845e9..25e9a0e 100644 --- a/public/js/background.min.js +++ b/public/js/background.min.js @@ -1 +1 @@ -function ChaZD(a,b,c){this.wordSource=b;var d=urls.dict+a,e=this,f=new XMLHttpRequest;f.open("GET",d,!0),f.onreadystatechange=function(){if(4==f.readyState){var d=JSON.parse(f.responseText);if(-1===a.indexOf("-")||e.checkErrorCode(d.errorCode).error||e.haveTranslation(d)){var g=e.parseResult.call(e,d);c(g)}else new ChaZD(a.replace(/-/g," "),b,c)}},f.send()}function preprocessWord(a){return-1===a.indexOf(" ")&&(a=a.replace(/_/g," "),/[a-z]+/.test(a)&&(a=trim(a.replace(/([A-Z])/g," $1")))),a}function showNotification(a){if(Notifications){var b=null,c=Notifications.checkPermission();return 0===c?(b=Notifications.createNotification(a.icon||chrome.extension.getURL("icons/icon128.png"),a.title||"ChaZD 查字典",a.content),b.onclick=function(){window.open("https://chrome.google.com/webstore/detail/chazd/nkiipedegbhbjmajlhpegcpcaacbfggp")},b.show()):Notifications.requestPermission(),b}}ChaZD.prototype.checkErrorCode=function(a){var b={message:"",error:0,errorCode:0};switch(a){case 0:b.message="query success";break;case 20:b.message="要翻译的文本过长",b.error=1,b.errorCode=20;break;case 30:b.message="无法进行有效的翻译",b.error=1,b.errorCode=30;break;case 40:b.message="不支持的语言类型",b.error=1,b.errorCode=40;break;case 50:b.message="无效的key",b.error=1,b.errorCode=50;break;case 60:b.message="无辞典结果",b.error=1,b.errorCode=60}return b},ChaZD.prototype.parseResult=function(a){var b={},c=this.checkErrorCode(a.errorCode);if(b.haveWebTranslation=!1,c.error)b.errorCode=c.errorCode;else{var d=this.initTitle(a);if(b.titleBlock=d.titleBlock,b.haveTranslation=this.haveTranslation(a),void 0!==a.basic){var e=this.parseBasicResult(a);b.basicBlock=e}if(void 0!==a.web){var f=this.parseWebResult(a);b.haveWebTranslation=!0,b.webBlock=f}}return b.validMessage=c.message,b},ChaZD.prototype.haveTranslation=function(a){if(this.checkErrorCode(a.errorCode).error)return!1;var b=a.translation,c=a.query;return trim(c.toLowerCase())===trim(b.toString().toLowerCase())?!1:!0},ChaZD.prototype.initTitle=function(a){var b=a.translation,c=a.query,d=this.initVoice(c);c=c.length>=50&&"select"==this.wordSource?this.shortWord(c):c;var e=fmt(frame.titleWord,c,d),f=fmt(frame.titleTranslation,b.toString());return{titleBlock:fmt(frame.titleContainer,e,f,c.length>=50?"long-text":"")}},ChaZD.prototype.shortWord=function(a){return a.slice(0,a.lastIndexOf(" ",50)).concat(" ...")},ChaZD.prototype.parseBasicResult=function(a){var b=a.basic,c=a.query,d=this.parseBasicPhonetic(b,c),e=this.parseBasicExplains(b,c),f=fmt(frame.basicContainer,d,e);return f},ChaZD.prototype.parseBasicPhonetic=function(a,b){var c=a["uk-phonetic"],d=a["us-phonetic"];if(void 0!==c&&void 0!==d){var e=this.initVoice(b,1),f=fmt(frame.ukPhoneticContainer,"["+c+"]"+e),g=this.initVoice(b,2),h=fmt(frame.usPhoneticContainer,"["+d+"]"+g);return fmt(frame.phoneticContainer,f,h)}return fmt(frame.phoneticContainer,"","")},ChaZD.prototype.initVoice=function(a,b){var c=urls.voice+a;void 0!==b&&(c=c+"&type="+b);var d="";return d=1===b?"英音":2===b?"美音":"真人发音",fmt(frame.voiceContainer,c,d)},ChaZD.prototype.parseBasicExplains=function(a){var b,c=a.explains,d="";for(b=0;b=50&&"select"==this.wordSource?this.shortWord(c):c;var e=fmt(frame.titleWord,c,d),f=fmt(frame.titleTranslation,b.toString());return{titleBlock:fmt(frame.titleContainer,e,f,c.length>=50?"long-text":"")}},ChaZD.prototype.shortWord=function(a){return a.slice(0,a.lastIndexOf(" ",50)).concat(" ...")},ChaZD.prototype.parseBasicResult=function(a){var b=a.basic,c=a.query,d=this.parseBasicPhonetic(b,c),e=this.parseBasicExplains(b,c),f=fmt(frame.basicContainer,d,e);return f},ChaZD.prototype.parseBasicPhonetic=function(a,b){var c=a["uk-phonetic"],d=a["us-phonetic"];if(void 0!==c&&void 0!==d){var e=this.initVoice(b,1),f=fmt(frame.ukPhoneticContainer,"["+c+"]"+e),g=this.initVoice(b,2),h=fmt(frame.usPhoneticContainer,"["+d+"]"+g);return fmt(frame.phoneticContainer,f,h)}return fmt(frame.phoneticContainer,"","")},ChaZD.prototype.initVoice=function(a,b){var c=(this.useHttps?urls.voiceHttps:urls.voice)+a;void 0!==b&&(c=c+"&type="+b);var d="";return d=1===b?"英音":2===b?"美音":"真人发音",fmt(frame.voiceContainer,c,d)},ChaZD.prototype.parseBasicExplains=function(a){var b,c=a.explains,d="";for(b=0;b词典君正在翻译。。。"),a?($input.value=a,chrome.extension.sendMessage({queryWord:a,source:"popup"},buildResult)):chrome.extension.sendMessage({queryWord:$input.value,source:"popup"},buildResult)}function buildVoice(a){var b=a.getAttribute("data-src"),c=document.createElement("audio");c.setAttribute("src",b),a.appendChild(c),c.addEventListener("ended",function(){this.load()}),a.addEventListener("click",function(){c.play()})}function createLink(a,b){a.addEventListener("click",function(){chrome.tabs.create({url:b})})}function totalHeight(a){for(var b=document.getElementsByClassName(a),c=b.length,d=0,e=0;c>e;e++)d+=b[e].scrollHeight;return d+10}var $button=document.querySelector("#search"),$tipsContainer=document.querySelector("#tips"),$input=document.querySelector("#query-word"),$queryResultContainer=document.querySelector("#query-result");-1!==window.navigator.platform.toLowerCase().indexOf("mac")&&(document.querySelector("#ctrl-option").firstChild.nodeValue="Command"),$tipsContainer.classList.contains("unshow")||$tipsContainer.classList.add("unshow");var buildResult=function(a){var b=a,c="";if("query success"==b.validMessage){c+=b.titleBlock,void 0!==b.basicBlock&&(c+=b.basicBlock),void 0!==b.webBlock&&(c+=b.webBlock),$queryResultContainer.innerHTML=c;var d,e,f=document.querySelectorAll(".voice-container");for(d=0,e=f.length;e>d;d++)buildVoice(f[d])}else $queryResultContainer.innerHTML=20==b.errorCode?"

这段文字太长,词典君无能为力了(┬_┬)

试试短一点的吧~

":40==b.errorCode?"

对不起,这段文字太高深了,请饶过词典君吧(┬_┬)

":"

词典君罢工啦(┬_┬)

是不是网络不太好?

稍后再试一次吧

"};$button.addEventListener("click",function(){queryInPopup()}),$input.select(),$input.addEventListener("input",function(){var a=$input.value;setTimeout(function(){$input.value===a&&""!==$input.value&&queryInPopup()},500)});var issue=document.querySelector("#issue"),email=document.querySelector("#email"),source=document.querySelector("#source"),keySet=document.querySelector("#key-set"),score=document.querySelector("#score");createLink(email,"mailto:ververcpp@gmail.com"),createLink(source,"https://github.com/ververcpp/ChaZD"),createLink(issue,"https://github.com/ververcpp/ChaZD/issues/new"),createLink(keySet,"chrome://extensions/configureCommands"),createLink(score,"https://chrome.google.com/webstore/detail/chazd/nkiipedegbhbjmajlhpegcpcaacbfggp"),document.querySelector("#setting-button").addEventListener("click",function(){var a=document.getElementById("settings");a.classList.toggle("active"),a.style.height=a.classList.contains("active")?blockHeight+"px":0});var blockHeight=totalHeight("top-menu")+totalHeight("sub-menu")+totalHeight("carved")+32,linkQuery=document.querySelector("#linkQuery"),noSelect=document.querySelector("#noSelect"),mouseSelect=document.querySelector("#mouseSelect"),useCtrl=document.querySelector("#useCtrl"),autoAudio=document.querySelector("#autoAudio"),defaultUk=document.querySelector("#defaultUk"),defaultUs=document.querySelector("#defaultUs"),showPositionSide=document.querySelector("#showPositionSide"),showPositionNear=document.querySelector("#showPositionNear"),autoHide=document.querySelector("#autoHide"),showDuration=document.querySelector("#showDuration"),currentDuration=document.querySelector("#currentDuration"),turnOffTips=document.querySelector("#turn-off-tips"),tips=document.querySelector("#tips"),toggleKey=document.querySelector("#toggle-key");chrome.storage.sync.get(null,function(a){""!==a.currentWord&&queryInPopup(a.currentWord),a.linkQuery===!0?(linkQuery.checked=!0,linkQuery.nextSibling.classList.remove("unactive")):(linkQuery.checked=!1,linkQuery.nextSibling.classList.add("unactive")),a.autoAudio===!0?(autoAudio.checked=!0,autoAudio.nextSibling.classList.remove("unactive")):(autoAudio.checked=!1,autoAudio.nextSibling.classList.add("unactive")),1===a.defaultVoice?(defaultUk.checked=!0,defaultUk.nextSibling.classList.remove("unactive"),defaultUs.nextSibling.classList.add("unactive")):2===a.defaultVoice&&(defaultUs.checked=!0,defaultUs.nextSibling.classList.remove("unactive"),defaultUk.nextSibling.classList.add("unactive")),"noSelect"===a.selectMode&&(noSelect.checked=!0,noSelect.nextSibling.classList.remove("unactive"),mouseSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.add("unactive"),toggleKey.disabled=!0,autoAudio.disabled=!0),"mouseSelect"===a.selectMode&&(mouseSelect.checked=!0,mouseSelect.nextSibling.classList.remove("unactive"),noSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.add("unactive"),toggleKey.disabled=!0,autoAudio.disabled=!1),"useCtrl"===a.selectMode&&(useCtrl.checked=!0,useCtrl.nextSibling.classList.remove("unactive"),noSelect.nextSibling.classList.add("unactive"),mouseSelect.nextSibling.classList.add("unactive"),toggleKey.disabled=!1,autoAudio.disabled=!1),a.showTips&&tips.classList.remove("unshow"),"side"===a.showPosition?(showPositionSide.checked=!0,showPositionSide.nextSibling.classList.remove("unactive"),showPositionNear.nextSibling.classList.add("unactive")):"near"===a.showPosition&&(showPositionNear.checked=!0,showPositionSide.nextSibling.classList.add("unactive"),showPositionNear.nextSibling.classList.remove("unactive")),"ctrl"===a.toggleKey?toggleKey.selectedIndex=0:"alt"===a.toggleKey?toggleKey.selectedIndex=1:"shift"===a.toggleKey&&(toggleKey.selectedIndex=2),a.autoHide===!0?(autoHide.checked=!0,autoHide.nextSibling.classList.remove("unactive"),showDuration.disabled=!1):(autoHide.checked=!1,autoHide.nextSibling.classList.add("unactive"),showDuration.disabled=!0),currentDuration.innerHTML=showDuration.value=a.showDuration}),linkQuery.addEventListener("click",function(){var a=linkQuery.checked;linkQuery.nextSibling.classList.toggle("unactive"),chrome.storage.sync.set({linkQuery:a},function(){})}),autoAudio.addEventListener("click",function(){var a=autoAudio.checked;a?autoAudio.nextSibling.classList.remove("unactive"):autoAudio.nextSibling.classList.add("unactive"),chrome.storage.sync.set({autoAudio:a},function(){})}),defaultUk.addEventListener("click",function(){defaultUk.nextSibling.classList.remove("unactive"),defaultUs.nextSibling.classList.add("unactive"),chrome.storage.sync.set({defaultVoice:1},function(){})}),defaultUs.addEventListener("click",function(){defaultUs.nextSibling.classList.remove("unactive"),defaultUk.nextSibling.classList.add("unactive"),chrome.storage.sync.set({defaultVoice:2},function(){})}),turnOffTips.addEventListener("click",function(){tips.classList.add("unshow"),chrome.storage.sync.set({showTips:!1},function(){})}),noSelect.addEventListener("click",function(){toggleKey.disabled=!0,autoAudio.disabled=!0,noSelect.nextSibling.classList.remove("unactive"),mouseSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.add("unactive"),chrome.storage.sync.set({selectMode:"noSelect"},function(){})}),mouseSelect.addEventListener("click",function(){toggleKey.disabled=!0,autoAudio.disabled=!1,noSelect.nextSibling.classList.add("unactive"),mouseSelect.nextSibling.classList.remove("unactive"),useCtrl.nextSibling.classList.add("unactive"),chrome.storage.sync.set({selectMode:"mouseSelect"},function(){})}),useCtrl.addEventListener("click",function(){toggleKey.disabled&&(toggleKey.disabled=!1),autoAudio.disabled=!1,noSelect.nextSibling.classList.add("unactive"),mouseSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.remove("unactive"),chrome.storage.sync.set({selectMode:"useCtrl"},function(){})}),showPositionSide.addEventListener("click",function(){showPositionSide.nextSibling.classList.remove("unactive"),showPositionNear.nextSibling.classList.add("unactive"),chrome.storage.sync.set({showPosition:"side"},function(){})}),showPositionNear.addEventListener("click",function(){showPositionSide.nextSibling.classList.add("unactive"),showPositionNear.nextSibling.classList.remove("unactive"),chrome.storage.sync.set({showPosition:"near"},function(){})}),autoHide.addEventListener("click",function(){var a=autoHide.checked;a?(autoHide.nextSibling.classList.remove("unactive"),showDuration.disabled=!1):(autoHide.nextSibling.classList.add("unactive"),showDuration.disabled=!0),chrome.storage.sync.set({autoHide:a},function(){})}),showDuration.addEventListener("input",function(){currentDuration.innerHTML=showDuration.value,chrome.storage.sync.set({showDuration:showDuration.value},function(){})}),toggleKey.onchange=function(){chrome.storage.sync.set({toggleKey:this.value},function(){})}; \ No newline at end of file +function queryInPopup(a){$queryResultContainer.classList.contains("unshow")&&$queryResultContainer.classList.remove("unshow"),""!==$input.value&&($queryResultContainer.innerHTML="ψ(._. )>词典君正在翻译。。。"),a?($input.value=a,chrome.extension.sendMessage({queryWord:a,source:"popup",useHttps:useHttpsValue},buildResult)):chrome.extension.sendMessage({queryWord:$input.value,source:"popup",useHttps:useHttpsValue},buildResult)}function buildVoice(a){var b=a.getAttribute("data-src"),c=document.createElement("audio");c.setAttribute("src",b),a.appendChild(c),c.addEventListener("ended",function(){this.load()}),a.addEventListener("click",function(){c.play()})}function createLink(a,b){a.addEventListener("click",function(){chrome.tabs.create({url:b})})}function totalHeight(a){for(var b=document.getElementsByClassName(a),c=b.length,d=0,e=0;c>e;e++)d+=b[e].scrollHeight;return d+10}var $button=document.querySelector("#search"),$input=document.querySelector("#query-word"),$queryResultContainer=document.querySelector("#query-result");-1!==window.navigator.platform.toLowerCase().indexOf("mac")&&(document.querySelector("#ctrl-option").firstChild.nodeValue="Command");var buildResult=function(a){var b=a,c="";if("query success"==b.validMessage){c+=b.titleBlock,void 0!==b.basicBlock&&(c+=b.basicBlock),void 0!==b.webBlock&&(c+=b.webBlock),$queryResultContainer.innerHTML=c;var d,e,f=document.querySelectorAll(".voice-container");for(d=0,e=f.length;e>d;d++)buildVoice(f[d])}else $queryResultContainer.innerHTML=20==b.errorCode?"

这段文字太长,词典君无能为力了(┬_┬)

试试短一点的吧~

":40==b.errorCode?"

对不起,这段文字太高深了,请饶过词典君吧(┬_┬)

":"

词典君罢工啦(┬_┬)

是不是网络不太好?

稍后再试一次吧

"};$button.addEventListener("click",function(){queryInPopup()}),$input.select(),$input.addEventListener("input",function(){var a=$input.value;setTimeout(function(){$input.value===a&&""!==$input.value&&queryInPopup()},500)});var issue=document.querySelector("#issue"),email=document.querySelector("#email"),source=document.querySelector("#source"),keySet=document.querySelector("#key-set"),score=document.querySelector("#score");createLink(email,"mailto:ververcpp@gmail.com"),createLink(source,"https://github.com/ververcpp/ChaZD"),createLink(issue,"https://github.com/ververcpp/ChaZD/issues/new"),createLink(keySet,"chrome://extensions/configureCommands"),createLink(score,"https://chrome.google.com/webstore/detail/chazd/nkiipedegbhbjmajlhpegcpcaacbfggp"),document.querySelector("#setting-button").addEventListener("click",function(){var a=document.getElementById("settings");a.classList.toggle("active"),a.style.height=a.classList.contains("active")?blockHeight+"px":0});var blockHeight=totalHeight("top-menu")+totalHeight("sub-menu")+totalHeight("carved")+32,linkQuery=document.querySelector("#linkQuery"),noSelect=document.querySelector("#noSelect"),mouseSelect=document.querySelector("#mouseSelect"),useCtrl=document.querySelector("#useCtrl"),autoAudio=document.querySelector("#autoAudio"),defaultUk=document.querySelector("#defaultUk"),defaultUs=document.querySelector("#defaultUs"),showPositionSide=document.querySelector("#showPositionSide"),showPositionNear=document.querySelector("#showPositionNear"),autoHide=document.querySelector("#autoHide"),showDuration=document.querySelector("#showDuration"),currentDuration=document.querySelector("#currentDuration"),turnOffTips=document.querySelector("#turn-off-tips"),tips=document.querySelector("#tips"),toggleKey=document.querySelector("#toggle-key"),useHttps=document.querySelector("#useHttps"),useHttpsValue=!1;chrome.storage.sync.get(null,function(a){""!==a.currentWord&&queryInPopup(a.currentWord),a.linkQuery===!0?(linkQuery.checked=!0,linkQuery.nextSibling.classList.remove("unactive")):(linkQuery.checked=!1,linkQuery.nextSibling.classList.add("unactive")),a.useHttps===!0?(useHttps.checked=!0,useHttpsValue=!0,useHttps.nextSibling.classList.remove("unactive")):(useHttps.checked=!1,useHttpsValue=!1,useHttps.nextSibling.classList.add("unactive")),a.autoAudio===!0?(autoAudio.checked=!0,autoAudio.nextSibling.classList.remove("unactive")):(autoAudio.checked=!1,autoAudio.nextSibling.classList.add("unactive")),1===a.defaultVoice?(defaultUk.checked=!0,defaultUk.nextSibling.classList.remove("unactive"),defaultUs.nextSibling.classList.add("unactive")):2===a.defaultVoice&&(defaultUs.checked=!0,defaultUs.nextSibling.classList.remove("unactive"),defaultUk.nextSibling.classList.add("unactive")),"noSelect"===a.selectMode&&(noSelect.checked=!0,noSelect.nextSibling.classList.remove("unactive"),mouseSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.add("unactive"),toggleKey.disabled=!0,autoAudio.disabled=!0),"mouseSelect"===a.selectMode&&(mouseSelect.checked=!0,mouseSelect.nextSibling.classList.remove("unactive"),noSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.add("unactive"),toggleKey.disabled=!0,autoAudio.disabled=!1),"useCtrl"===a.selectMode&&(useCtrl.checked=!0,useCtrl.nextSibling.classList.remove("unactive"),noSelect.nextSibling.classList.add("unactive"),mouseSelect.nextSibling.classList.add("unactive"),toggleKey.disabled=!1,autoAudio.disabled=!1),a.showTips&&tips.classList.remove("unshow"),"side"===a.showPosition?(showPositionSide.checked=!0,showPositionSide.nextSibling.classList.remove("unactive"),showPositionNear.nextSibling.classList.add("unactive")):"near"===a.showPosition&&(showPositionNear.checked=!0,showPositionSide.nextSibling.classList.add("unactive"),showPositionNear.nextSibling.classList.remove("unactive")),"ctrl"===a.toggleKey?toggleKey.selectedIndex=0:"alt"===a.toggleKey?toggleKey.selectedIndex=1:"shift"===a.toggleKey&&(toggleKey.selectedIndex=2),a.autoHide===!0?(autoHide.checked=!0,autoHide.nextSibling.classList.remove("unactive"),showDuration.disabled=!1):(autoHide.checked=!1,autoHide.nextSibling.classList.add("unactive"),showDuration.disabled=!0),currentDuration.innerHTML=showDuration.value=a.showDuration}),linkQuery.addEventListener("click",function(){var a=linkQuery.checked;linkQuery.nextSibling.classList.toggle("unactive"),chrome.storage.sync.set({linkQuery:a},function(){})}),useHttps.addEventListener("click",function(){var a=useHttps.checked;useHttps.nextSibling.classList.toggle("unactive"),chrome.storage.sync.set({useHttps:a})}),autoAudio.addEventListener("click",function(){var a=autoAudio.checked;a?autoAudio.nextSibling.classList.remove("unactive"):autoAudio.nextSibling.classList.add("unactive"),chrome.storage.sync.set({autoAudio:a},function(){})}),defaultUk.addEventListener("click",function(){defaultUk.nextSibling.classList.remove("unactive"),defaultUs.nextSibling.classList.add("unactive"),chrome.storage.sync.set({defaultVoice:1},function(){})}),defaultUs.addEventListener("click",function(){defaultUs.nextSibling.classList.remove("unactive"),defaultUk.nextSibling.classList.add("unactive"),chrome.storage.sync.set({defaultVoice:2},function(){})}),turnOffTips.addEventListener("click",function(){tips.classList.add("unshow"),chrome.storage.sync.set({showTips:!1},function(){})}),noSelect.addEventListener("click",function(){toggleKey.disabled=!0,autoAudio.disabled=!0,noSelect.nextSibling.classList.remove("unactive"),mouseSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.add("unactive"),chrome.storage.sync.set({selectMode:"noSelect"},function(){})}),mouseSelect.addEventListener("click",function(){toggleKey.disabled=!0,autoAudio.disabled=!1,noSelect.nextSibling.classList.add("unactive"),mouseSelect.nextSibling.classList.remove("unactive"),useCtrl.nextSibling.classList.add("unactive"),chrome.storage.sync.set({selectMode:"mouseSelect"},function(){})}),useCtrl.addEventListener("click",function(){toggleKey.disabled&&(toggleKey.disabled=!1),autoAudio.disabled=!1,noSelect.nextSibling.classList.add("unactive"),mouseSelect.nextSibling.classList.add("unactive"),useCtrl.nextSibling.classList.remove("unactive"),chrome.storage.sync.set({selectMode:"useCtrl"},function(){})}),showPositionSide.addEventListener("click",function(){showPositionSide.nextSibling.classList.remove("unactive"),showPositionNear.nextSibling.classList.add("unactive"),chrome.storage.sync.set({showPosition:"side"},function(){})}),showPositionNear.addEventListener("click",function(){showPositionSide.nextSibling.classList.add("unactive"),showPositionNear.nextSibling.classList.remove("unactive"),chrome.storage.sync.set({showPosition:"near"},function(){})}),autoHide.addEventListener("click",function(){var a=autoHide.checked;a?(autoHide.nextSibling.classList.remove("unactive"),showDuration.disabled=!1):(autoHide.nextSibling.classList.add("unactive"),showDuration.disabled=!0),chrome.storage.sync.set({autoHide:a},function(){})}),showDuration.addEventListener("input",function(){currentDuration.innerHTML=showDuration.value,chrome.storage.sync.set({showDuration:showDuration.value},function(){})}),toggleKey.onchange=function(){chrome.storage.sync.set({toggleKey:this.value},function(){})}; \ No newline at end of file diff --git a/public/js/selection.min.js b/public/js/selection.min.js index 6e2d03b..56ab3a8 100644 --- a/public/js/selection.min.js +++ b/public/js/selection.min.js @@ -1 +1 @@ -!function(){function a(a){var b=a.getAttribute("data-src"),c=document.createElement("audio");c.setAttribute("src",b+"&type="+q),a.appendChild(c),n===!0&&c.play(),c.addEventListener("ended",function(){this.load()}),a.addEventListener("click",function(){c.play()})}function b(a,b){return a.top===b.top&&a.bottom===b.bottom&&a.left===b.left&&a.right===b.right?!0:!1}var c,d={top:0,bottom:0,left:0,right:0,again:0},e=function(a){var c=window.getSelection&&window.getSelection();if(c&&c.rangeCount>0){var e=trim(c.toString()),h=c.getRangeAt(0).getBoundingClientRect();if(b(h,d)&&d.again)return void(d.again=0);if(""===e||!/[a-zA-Z\s]/.test(e))return;chrome.storage.sync.set({currentWord:e},function(){});for(var i in d)d[i]="again"==i?1:h[i];var j={};chrome.storage.sync.get(null,function(b){for(var c in b)j[c]=b[c];"side"==j.showPosition&&f(e),"near"==j.showPosition&&g(e,h,a)})}},f=function(a){var b=i(a);b.classList.add("ChaZD-result-side"),document.documentElement.appendChild(b),o&&(c=setTimeout(function(){document.querySelector(".ChaZD-result-container")&&document.documentElement.removeChild(b)},1e3*p))},g=function(a,b,d){var e=i(a),f=h();document.documentElement.appendChild(e),document.documentElement.appendChild(f);var g={};0===b.left&&0===b.top&&(b={left:d.clientX,top:d.clientY,height:15});var j=e.offsetWidth,k=b.right-b.left,l=b.left+window.pageXOffset,m=b.top+window.pageYOffset,n=k/2+l,q=l-(j-k)/2,r=n-12;qwindow.pageXOffset+document.documentElement.clientWidth&&(q=window.pageXOffset+document.documentElement.clientWidth-j);var s=0;if(s=document.documentElement.clientHeight>document.body.clientHeight?document.body.clientHeight:document.documentElement.clientHeight,0===s&&(s=document.documentElement.clientHeight),b.top>=150){var t=s-m+10,u=t+1;g={left:q,bottom:t,arrowLeft:r,arrowBottom:u}}else g={left:q,top:m+b.height+12,arrowLeft:r,arrowTop:m+b.height+1};e.style.left=g.left+"px",f.style.left=g.arrowLeft+"px";var v,w,x=document.querySelectorAll(".ChaZD-arrow-outer"),y=document.querySelectorAll(".ChaZD-arrow-inner");if(g.bottom)for(e.style.bottom=g.bottom+"px",f.style.bottom=g.arrowBottom+"px",v=0,w=x.length;w>v;v++)x[v].classList.add("ChaZD-arrow-outer-down"),y[v].classList.add("ChaZD-arrow-inner-down");if(g.top)for(e.style.top=g.top+"px",f.style.top=g.arrowTop+"px",v=0,w=x.length;w>v;v++)x[v].classList.add("ChaZD-arrow-outer-up"),y[v].classList.add("ChaZD-arrow-inner-up");o&&(c=setTimeout(function(){document.querySelector(".ChaZD-result-container")&&document.querySelector(".ChaZD-arrow-main")&&(document.documentElement.removeChild(e),document.documentElement.removeChild(f))},1e3*p))},h=function(){var a=document.createElement("div");a.classList.add("ChaZD-arrow-main");var b=document.createElement("div");b.setAttribute("class","ChaZD-arrow-outer");var c=document.createElement("div");return c.setAttribute("class","ChaZD-arrow-inner"),a.appendChild(b),a.appendChild(c),a},i=function(b){var c=document.createElement("div");c.classList.add("ChaZD-result-container"),c.setAttribute("data-text",b);var d=document.createElement("div");return d.setAttribute("id","ChaZD-searching"),d.innerHTML="ψ(._. )>划词君正在翻译。。。",c.appendChild(d),chrome.runtime.sendMessage({queryWord:b,source:"select"},function(b){var e=b;if(d.innerHTML="","query success"===e.validMessage){c.innerHTML=e.titleBlock;var f=c.querySelector(".voice-container");a(f);var g=document.createElement("div");e.basicBlock?(g.innerHTML=e.basicBlock,c.appendChild(g)):e.haveTranslation?c.querySelector(".title-translation").style.display="block":e.haveWebTranslation?(g.innerHTML=e.webBlock,c.appendChild(g),c.querySelector(".web-title").innerHTML="网络释义"):c.innerHTML="╮(╯▽╰)╭划词君无能为力啊
还是右键问问谷歌君吧=>"}else c.innerHTML=20==e.errorCode?"

这段文字太长,词典君无能为力了(┬_┬)

试试短一点的吧~

":40==e.errorCode?"

对不起,这段文字太高深了,请饶过词典君吧(┬_┬)

":"

词典君罢工啦(┬_┬)

是不是网络不太好?

稍后再试一次吧

"}),c},j=!0,k=!1,l="ctrl",m=!1,n=!1,o=!1,p=3,q=1;chrome.storage.sync.get(null,function(a){j="noSelect"===a.selectMode?!0:!1,k="useCtrl"===a.selectMode?!0:!1,l=a.toggleKey,m=a.linkQuery,n=a.autoAudio,o=a.autoHide,p=a.showDuration,q=a.defaultVoice}),chrome.storage.onChanged.addListener(function(a){if(void 0!==a.linkQuery&&(m=a.linkQuery.newValue),void 0!==a.autoAudio&&(n=a.autoAudio.newValue),void 0!==a.defaultVoice&&(q=a.defaultVoice.newValue),void 0!==a.selectMode){var b=a.selectMode.newValue;j="noSelect"===b?!0:!1,k="useCtrl"===b?!0:!1}void 0!==a.toggleKey&&(l=a.toggleKey.newValue),void 0!==a.autoHide&&(o=a.autoHide.newValue),void 0!==a.showDuration&&(p=a.showDuration.newValue)});var r=["ChaZD-result-container","title-container","title-word","title-translation","basic-container","phonetic-container","explains-container","explains-container","explains-list","property-container","explains-item","voice-container","us-phonetic-container","uk-phonetic-container","web-explains-container","web-explains-list","web-key","explains-item-value","web-value"];document.documentElement.addEventListener("mousedown",function(a){for(var b in r)if(a.target.classList.contains(r[b]))return;clearTimeout(c);var d,e,f=document.querySelectorAll(".ChaZD-result-container"),g=document.querySelectorAll(".ChaZD-arrow-main");if(f)for(d=0,e=f.length;e>d;d++)document.documentElement.removeChild(f[d]);if(g)for(d=0,e=g.length;e>d;d++)document.documentElement.removeChild(g[d]);chrome.storage.sync.set({currentWord:""})}),window.addEventListener("resize",function(){var a=document.querySelector(".ChaZD-result-container"),b=document.querySelector(".ChaZD-arrow-main");a&&document.documentElement.removeChild(a),b&&document.documentElement.removeChild(b)});var s=function(a){if(!j){if(k)if("ctrl"===l){if(!a.ctrlKey&&!a.metaKey)return void(d.again=0)}else if("alt"===l){if(!a.altKey)return void(d.again=0)}else if("shift"===l&&!a.shiftKey)return void(d.again=0);e(a)}},t=null,u=function(a){m&&(t=a.target,a.shiftKey&&w(a))},v=function(a){m&&(t&&t.classList.contains("ChaZD-link")&&x(a,!0),t=null)},w=function(a){t&&a.shiftKey&&(y(a),t.setAttribute("ChaZD-href",t.getAttribute("href")),t.removeAttribute("href"),t.classList.add("ChaZD-link"))},x=function(a,b){t&&(b||16==a.keyCode)&&(t.setAttribute("href",t.getAttribute("ChaZD-href")),t.removeAttribute("ChaZD-href"),t.classList.remove("ChaZD-link"))},y=function(a){m&&a.shiftKey&&window.getSelection().empty()};document.documentElement.addEventListener("mouseup",s),document.documentElement.addEventListener("mouseover",function(a){("A"===a.target.nodeName||"a"===a.target.nodeName)&&u(a)}),document.documentElement.addEventListener("mouseout",function(a){("A"===a.target.nodeName||"a"===a.target.nodeName)&&v(a)}),document.documentElement.addEventListener("keydown",w),document.documentElement.addEventListener("keyup",x),document.documentElement.addEventListener("selectstart",s)}(); \ No newline at end of file +!function(){function a(a){var b=a.getAttribute("data-src"),c=document.createElement("audio");c.setAttribute("src",b+"&type="+e.defaultVoice),a.appendChild(c),e.autoAudio===!0&&c.play(),c.addEventListener("ended",function(){this.load()}),a.addEventListener("click",function(){c.play()})}function b(a,b){return a.top===b.top&&a.bottom===b.bottom&&a.left===b.left&&a.right===b.right?!0:!1}var c,d={top:0,bottom:0,left:0,right:0,again:0},e={};chrome.storage.sync.get(null,function(a){for(var b in a)e[b]=a[b]}),chrome.storage.onChanged.addListener(function(a){void 0!==a.linkQuery&&(e.linkQuery=a.linkQuery.newValue),void 0!==a.useHttps&&(e.useHttps=a.useHttps.newValue),void 0!==a.autoAudio&&(e.autoAudio=a.autoAudio.newValue),void 0!==a.defaultVoice&&(e.defaultVoice=a.defaultVoice.newValue),void 0!==a.selectMode&&(e.selectMode=a.selectMode.newValue),void 0!==a.toggleKey&&(e.toggleKey=a.toggleKey.newValue),void 0!==a.autoHide&&(e.autoHide=a.autoHide.newValue),void 0!==a.showDuration&&(e.showDuration=a.showDuration.newValue),void 0!==a.showPosition&&(e.showPosition=a.showPosition.newValue)});var f=function(a){var c=window.getSelection&&window.getSelection();if(c&&c.rangeCount>0){var f=trim(c.toString()),i=c.getRangeAt(0).getBoundingClientRect();if(b(i,d)&&d.again)return void(d.again=0);if(""===f||!/^[^\u4e00-\u9fa5]+$/.test(f))return;for(var j=document.documentElement.querySelectorAll(".ChaZD-result-container"),k=0,l=j.length;l>k;k++)if(j[k].getAttribute("data-text").toLowerCase()===f.toLowerCase())return;chrome.storage.sync.set({currentWord:f},function(){});for(var m in d)d[m]="again"==m?1:i[m];"side"===e.showPosition&&g(f,e.useHttps),"near"===e.showPosition&&h(f,e.useHttps,i,a)}},g=function(a,b){var d=j(a,b);d.classList.add("ChaZD-result-side"),document.documentElement.appendChild(d),e.autoHide&&(c=setTimeout(function(){document.querySelector(".ChaZD-result-container")&&document.documentElement.removeChild(d)},1e3*e.showDuration))},h=function(a,b,d,f){var g=j(a,b),h=i();document.documentElement.appendChild(g),document.documentElement.appendChild(h);var k={};0===d.left&&0===d.top&&(d={left:f.clientX,top:f.clientY,height:15});var l=g.offsetWidth,m=d.right-d.left,n=d.left+window.pageXOffset,o=d.top+window.pageYOffset,p=m/2+n,q=n-(l-m)/2,r=p-12;qwindow.pageXOffset+document.documentElement.clientWidth&&(q=window.pageXOffset+document.documentElement.clientWidth-l);var s=0;if(s=document.documentElement.clientHeight>document.body.clientHeight?document.body.clientHeight:document.documentElement.clientHeight,0===s&&(s=document.documentElement.clientHeight),d.top>=150){var t=s-o+10,u=t+1;k={left:q,bottom:t,arrowLeft:r,arrowBottom:u}}else k={left:q,top:o+d.height+12,arrowLeft:r,arrowTop:o+d.height+1};g.style.left=k.left+"px",h.style.left=k.arrowLeft+"px";var v,w,x=document.querySelectorAll(".ChaZD-arrow-outer"),y=document.querySelectorAll(".ChaZD-arrow-inner");if(k.bottom)for(g.style.bottom=k.bottom+"px",h.style.bottom=k.arrowBottom+"px",v=0,w=x.length;w>v;v++)x[v].classList.add("ChaZD-arrow-outer-down"),y[v].classList.add("ChaZD-arrow-inner-down");if(k.top)for(g.style.top=k.top+"px",h.style.top=k.arrowTop+"px",v=0,w=x.length;w>v;v++)x[v].classList.add("ChaZD-arrow-outer-up"),y[v].classList.add("ChaZD-arrow-inner-up");e.autoHide&&(c=setTimeout(function(){document.querySelector(".ChaZD-result-container")&&document.querySelector(".ChaZD-arrow-main")&&(document.documentElement.removeChild(g),document.documentElement.removeChild(h))},1e3*e.showDuration))},i=function(){var a=document.createElement("div");a.classList.add("ChaZD-arrow-main");var b=document.createElement("div");b.setAttribute("class","ChaZD-arrow-outer");var c=document.createElement("div");return c.setAttribute("class","ChaZD-arrow-inner"),a.appendChild(b),a.appendChild(c),a},j=function(b,c){var d=document.createElement("div");d.classList.add("ChaZD-result-container"),d.setAttribute("data-text",b);var e=document.createElement("div");return e.setAttribute("id","ChaZD-searching"),e.innerHTML="ψ(._. )>划词君正在翻译。。。",d.appendChild(e),chrome.runtime.sendMessage({queryWord:b,source:"select",useHttps:c},function(b){var c=b;if(e.innerHTML="","query success"===c.validMessage){d.innerHTML=c.titleBlock;var f=d.querySelector(".voice-container");a(f);var g=document.createElement("div");c.basicBlock?(g.innerHTML=c.basicBlock,d.appendChild(g)):c.haveTranslation?d.querySelector(".title-translation").style.display="block":c.haveWebTranslation?(g.innerHTML=c.webBlock,d.appendChild(g),d.querySelector(".web-title").innerHTML="网络释义"):d.innerHTML="╮(╯▽╰)╭划词君无能为力啊
还是右键问问谷歌君吧=>"}else d.innerHTML=20==c.errorCode?"

这段文字太长,词典君无能为力了(┬_┬)

试试短一点的吧~

":40==c.errorCode?"

对不起,这段文字太高深了,请饶过词典君吧(┬_┬)

":"

词典君罢工啦(┬_┬)

是不是网络不太好?

稍后再试一次吧

"}),d},k=["ChaZD-result-container","title-container","title-word","title-translation","basic-container","phonetic-container","explains-container","explains-container","explains-list","property-container","explains-item","voice-container","us-phonetic-container","uk-phonetic-container","web-explains-container","web-explains-list","web-key","explains-item-value","web-value"];document.documentElement.addEventListener("mousedown",function(a){for(var b in k)if(a.target.classList.contains(k[b]))return;clearTimeout(c);var d,e,f=document.querySelectorAll(".ChaZD-result-container"),g=document.querySelectorAll(".ChaZD-arrow-main");if(f)for(d=0,e=f.length;e>d;d++)document.documentElement.removeChild(f[d]);if(g)for(d=0,e=g.length;e>d;d++)document.documentElement.removeChild(g[d]);chrome.storage.sync.set({currentWord:""})}),window.addEventListener("resize",function(){var a=document.querySelector(".ChaZD-result-container"),b=document.querySelector(".ChaZD-arrow-main");a&&document.documentElement.removeChild(a),b&&document.documentElement.removeChild(b)});var l=function(a){if("noSelect"!==e.selectMode){if("useCtrl"===e.selectMode)if("ctrl"===e.toggleKey){if(!a.ctrlKey&&!a.metaKey)return void(d.again=0)}else if("alt"===e.toggleKey){if(!a.altKey)return void(d.again=0)}else if("shift"===e.toggleKey&&!a.shiftKey)return void(d.again=0);f(a)}},m=null,n=function(a){e.linkQuery&&(m=a.target,a.shiftKey&&p(a))},o=function(a){e.linkQuery&&(m&&m.classList.contains("ChaZD-link")&&q(a,!0),m=null)},p=function(a){m&&a.shiftKey&&(r(a),m.setAttribute("ChaZD-href",m.getAttribute("href")),m.removeAttribute("href"),m.classList.add("ChaZD-link"))},q=function(a,b){m&&(b||16==a.keyCode)&&(m.setAttribute("href",m.getAttribute("ChaZD-href")),m.removeAttribute("ChaZD-href"),m.classList.remove("ChaZD-link"))},r=function(a){e.linkQuery&&a.shiftKey&&window.getSelection().empty()};document.documentElement.addEventListener("mouseup",l),document.documentElement.addEventListener("mouseover",function(a){("A"===a.target.nodeName||"a"===a.target.nodeName)&&n(a)}),document.documentElement.addEventListener("mouseout",function(a){("A"===a.target.nodeName||"a"===a.target.nodeName)&&o(a)}),document.documentElement.addEventListener("keydown",p),document.documentElement.addEventListener("keyup",q),document.documentElement.addEventListener("selectstart",l)}(); \ No newline at end of file diff --git a/public/js/utility.min.js b/public/js/utility.min.js index 03679bd..fb70afe 100644 --- a/public/js/utility.min.js +++ b/public/js/utility.min.js @@ -1 +1 @@ -function isEmpty(a){for(var b in a)return!1;return!0}function fmt(){var a=arguments;return a[0].replace(/#{(.*?)}/g,function(b,c){return function(a,b){var c=/\d+/.test(b[0])?parseInt(b[0]):b[0];return b.length>1?arguments.callee(a[c],b.slice(1)):a[c]}("object"==typeof a[1]?a[1]:a,c.split(/\.|\[|\]\[|\]\./))})}function trim(a){return a.replace(/(^\s*)|(\s*$)/g,"")}var api={key:1116151381,keyfrom:"youdaocidian"},urls={dict:"https://fanyi.youdao.com/openapi.do?keyfrom="+api.keyfrom+"&key="+api.key+"&type=data&doctype=json&version=1.1&q=",voice:"https://dict.youdao.com/dictvoice?audio="},settings={selectMode:"mouseSelect",showPosition:"near",toggleKey:"ctrl",showTips:!0,currentWord:"",linkQuery:!1,autoAudio:!1,autoHide:!1,showDuration:3,defaultVoice:1},frame={titleContainer:'
#{1}#{2}
',titleWord:'
#{1}#{2}
',voiceContainer:'
',titleTranslation:'
#{1}
',basicContainer:'
#{1}#{2}
',phoneticContainer:'
#{1}#{2}
',ukPhoneticContainer:'
#{1}
',usPhoneticContainer:'
#{1}
',explainsContainer:'
#{1}
',explainsList:'
    #{1}
',explain:'
  • #{1}#{2}
  • ',propertyContainer:'#{2}',webExplainsContainer:'
    网络释义及短语
    #{1}
    ',webExplainsList:'
      #{1}
    ',webExplain:'
  • #{1}#{2}
  • '}; \ No newline at end of file +function isEmpty(a){for(var b in a)return!1;return!0}function fmt(){var a=arguments;return a[0].replace(/#{(.*?)}/g,function(b,c){return function(a,b){var c=/\d+/.test(b[0])?parseInt(b[0]):b[0];return b.length>1?arguments.callee(a[c],b.slice(1)):a[c]}("object"==typeof a[1]?a[1]:a,c.split(/\.|\[|\]\[|\]\./))})}function trim(a){return a.replace(/(^\s*)|(\s*$)/g,"")}var api={key:1116151381,keyfrom:"youdaocidian"},urls={dict:"http://fanyi.youdao.com/openapi.do?keyfrom="+api.keyfrom+"&key="+api.key+"&type=data&doctype=json&version=1.1&q=",voice:"http://dict.youdao.com/dictvoice?audio=",dictHttps:"https://fanyi.youdao.com/openapi.do?keyfrom="+api.keyfrom+"&key="+api.key+"&type=data&doctype=json&version=1.1&q=",voiceHttps:"https://dict.youdao.com/dictvoice?audio="},settings={selectMode:"mouseSelect",showPosition:"near",toggleKey:"ctrl",showTips:!0,currentWord:"",linkQuery:!1,autoAudio:!1,autoHide:!1,showDuration:3,defaultVoice:1,useHttps:!1},frame={titleContainer:'
    #{1}#{2}
    ',titleWord:'
    #{1}#{2}
    ',voiceContainer:'
    ',titleTranslation:'
    #{1}
    ',basicContainer:'
    #{1}#{2}
    ',phoneticContainer:'
    #{1}#{2}
    ',ukPhoneticContainer:'
    #{1}
    ',usPhoneticContainer:'
    #{1}
    ',explainsContainer:'
    #{1}
    ',explainsList:'
      #{1}
    ',explain:'
  • #{1}#{2}
  • ',propertyContainer:'#{2}',webExplainsContainer:'
    网络释义及短语
    #{1}
    ',webExplainsList:'
      #{1}
    ',webExplain:'
  • #{1}#{2}
  • '}; \ No newline at end of file diff --git a/src/inPage.css b/src/inPage.css index 6e30069..cdbd18f 100644 --- a/src/inPage.css +++ b/src/inPage.css @@ -66,7 +66,7 @@ .ChaZD-result-side { position: fixed !important; right: 10px; - top: 5px; + top: 80px; } .ChaZD-result-container { @@ -83,8 +83,10 @@ border-radius: 4px; z-index: 999997; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: normal; font-size: 14px; position: absolute; + text-decoration: none; line-height: normal; box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.5); -webkit-box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.5); @@ -136,7 +138,7 @@ background-color: #ffffdd; border: none; } -.ChaZD-result-container .basic-container .phonetic-container div { +.ChaZD-result-container .basic-container .phonetic-container .uk-phonetic-container, .ChaZD-result-container .basic-container .phonetic-container .us-phonetic-container { display: inline-block; color: red; margin-right: 5px; @@ -163,27 +165,28 @@ margin: 0; padding: 0; } -.ChaZD-result-container .basic-container .explains-container .explains-list li { +.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item { padding: 0px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; margin: 0 0 5px 0; list-style: none; font-size: 14px; + background-color: transparent; } -.ChaZD-result-container .basic-container .explains-container .explains-list li:before { +.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item:before { display: none; } -.ChaZD-result-container .basic-container .explains-container .explains-list li span { - display: block; - overflow: hidden; -} -.ChaZD-result-container .basic-container .explains-container .property-container { +.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item .property-container { display: block; float: left; font-weight: bold; color: #222222; margin-right: 5px; } +.ChaZD-result-container .basic-container .explains-container .explains-list .explains-item .explains-item-value { + display: block; + overflow: hidden; +} .ChaZD-result-container .basic-container .explains-container .voice-container { display: none; } diff --git a/src/inPage.css.map b/src/inPage.css.map index 00ebee2..a1ebebb 100644 --- a/src/inPage.css.map +++ b/src/inPage.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": ";AAoBI,0BAEC;EAaD,IAAK;IAAC,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAbd,uBAEC;EAUD,IAAK;IAAC,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAVd,qBAEC;EAOD,IAAK;IAAC,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAPd,kBAEC;EAID,IAAK;IAAC,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAhBd,2BAEC;EAkBD,IAAK;IAAC,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAlBd,wBAEC;EAeD,IAAK;IAAC,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAfd,sBAEC;EAYD,IAAK;IAAC,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAZd,mBAEC;EASD,IAAK;IAAC,O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8CAA+C;EAC3C,UAAU,EAAE,WAAW;EACvB,KAAK,EAAE,CAAC;EACR,WAAW,EAAE,sBAAsB;EACnC,YAAY,EAAE,sBAAsB;EACpC,QAAQ,EAAE,QAAQ;EAClB,IAAI,EAAE,GAAG;;;AAIb,qBAAsB;EAClB,aAAa,EAAE,kBAA4B;EAC3C,GAAG,EAAE,GAAG;;;AAGZ,uBAAwB;EACpB,UAAU,EAAE,kBAA4B;;;AAG5C,YAAa;EACT,eAAe,EAAE,eAAe;EAChC,MAAM,EAAE,eAAe", "sources": ["sass/inPage.scss"], "names": [], "file": "inPage.css" diff --git a/src/javascript/background.js b/src/javascript/background.js index 374323e..a791e4c 100644 --- a/src/javascript/background.js +++ b/src/javascript/background.js @@ -1,6 +1,7 @@ -function ChaZD(queryWord, wordSource, sendResponse) { +function ChaZD(queryWord, useHttps, wordSource, sendResponse) { this.wordSource = wordSource; - var url = urls.dict + queryWord; + this.useHttps = useHttps; + var url = (useHttps ? urls.dictHttps : urls.dict) + queryWord; //console.log("Query url: " + url); var queryResult = {}; var self = this; @@ -13,7 +14,7 @@ function ChaZD(queryWord, wordSource, sendResponse) { if (queryWord.indexOf("-") !== -1 && !self.checkErrorCode(result.errorCode).error && !self.haveTranslation(result)) { //优化使用连字符的词的查询结果 - new ChaZD(queryWord.replace(/-/g, " "), wordSource, sendResponse); + new ChaZD(queryWord.replace(/-/g, " "), useHttps, wordSource, sendResponse); } else { var resultObj = self.parseResult.call(self, result); sendResponse(resultObj); @@ -159,7 +160,7 @@ ChaZD.prototype.parseBasicPhonetic = function (basic, queryWord) { }; ChaZD.prototype.initVoice = function (queryWord, type) { - var src = urls.voice + queryWord; + var src = (this.useHttps ? urls.voiceHttps : urls.voice) + queryWord; if(type !== undefined) { src = src + "&type=" + type; } @@ -295,23 +296,33 @@ chrome.runtime.onInstalled.addListener( if (details.reason === "install") { //console.log("[ChaZD] first install."); showNotification({ - title : "感谢支持ChaZD!", - content : "ChaZD力求成为最简洁易用的Chrome词典扩展,欢迎提出您的意见或建议。" + - "如果觉得ChaZD还不错,记得给5星好评哦:)" + title : "感谢支持 ChaZD !", + content : "ChaZD 力求成为最简洁易用的 Chrome 词典扩展,欢迎提出您的意见或建议。" + + "如果觉得 ChaZD 还不错,记得给5星好评哦:)" }); //alert("Thank you for install my app:)"); } else if (details.reason === "update") { //console.log("[ChaZD] update from version " + details.previousVersion); //alert("New version has updated!"); + chrome.storage.sync.set({"showTips" : true}, function() { + //console.log("[ChaZD] Success update settings selectMode = mouseSelect"); + }); showNotification({ - title : "ChaZD 更新到0.8.15版!", - content : "修改 bug" - + title : "ChaZD 更新到0.8.19版!", + content : "修复若干 bug,如出现无法查词的问题,请在设置中关闭使用 HTTPS 接口" }); } } ); +// chrome.contextMenus.create({"title": "在此页面禁用 ChaZD", "id": "deniedPage"}); +// chrome.contextMenus.create({"title": "在此站点禁用 ChaZD", "id": "deniedSite"}); +// chrome.contextMenus.create({"title": "管理禁用列表", "id": "deniedList"}); +// chrome.contextMenus.onClicked.addListener(function (info, tab){ +// console.log(JSON.stringify(info)); +// if (info.menuItemId === "deniedPage") {} +// }); + chrome.storage.sync.get(null,function (items) { //console.log(JSON.stringify(items)); if (items.showTips === undefined ) { @@ -335,7 +346,7 @@ chrome.runtime.onMessage.addListener( function (message, sender, sendResponse) { //console.log("message from sender:" + JSON.stringify(message)); //console.log("sender is " + JSON.stringify(sender)); - new ChaZD(preprocessWord(message.queryWord), message.source, sendResponse); + new ChaZD(preprocessWord(message.queryWord), message.useHttps, message.source, sendResponse); return true; }); diff --git a/src/javascript/popup.js b/src/javascript/popup.js index d404386..f2ae91a 100644 --- a/src/javascript/popup.js +++ b/src/javascript/popup.js @@ -1,14 +1,14 @@ var $button = document.querySelector("#search"); -var $tipsContainer = document.querySelector("#tips"); +//var $tipsContainer = document.querySelector("#tips"); var $input = document.querySelector("#query-word"); var $queryResultContainer = document.querySelector("#query-result"); if (-1 !== window.navigator.platform.toLowerCase().indexOf("mac")) { document.querySelector("#ctrl-option").firstChild.nodeValue = "Command"; } -if (!$tipsContainer.classList.contains("unshow")){ - $tipsContainer.classList.add("unshow"); -} +// if (!$tipsContainer.classList.contains("unshow")){ +// $tipsContainer.classList.add("unshow"); +// } function queryInPopup(queryText) { @@ -23,10 +23,10 @@ function queryInPopup(queryText) { //console.log("quertText: " + queryText); if (queryText) { $input.value = queryText; - chrome.extension.sendMessage({queryWord: queryText, source: "popup"}, buildResult); + chrome.extension.sendMessage({queryWord: queryText, source: "popup", useHttps: useHttpsValue}, buildResult); } else { - chrome.extension.sendMessage({queryWord: $input.value, source: "popup"}, buildResult); + chrome.extension.sendMessage({queryWord: $input.value, source: "popup", useHttps: useHttpsValue}, buildResult); } } @@ -146,6 +146,8 @@ var currentDuration = document.querySelector("#currentDuration"); var turnOffTips = document.querySelector("#turn-off-tips"); var tips = document.querySelector("#tips"); var toggleKey = document.querySelector("#toggle-key"); +var useHttps = document.querySelector("#useHttps"); +var useHttpsValue = false; chrome.storage.sync.get(null, function (items) { if(items.currentWord !== "") { @@ -158,6 +160,15 @@ chrome.storage.sync.get(null, function (items) { linkQuery.checked = false; linkQuery.nextSibling.classList.add("unactive"); } + if(items.useHttps === true) { + useHttps.checked = true; + useHttpsValue = true; + useHttps.nextSibling.classList.remove("unactive"); + } else { + useHttps.checked = false; + useHttpsValue = false; + useHttps.nextSibling.classList.add("unactive"); + } if(items.autoAudio === true) { autoAudio.checked = true; autoAudio.nextSibling.classList.remove("unactive"); @@ -240,6 +251,12 @@ linkQuery.addEventListener("click", function (event) { }); }); +useHttps.addEventListener("click", function (event) { + var currentUseHttps = useHttps.checked; + useHttps.nextSibling.classList.toggle("unactive"); + chrome.storage.sync.set({"useHttps": currentUseHttps}); +}); + autoAudio.addEventListener("click", function (event) { var currentAutoAudio = autoAudio.checked; if (currentAutoAudio) { diff --git a/src/javascript/selection.js b/src/javascript/selection.js index a129418..775f67d 100644 --- a/src/javascript/selection.js +++ b/src/javascript/selection.js @@ -7,6 +7,47 @@ again: 0 }; + var timeout; + var currentSettings = {}; + chrome.storage.sync.get(null, function(items) { + for (var key in items) { + currentSettings[key] = items[key]; + } + }); + + chrome.storage.onChanged.addListener(function(changes) { + // for (var key in changes) { + // console.log("[ChaZD]Settings Update, [%s] %s => %s", key, changes[key].oldValue, changes[key].newValue); + // } + if (changes.linkQuery !== undefined) { + currentSettings.linkQuery = changes.linkQuery.newValue; + } + if (changes.useHttps !== undefined) { + currentSettings.useHttps = changes.useHttps.newValue; + } + if (changes.autoAudio !== undefined) { + currentSettings.autoAudio = changes.autoAudio.newValue; + } + if (changes.defaultVoice !== undefined) { + currentSettings.defaultVoice = changes.defaultVoice.newValue; + } + if (changes.selectMode !== undefined) { + currentSettings.selectMode = changes.selectMode.newValue; + } + if (changes.toggleKey !== undefined) { + currentSettings.toggleKey = changes.toggleKey.newValue; + } + if (changes.autoHide !== undefined) { + currentSettings.autoHide = changes.autoHide.newValue; + } + if (changes.showDuration !== undefined) { + currentSettings.showDuration = changes.showDuration.newValue; + } + if (changes.showPosition !== undefined) { + currentSettings.showPosition = changes.showPosition.newValue; + } + }); + var queryInPage = function(event) { var selection = window.getSelection && window.getSelection(); if(selection && selection.rangeCount > 0) { @@ -17,7 +58,12 @@ return; } - if (selectText === "" || !(/[a-zA-Z\s]/.test(selectText))) {return;} + if (selectText === "" || !(/^[^\u4e00-\u9fa5]+$/.test(selectText))) {return;} + var haveResult = document.documentElement.querySelectorAll(".ChaZD-result-container"); + for (var i = 0, len = haveResult.length; i < len; i++) { + if (haveResult[i].getAttribute("data-text").toLowerCase() === selectText.toLowerCase()){return;} + } + ////////if (currentQueryWord !== "" && selectText === currentQueryWord) {return;} chrome.storage.sync.set({"currentWord" : selectText}, function() { //console.log("[ChaZD] Success update settings currentWord = " + selectText); }); @@ -29,47 +75,36 @@ preSelection[key] = selectRange[key]; } } - //console.log("[ChaZD]Selected Text at %s : %s", location.href, selectText); - var currentSettings = {}; - chrome.storage.sync.get(null, function(items) { - //console.log("[Settings after select]"); - for (var key in items) { - currentSettings[key] = items[key]; - //console.log(" %s : %s", key, currentSettings[key]); - } - //var duration = currentSettings["duration"] - if (currentSettings.showPosition == "side") { - //console.log("in 1"); - showResultSide(selectText); - } - if (currentSettings.showPosition == "near") { - //console.log("in 2"); - showResultNear(selectText, selectRange, event); - } - }); + if (currentSettings.showPosition === "side") { + //console.log("in 1"); + showResultSide(selectText, currentSettings.useHttps); + } + if (currentSettings.showPosition === "near") { + //console.log("in 2"); + showResultNear(selectText, currentSettings.useHttps, selectRange, event); + } } }; - var timeout; - - var showResultSide = function (text) { + var showResultSide = function (text, useHttps) { //if(isExist(text)) return; - var $resultSideContainer = makeResultContainer(text); + var $resultSideContainer = makeResultContainer(text, useHttps); $resultSideContainer.classList.add("ChaZD-result-side"); document.documentElement.appendChild($resultSideContainer); - if (autoHide) { + if (currentSettings.autoHide) { timeout = setTimeout(function () { if (document.querySelector(".ChaZD-result-container")) { document.documentElement.removeChild($resultSideContainer); + ////////currentQueryWord = ""; } - }, 1000 * showDuration); + }, 1000 * currentSettings.showDuration); } }; - var showResultNear = function (text, range, event) { + var showResultNear = function (text, useHttps, range, event) { //if(isExist(text)) return; - var resultNearContainer = makeResultContainer(text); + var resultNearContainer = makeResultContainer(text, useHttps); var arrowMain = makeArrowDiv(); document.documentElement.appendChild(resultNearContainer); document.documentElement.appendChild(arrowMain); @@ -150,13 +185,14 @@ } } - if (autoHide) { + if (currentSettings.autoHide) { timeout = setTimeout(function () { if (document.querySelector(".ChaZD-result-container") && document.querySelector(".ChaZD-arrow-main")) { document.documentElement.removeChild(resultNearContainer); document.documentElement.removeChild(arrowMain); + ////////currentQueryWord = ""; } - }, 1000 * showDuration); + }, 1000 * currentSettings.showDuration); } // var t = setTimeout(function () { // document.body.removeChild(resultNearContainer); @@ -178,7 +214,7 @@ return arrowDivMain; }; - var makeResultContainer = function (text) { + var makeResultContainer = function (text, useHttps) { var $resultContainer = document.createElement("div"); $resultContainer.classList.add("ChaZD-result-container"); $resultContainer.setAttribute("data-text", text); @@ -188,7 +224,8 @@ $resultContainer.appendChild($searchingNode); chrome.runtime.sendMessage({ queryWord: text, - source: "select" + source: "select", + useHttps: useHttps }, function(response) { var resultObj = response; $searchingNode.innerHTML = ""; @@ -234,10 +271,10 @@ var src = voice.getAttribute("data-src"); //console.log("voice src: [] " + src); var audioBlock = document.createElement("audio"); - audioBlock.setAttribute("src", src + "&type=" + defaultVoice); + audioBlock.setAttribute("src", src + "&type=" + currentSettings.defaultVoice); //audioBlock.setAttribute("ended", "this.load()"); voice.appendChild(audioBlock); - if (autoAudio === true) { + if (currentSettings.autoAudio === true) { audioBlock.play(); } audioBlock.addEventListener("ended", function (event) { @@ -259,55 +296,7 @@ } return false; } - - var noSelect = true; - var useCtrl = false; - var toggleKey = "ctrl"; - var linkQuery = false; - var autoAudio = false; - var autoHide = false; - var showDuration = 3; - var defaultVoice = 1; - chrome.storage.sync.get(null, function(items) { - noSelect = (items.selectMode === "noSelect") ? true : false; - useCtrl = (items.selectMode === "useCtrl") ? true : false; - toggleKey = items.toggleKey; - linkQuery = items.linkQuery; - autoAudio = items.autoAudio; - autoHide = items.autoHide; - showDuration = items.showDuration; - defaultVoice = items.defaultVoice; - }); - - chrome.storage.onChanged.addListener(function(changes) { - // for (var key in changes) { - // console.log("[ChaZD]Settings Update, [%s] %s => %s", key, changes[key].oldValue, changes[key].newValue); - // } - if (changes.linkQuery !== undefined) { - linkQuery = changes.linkQuery.newValue; - } - if (changes.autoAudio !== undefined) { - autoAudio = changes.autoAudio.newValue; - } - if (changes.defaultVoice !== undefined) { - defaultVoice = changes.defaultVoice.newValue; - } - if (changes.selectMode !== undefined) { - var selectMode = changes.selectMode.newValue; - noSelect = (selectMode === "noSelect") ? true : false; - useCtrl = (selectMode === "useCtrl") ? true : false; - } - if (changes.toggleKey !== undefined) { - toggleKey = changes.toggleKey.newValue; - } - if (changes.autoHide !== undefined) { - autoHide = changes.autoHide.newValue; - } - if (changes.showDuration !== undefined) { - showDuration = changes.showDuration.newValue; - } - }); - + var classNameCollection = ["ChaZD-result-container", "title-container", "title-word", "title-translation", "basic-container", "phonetic-container", "explains-container", "explains-container", "explains-list", "property-container", "explains-item", "voice-container", "us-phonetic-container", "uk-phonetic-container", "web-explains-container", "web-explains-list", "web-key", "explains-item-value", "web-value"]; document.documentElement.addEventListener("mousedown", function(event) { @@ -337,6 +326,7 @@ } } chrome.storage.sync.set({"currentWord" : ""}); + ////////currentQueryWord = ""; //clearSelection(event); }); @@ -349,28 +339,29 @@ if (chazdArrow) { document.documentElement.removeChild(chazdArrow); } + ////////currentQueryWord = ""; }); var queryEvent = function (event) { //console.log("[ChaZD] current useCtrl: " + useCtrl); - if (noSelect) {return;} - if (useCtrl) { + if (currentSettings.selectMode === "noSelect") {return;} + if (currentSettings.selectMode === "useCtrl") { //console.log("current togglekey: " + toggleKey); - if (toggleKey === "ctrl") { + if (currentSettings.toggleKey === "ctrl") { //console.log("[ChaZD] In Ctrl"); if (!event.ctrlKey && !event.metaKey) { //console.log("[ChaZD] Aho~~~"); preSelection.again = 0; return; } - } else if (toggleKey === "alt") { + } else if (currentSettings.toggleKey === "alt") { //console.log("[ChaZD] In Alt"); if (!event.altKey) { preSelection.again = 0; //console.log("[ChaZD] Aho~~~"); return; } - } else if (toggleKey === "shift") { + } else if (currentSettings.toggleKey === "shift") { //console.log("[ChaZD] In Shift"); if (!event.shiftKey) { preSelection.again = 0; @@ -380,18 +371,12 @@ } } queryInPage(event); - // var selectVoice = null - // if(selectVoice = document.querySelector(".voice-container")) { - // selectVoice.addEventListener("click", function(event) { - // selectVoice.firstChild.play(); - // }) - // } }; var link = null; var focusLink = function (event) { - if (linkQuery) { + if (currentSettings.linkQuery) { //event.stopPropagation(); //console.log("focusLink"); link = event.target; @@ -405,7 +390,7 @@ }; var blurLink = function (event) { - if (linkQuery) { + if (currentSettings.linkQuery) { //event.stopPropagation(); if (link && link.classList.contains("ChaZD-link")) { enableLink(event, true); @@ -432,7 +417,7 @@ }; var clearSelection = function (event) { - if (linkQuery && event.shiftKey) { + if (currentSettings.linkQuery && event.shiftKey) { window.getSelection().empty(); } }; diff --git a/src/javascript/utility.js b/src/javascript/utility.js index 7a754e4..0177041 100644 --- a/src/javascript/utility.js +++ b/src/javascript/utility.js @@ -4,22 +4,24 @@ var api = { }; var urls = { - dict : "https://fanyi.youdao.com/openapi.do?keyfrom=" + api.keyfrom +"&key="+ api.key +"&type=data&doctype=json&version=1.1&q=", - voice : "https://dict.youdao.com/dictvoice?audio=" + dict : "http://fanyi.youdao.com/openapi.do?keyfrom=" + api.keyfrom +"&key="+ api.key +"&type=data&doctype=json&version=1.1&q=", + voice : "http://dict.youdao.com/dictvoice?audio=", + dictHttps : "https://fanyi.youdao.com/openapi.do?keyfrom=" + api.keyfrom +"&key="+ api.key +"&type=data&doctype=json&version=1.1&q=", + voiceHttps : "https://dict.youdao.com/dictvoice?audio=", }; var settings = { - selectMode : "mouseSelect", //划词的形式:直接划词 | Ctrl+划词 + selectMode : "mouseSelect", //划词的形式:直接划词 or Ctrl + 划词 showPosition : "near", //划词翻译结果显示的位置 - //duration : 5, //翻译结果显示的时间 toggleKey : "ctrl", - showTips : true, //是否显示Tips + showTips : true, //是否显示 Tips currentWord: "", //当前划词查询的内容 linkQuery: false, //在链接上划词 autoAudio: false, //划词自动发音 autoHide: false, //自动隐藏翻译结果 showDuration: 3, //翻译结果显示持续时间 defaultVoice: 1, //划词默认发音:1--英音;2--美音 + useHttps: false, //是否使用 HTTPS 的接口 }; var frame = { diff --git a/src/sass/inPage.scss b/src/sass/inPage.scss index 2455aa2..caad307 100644 --- a/src/sass/inPage.scss +++ b/src/sass/inPage.scss @@ -45,7 +45,7 @@ $gap: 10px; .ChaZD-result-side { position: fixed !important; right: 10px; - top: 5px; + top: 80px; } .ChaZD-result-container { @@ -62,8 +62,10 @@ $gap: 10px; border-radius: 4px; z-index: 999997; font-family: $font-family; + font-weight: normal; font-size: $font-size; position: absolute; + text-decoration: none; line-height: normal; @include box-shadow(0px, 0px, 20px,rgba(0, 0, 0, 0.5)); @include animation("fade-in 0.3s ease"); @@ -121,7 +123,7 @@ $gap: 10px; .phonetic-container { //display: none; - div { + .uk-phonetic-container, .us-phonetic-container { display: inline-block; color: red; margin-right: 5px; @@ -153,7 +155,7 @@ $gap: 10px; margin: 0; padding: 0; - li { + .explains-item { &:before { display: none; } @@ -162,21 +164,23 @@ $gap: 10px; margin: 0 0 $gap / 2 0; list-style: none; font-size: $font-size; - span { + background-color: transparent; + + .property-container { + display: block; + float: left; + font-weight: bold; + color: $text-color; + margin-right: 5px; + } + + .explains-item-value { display: block; overflow: hidden; } } } - .property-container { - display: block; - float: left; - font-weight: bold; - color: $text-color; - margin-right: 5px; - } - .voice-container { display: none; } diff --git a/src/style.css b/src/style.css index f39360a..a556b7e 100644 --- a/src/style.css +++ b/src/style.css @@ -341,7 +341,7 @@ ul { .tips-container p { margin: 0; - margin-top: 10px; + margin-top: 5px; padding: 0; } @@ -481,8 +481,12 @@ footer img { margin-top: 5px; } -.setting-block .link-query-help { - margin-left: 18px; +.setting-block .link-query { + margin-left: 5px; +} + +.setting-block .help { + font-size: 12px; cursor: help; }