"]
34 |
35 | } ],
36 |
37 | "browser_action": {
38 | "default_popup": "popup.html",
39 | "default_icon": {
40 | "38": "icons/icon38.png",
41 | "19": "icons/icon19.png"
42 | }
43 | },
44 |
45 | "icons": {
46 | "16": "icons/icon16.png",
47 | "48": "icons/icon48.png",
48 | "128": "icons/icon128.png"
49 | },
50 |
51 | "commands": {
52 | "_execute_browser_action": {
53 | "suggested_key": {
54 | "default": "Ctrl+Shift+F",
55 | "mac": "MacCtrl+Shift+F"
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/options.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 好学单词 设置
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ChaZD",
3 | "version": "0.8.19",
4 | "description": "A Chinese-English translator extension for Chrome",
5 | "main": null,
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/ververcpp/ChaZD.git"
12 | },
13 | "keywords": [
14 | "chrome",
15 | "extension",
16 | "ChaZD"
17 | ],
18 | "author": "ververcpp",
19 | "license": "ISC",
20 | "bugs": {
21 | "url": "https://github.com/ververcpp/ChaZD/issues"
22 | },
23 | "engines": {
24 | "node": ">= 0.8.0"
25 | },
26 | "homepage": "https://github.com/ververcpp/ChaZD",
27 | "devDependencies": {
28 | "grunt": "^0.4.5",
29 | "grunt-contrib-copy": "^0.7.0",
30 | "grunt-contrib-cssmin": "^0.10.0",
31 | "grunt-contrib-jshint": "^0.10.0",
32 | "grunt-contrib-sass": "^0.8.1",
33 | "grunt-contrib-uglify": "^0.6.0",
34 | "grunt-contrib-watch": "^0.6.1",
35 | "load-grunt-tasks": "^1.0.0"
36 | },
37 | "dependencies": {}
38 | }
39 |
--------------------------------------------------------------------------------
/popup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Youdao Dictionary
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | Tips: 你可以通过“Ctrl+Shift+F”快速启动词典,
19 | 也可以在这里自定义快捷键哦:)
20 |
21 |
22 | Tips 2: 如出现无法查词的问题,请在设置中关闭使用 HTTPS 接口
23 |
24 |
不再显示Tips
25 |
26 |
27 |
28 |
32 |
41 |
45 |
48 |
49 |
52 |
55 |
64 |
65 |
68 |
74 |
75 |
78 |
81 |
85 |
86 |
96 |
97 |
98 |
99 |
103 |
104 |
--------------------------------------------------------------------------------
/public/css/fonts/YDdict-Icon-font.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XYUU/ChaZD/f1d020ca8fe02297abd113aaf91bfcb3cd176476/public/css/fonts/YDdict-Icon-font.eot
--------------------------------------------------------------------------------
/public/css/fonts/YDdict-Icon-font.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/public/css/fonts/YDdict-Icon-font.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XYUU/ChaZD/f1d020ca8fe02297abd113aaf91bfcb3cd176476/public/css/fonts/YDdict-Icon-font.ttf
--------------------------------------------------------------------------------
/public/css/fonts/YDdict-Icon-font.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XYUU/ChaZD/f1d020ca8fe02297abd113aaf91bfcb3cd176476/public/css/fonts/YDdict-Icon-font.woff
--------------------------------------------------------------------------------
/public/css/inPage.min.css:
--------------------------------------------------------------------------------
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: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}
--------------------------------------------------------------------------------
/public/css/style.min.css:
--------------------------------------------------------------------------------
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: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}
--------------------------------------------------------------------------------
/public/js/background.min.js:
--------------------------------------------------------------------------------
1 | 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}}window.Notifications=window.Notifications||window.webkitNotifications,chrome.runtime.onInstalled.addListener(function(a){"install"===a.reason?showNotification({title:"感谢支持 ChaZD !",content:"ChaZD 力求成为最简洁易用的 Chrome 词典扩展,欢迎提出您的意见或建议。如果觉得 ChaZD 还不错,记得给5星好评哦:)"}):"update"===a.reason&&(chrome.storage.sync.set({showTips:!0},function(){}),showNotification({title:"ChaZD 更新到0.8.19版!",content:"修复若干 bug,如出现无法查词的问题,请在设置中关闭使用 HTTPS 接口"}))}),chrome.storage.sync.get(null,function(a){if(void 0===a.showTips)chrome.storage.sync.set(settings);else{for(var b in a)void 0===settings[b]?chrome.storage.sync.remove(b):settings[b]=a[b];chrome.storage.sync.set(settings)}}),chrome.runtime.onMessage.addListener(function(a,b,c){var d=new api[currentSettings.apiName];return d.Query(preprocessWord(a.queryWord),a.source,c),!0});
--------------------------------------------------------------------------------
/public/js/popup.min.js:
--------------------------------------------------------------------------------
1 | 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"},buildResult)):chrome.extension.sendMessage({queryWord:$input.value,source:"popup"},buildResult)}function createLink(a,b){a.addEventListener("click",function(a){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(0==b.Code){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"),g=function(a){var b=a.getAttribute("data-src"),c=document.createElement("audio");c.setAttribute("src",b),a.appendChild(c),c.addEventListener("ended",function(a){this.load()}),a.addEventListener("click",function(a){c.play()})};for(d=0,e=f.length;e>d;d++)g(f[d])}else 20==b.Code?$queryResultContainer.innerHTML="这段文字太长,词典君无能为力了(┬_┬)
试试短一点的吧~
":40==b.Code?$queryResultContainer.innerHTML="对不起,这段文字太高深了,请饶过词典君吧(┬_┬)
":$queryResultContainer.innerHTML="词典君罢工啦(┬_┬)
是不是网络不太好?
稍后再试一次吧
"};$button.addEventListener("click",function(a){queryInPopup()}),$input.select(),$input.addEventListener("input",function(a){var b=$input.value;setTimeout(function(){$input.value===b&&""!==$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(a){var b=document.getElementById("settings");b.classList.toggle("active"),b.classList.contains("active")?b.style.height=blockHeight+"px":b.style.height=0});var blockHeight=totalHeight("top-menu")+totalHeight("sub-menu")+totalHeight("carved")+52,linkQuery=document.querySelector("#linkQuery"),noSelect=document.querySelector("#noSelect"),mouseSelect=document.querySelector("#mouseSelect"),useCtrl=document.querySelector("#useCtrl"),autoAudio=document.querySelector("#autoAudio"),human=document.querySelector("#human"),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"),autoLearn=document.querySelector("#autoLearn"),openAPI=document.querySelector("#open-api");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,useHttps.nextSibling.classList.remove("unactive")):(useHttps.checked=!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")),0===a.defaultVoice?(human.checked=!0,defaultUk.nextSibling.classList.remove("unactive"),defaultUs.nextSibling.classList.remove("unactive"),human.nextSibling.classList.add("unactive")):1===a.defaultVoice?(defaultUs.checked=!0,human.nextSibling.classList.remove("unactive"),defaultUs.nextSibling.classList.remove("unactive"),defaultUk.nextSibling.classList.add("unactive")):2===a.defaultVoice&&(defaultUs.checked=!0,human.nextSibling.classList.remove("unactive"),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),"shanbay"===a.apiName?openAPI.selectedIndex=0:"xyuu"===a.apiName?openAPI.selectedIndex=1:"youdao"===a.apiName&&(openAPI.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),a.autoLearn===!0?(autoLearn.checked=!0,autoLearn.nextSibling.classList.remove("unactive")):(autoLearn.checked=!1,autoLearn.nextSibling.classList.add("unactive")),currentDuration.innerHTML=showDuration.value=a.showDuration}),linkQuery.addEventListener("click",function(a){var b=linkQuery.checked;linkQuery.nextSibling.classList.toggle("unactive"),chrome.storage.sync.set({linkQuery:b},function(){})}),useHttps.addEventListener("click",function(a){var b=useHttps.checked;useHttps.nextSibling.classList.toggle("unactive"),chrome.storage.sync.set({useHttps:b})}),autoAudio.addEventListener("click",function(a){var b=autoAudio.checked;b?autoAudio.nextSibling.classList.remove("unactive"):autoAudio.nextSibling.classList.add("unactive"),chrome.storage.sync.set({autoAudio:b},function(){})}),autoLearn.addEventListener("click",function(a){var b=autoLearn.checked;b?autoLearn.nextSibling.classList.remove("unactive"):autoLearn.nextSibling.classList.add("unactive"),chrome.storage.sync.set({autoLearn:b},function(){})}),human.addEventListener("click",function(a){human.nextSibling.classList.remove("unactive"),human.nextSibling.classList.add("unactive"),chrome.storage.sync.set({defaultVoice:0},function(){})}),defaultUk.addEventListener("click",function(a){defaultUk.nextSibling.classList.remove("unactive"),defaultUs.nextSibling.classList.add("unactive"),chrome.storage.sync.set({defaultVoice:1},function(){})}),defaultUs.addEventListener("click",function(a){defaultUs.nextSibling.classList.remove("unactive"),defaultUk.nextSibling.classList.add("unactive"),chrome.storage.sync.set({defaultVoice:2},function(){})}),turnOffTips.addEventListener("click",function(a){tips.classList.add("unshow"),chrome.storage.sync.set({showTips:!1},function(){})}),noSelect.addEventListener("click",function(a){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(a){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(a){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(a){showPositionSide.nextSibling.classList.remove("unactive"),showPositionNear.nextSibling.classList.add("unactive"),chrome.storage.sync.set({showPosition:"side"},function(){})}),showPositionNear.addEventListener("click",function(a){showPositionSide.nextSibling.classList.add("unactive"),showPositionNear.nextSibling.classList.remove("unactive"),chrome.storage.sync.set({showPosition:"near"},function(){})}),autoHide.addEventListener("click",function(a){var b=autoHide.checked;b?(autoHide.nextSibling.classList.remove("unactive"),showDuration.disabled=!1):(autoHide.nextSibling.classList.add("unactive"),showDuration.disabled=!0),chrome.storage.sync.set({autoHide:b},function(){})}),showDuration.addEventListener("input",function(a){currentDuration.innerHTML=showDuration.value,chrome.storage.sync.set({showDuration:showDuration.value},function(){})}),toggleKey.onchange=function(a){chrome.storage.sync.set({toggleKey:this.value},function(){})},openAPI.onchange=function(a){chrome.storage.sync.set({apiName:this.value},function(){})};
--------------------------------------------------------------------------------
/public/js/selection.min.js:
--------------------------------------------------------------------------------
1 | !function(){function a(a,b){return a.top===b.top&&a.bottom===b.bottom&&a.left===b.left&&a.right===b.right?!0:!1}var b,c={top:0,bottom:0,left:0,right:0,again:0},d=function(b){var d=window.getSelection&&window.getSelection();if(d&&d.rangeCount>0){var g=trim(d.toString()),h=d.getRangeAt(0).getBoundingClientRect();if(a(h,c)&&c.again)return void(c.again=0);if(""===g||!/^[^\u4e00-\u9fa5]+$/.test(g))return;for(var i=document.documentElement.querySelectorAll(".ChaZD-result-container"),j=0,k=i.length;k>j;j++)if(i[j].getAttribute("data-text").toLowerCase()===g.toLowerCase())return;chrome.storage.sync.set({currentWord:g},function(){});for(var l in c)"again"==l?c[l]=1:c[l]=h[l];"side"===currentSettings.showPosition&&e(g,currentSettings.useHttps),"near"===currentSettings.showPosition&&f(g,currentSettings.useHttps,h,b)}},e=function(a,c){var d=h(a,c);d.classList.add("ChaZD-result-side"),document.documentElement.appendChild(d),currentSettings.autoHide&&(b=setTimeout(function(){document.querySelector(".ChaZD-result-container")&&document.documentElement.removeChild(d)},1e3*currentSettings.showDuration))},f=function(a,c,d,e){var f=h(a,c),i=g();document.documentElement.appendChild(f),document.documentElement.appendChild(i);var j={};0===d.left&&0===d.top&&(d={left:e.clientX,top:e.clientY,height:15});var k=f.offsetWidth,l=d.right-d.left,m=d.left+window.pageXOffset,n=d.top+window.pageYOffset,o=l/2+m,p=m-(k-l)/2,q=o-12;pwindow.pageXOffset+document.documentElement.clientWidth&&(p=window.pageXOffset+document.documentElement.clientWidth-k);var r=0;if(r=document.documentElement.clientHeight>document.body.clientHeight?document.body.clientHeight:document.documentElement.clientHeight,0===r&&(r=document.documentElement.clientHeight),d.top>=150){var s=r-n+10,t=s+1;j={left:p,bottom:s,arrowLeft:q,arrowBottom:t}}else j={left:p,top:n+d.height+12,arrowLeft:q,arrowTop:n+d.height+1};f.style.left=j.left+"px",i.style.left=j.arrowLeft+"px";var u,v,w=document.querySelectorAll(".ChaZD-arrow-outer"),x=document.querySelectorAll(".ChaZD-arrow-inner");if(j.bottom)for(f.style.bottom=j.bottom+"px",i.style.bottom=j.arrowBottom+"px",u=0,v=w.length;v>u;u++)w[u].classList.add("ChaZD-arrow-outer-down"),x[u].classList.add("ChaZD-arrow-inner-down");if(j.top)for(f.style.top=j.top+"px",i.style.top=j.arrowTop+"px",u=0,v=w.length;v>u;u++)w[u].classList.add("ChaZD-arrow-outer-up"),x[u].classList.add("ChaZD-arrow-inner-up");currentSettings.autoHide&&(b=setTimeout(function(){document.querySelector(".ChaZD-result-container")&&document.querySelector(".ChaZD-arrow-main")&&(document.documentElement.removeChild(f),document.documentElement.removeChild(i))},1e3*currentSettings.showDuration))},g=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},h=function(a,b){var c=document.createElement("div");c.classList.add("ChaZD-result-container"),c.setAttribute("data-text",a);var d=document.createElement("div");return d.setAttribute("id","ChaZD-searching"),d.innerHTML="ψ(._. )>划词君正在翻译。。。",c.appendChild(d),chrome.runtime.sendMessage({queryWord:a,source:"select"},function(a){var b=a;if(d.innerHTML="",0===b.Code){c.innerHTML=b.titleBlock;var e=c.querySelector(".voice-container"),f=function(a){var b=a.getAttribute("data-src"),c=document.createElement("audio");currentSettings.defaultVoice&&(b+="&type="+currentSettings.defaultVoice),c.setAttribute("src",b),a.appendChild(c),currentSettings.autoAudio===!0&&c.play(),c.addEventListener("ended",function(a){this.load()}),a.addEventListener("click",function(a){c.play()})};f(e);var g=document.createElement("div");b.basicBlock?(g.innerHTML=b.basicBlock,c.appendChild(g)):b.haveTranslation?c.querySelector(".title-translation").style.display="block":b.haveWebTranslation?(g.innerHTML=b.webBlock,c.appendChild(g),c.querySelector(".web-title").innerHTML="网络释义"):c.innerHTML="╮(╯▽╰)╭划词君无能为力啊
还是右键问问谷歌君吧=>"}else 20==b.Code?c.innerHTML="这段文字太长,词典君无能为力了(┬_┬)
试试短一点的吧~
":40==b.Code?c.innerHTML="对不起,这段文字太高深了,请饶过词典君吧(┬_┬)
":c.innerHTML="词典君罢工啦(┬_┬)
是不是网络不太好?
稍后再试一次吧
"}),c},i=["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 c in i)if(a.target.classList.contains(i[c]))return;clearTimeout(b);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(a){var b=document.querySelector(".ChaZD-result-container"),c=document.querySelector(".ChaZD-arrow-main");b&&document.documentElement.removeChild(b),c&&document.documentElement.removeChild(c)});var j=function(a){if("noSelect"!==currentSettings.selectMode){if("useCtrl"===currentSettings.selectMode)if("ctrl"===currentSettings.toggleKey){if(!a.ctrlKey&&!a.metaKey)return void(c.again=0)}else if("alt"===currentSettings.toggleKey){if(!a.altKey)return void(c.again=0)}else if("shift"===currentSettings.toggleKey&&!a.shiftKey)return void(c.again=0);d(a)}},k=null,l=function(a){currentSettings.linkQuery&&(k=a.target,a.shiftKey&&n(a))},m=function(a){currentSettings.linkQuery&&(k&&k.classList.contains("ChaZD-link")&&o(a,!0),k=null)},n=function(a){k&&a.shiftKey&&(p(a),k.setAttribute("ChaZD-href",k.getAttribute("href")),k.removeAttribute("href"),k.classList.add("ChaZD-link"))},o=function(a,b){k&&(b||16==a.keyCode)&&(k.setAttribute("href",k.getAttribute("ChaZD-href")),k.removeAttribute("ChaZD-href"),k.classList.remove("ChaZD-link"))},p=function(a){currentSettings.linkQuery&&a.shiftKey&&window.getSelection().empty()};document.documentElement.addEventListener("mouseup",j),document.documentElement.addEventListener("mouseover",function(a){("A"===a.target.nodeName||"a"===a.target.nodeName)&&l(a)}),document.documentElement.addEventListener("mouseout",function(a){("A"===a.target.nodeName||"a"===a.target.nodeName)&&m(a)}),document.documentElement.addEventListener("keydown",n),document.documentElement.addEventListener("keyup",o),document.documentElement.addEventListener("selectstart",j)}();
--------------------------------------------------------------------------------
/public/js/utility.min.js:
--------------------------------------------------------------------------------
1 | function ajax(a,b,c,d,e){var f=new XMLHttpRequest;f.open(a,b,!0),f.onreadystatechange=function(){4==f.readyState&&d(f)},void 0!=e&&e(f),f.send(c)}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 settings={selectMode:"mouseSelect",showPosition:"near",toggleKey:"ctrl",showTips:!0,currentWord:"",linkQuery:!1,autoAudio:!1,autoHide:!1,showDuration:3,defaultVoice:0,useHttps:!1,autoLearn:!0,apiName:"shanbay"},currentSettings=settings;chrome.storage.sync.get(null,function(a){for(var b in a)currentSettings[b]=a[b]}),chrome.storage.onChanged.addListener(function(a){void 0!==a.linkQuery&&(currentSettings.linkQuery=a.linkQuery.newValue),void 0!==a.useHttps&&(currentSettings.useHttps=a.useHttps.newValue),void 0!==a.autoAudio&&(currentSettings.autoAudio=a.autoAudio.newValue),void 0!==a.defaultVoice&&(currentSettings.defaultVoice=a.defaultVoice.newValue),void 0!==a.selectMode&&(currentSettings.selectMode=a.selectMode.newValue),void 0!==a.toggleKey&&(currentSettings.toggleKey=a.toggleKey.newValue),void 0!==a.autoHide&&(currentSettings.autoHide=a.autoHide.newValue),void 0!==a.showDuration&&(currentSettings.showDuration=a.showDuration.newValue),void 0!==a.showPosition&&(currentSettings.showPosition=a.showPosition.newValue),void 0!==a.autoLearn&&(currentSettings.autoLearn=a.autoLearn.newValue),void 0!==a.apiName&&(currentSettings.apiName=a.apiName.newValue)});var frame={titleContainer:'#{1}#{2}
',titleWord:'#{1}#{2}
',voiceContainer:'',titleTranslation:'#{1}
',basicContainer:'#{1}#{2}
',phoneticContainer:'#{1}#{2}
',ukPhoneticContainer:'#{1}
',usPhoneticContainer:'#{1}
',explainsContainer:'#{1}
',explainsList:'',explain:'#{1}#{2}',propertyContainer:'#{2}',webExplainsContainer:'',webExplainsList:'',webExplain:'#{1}#{2}'},youdao=function(){var a={key:1116151381,keyfrom:"youdaocidian"},b={dict:"http://fanyi.youdao.com/openapi.do?keyfrom="+a.keyfrom+"&key="+a.key+"&type=data&doctype=json&version=1.1&q=",voice:"http://dict.youdao.com/dictvoice?audio=",dictHttps:"https://fanyi.youdao.com/openapi.do?keyfrom="+a.keyfrom+"&key="+a.key+"&type=data&doctype=json&version=1.1&q=",voiceHttps:"https://dict.youdao.com/dictvoice?audio="},c=this;c.initVoice=function(a,b){var c="";return c=1===b?"英音":2===b?"美音":"真人发音",fmt(frame.voiceContainer,a,c)},c.checkCode=function(a){var b={message:"",error:0,Code:0};switch(a){case 0:b.Message="查询成功";break;case 20:b.Message="要翻译的文本过长",b.error=1,b.Code=20;break;case 30:b.Message="无法进行有效的翻译",b.error=1,b.Code=30;break;case 40:b.Message="不支持的语言类型",b.error=1,b.Code=40;break;case 50:b.Message="无效的key",b.error=1,b.Code=50;break;case 60:b.Message="无辞典结果",b.error=1,b.Code=60}return b},c.shortWord=function(a){return a.slice(0,a.lastIndexOf(" ",50)).concat(" ...")},c.getVoice=function(a,c){var d=(currentSettings.useHttps?b.voiceHttps:b.voice)+a.query;return void 0!==c&&(d=d+"&type="+c),d},c.initTitle=function(a){var b=a.translation,d=a.query,e=c.initVoice(c.getVoice(a));d=d.length>=50&&"select"==c.wordSource?c.shortWord(d):d;var f=fmt(frame.titleWord,d,e),g=b?fmt(frame.titleTranslation,b.toString()):"";return{titleBlock:fmt(frame.titleContainer,f,g,d.length>=50?"long-text":"")}},c.haveTranslation=function(a){if(c.checkCode(a.errorCode).error||!b)return!1;var b=a.translation,d=a.query;return trim(d.toLowerCase())===trim(b.toString().toLowerCase())?!1:!0},c.parseBasicPhonetic=function(a){var b=a.basic,d=b["uk-phonetic"],e=b["us-phonetic"];if(void 0!==d&&void 0!==e){var f=c.initVoice(c.getVoice(a,1),1),g=fmt(frame.ukPhoneticContainer,"["+d+"]"+f),h=c.initVoice(c.getVoice(a,2),2),i=fmt(frame.usPhoneticContainer,"["+e+"]"+h);return fmt(frame.phoneticContainer,g,i)}return fmt(frame.phoneticContainer,"","")},c.parseProperty=function(a){var b="";switch(a){case"adj.":b="形容词";break;case"adv.":b="副词";break;case"n.":b="名词";break;case"vi.":b="不及物动词";break;case"vt.":b="及物动词";break;case"prep.":b="介词";break;case"conj.":b="连词";break;case"int.":b="感叹词";break;case"abbr.":b="代词";break;case"pron.":b=""}return b},c.parseBasicExplains=function(a){var b,d=a.basic,e=d.explains,f="";for(b=0;b
2 |
3 |
--------------------------------------------------------------------------------
/src/assets/fonts/YDdict-Icon-font.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XYUU/ChaZD/f1d020ca8fe02297abd113aaf91bfcb3cd176476/src/assets/fonts/YDdict-Icon-font.ttf
--------------------------------------------------------------------------------
/src/assets/fonts/YDdict-Icon-font.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XYUU/ChaZD/f1d020ca8fe02297abd113aaf91bfcb3cd176476/src/assets/fonts/YDdict-Icon-font.woff
--------------------------------------------------------------------------------
/src/inPage.css:
--------------------------------------------------------------------------------
1 | @charset "UTF-8";
2 | @-webkit-keyframes fade-in {
3 | from {
4 | opacity: 0;
5 | }
6 | to {
7 | opacity: 1;
8 | }
9 | }
10 | @-moz-keyframes fade-in {
11 | from {
12 | opacity: 0;
13 | }
14 | to {
15 | opacity: 1;
16 | }
17 | }
18 | @-o-keyframes fade-in {
19 | from {
20 | opacity: 0;
21 | }
22 | to {
23 | opacity: 1;
24 | }
25 | }
26 | @keyframes fade-in {
27 | from {
28 | opacity: 0;
29 | }
30 | to {
31 | opacity: 1;
32 | }
33 | }
34 | @-webkit-keyframes fade-out {
35 | from {
36 | opacity: 1;
37 | }
38 | to {
39 | opacity: 0;
40 | }
41 | }
42 | @-moz-keyframes fade-out {
43 | from {
44 | opacity: 1;
45 | }
46 | to {
47 | opacity: 0;
48 | }
49 | }
50 | @-o-keyframes fade-out {
51 | from {
52 | opacity: 1;
53 | }
54 | to {
55 | opacity: 0;
56 | }
57 | }
58 | @keyframes fade-out {
59 | from {
60 | opacity: 1;
61 | }
62 | to {
63 | opacity: 0;
64 | }
65 | }
66 | .ChaZD-result-side {
67 | position: fixed !important;
68 | right: 10px;
69 | top: 80px;
70 | }
71 |
72 | .ChaZD-result-container {
73 | width: 250px;
74 | overflow: auto;
75 | text-shadow: none;
76 | background-color: #ffffdd;
77 | text-align: left;
78 | color: #222222;
79 | padding: 10px;
80 | margin: 0px;
81 | opacity: 1;
82 | border: 1px solid #999999;
83 | border-radius: 4px;
84 | z-index: 999997;
85 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
86 | font-weight: normal;
87 | font-size: 14px;
88 | position: absolute;
89 | text-decoration: none;
90 | line-height: normal;
91 | box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.5);
92 | -webkit-box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.5);
93 | -webkit-animation: fade-in 0.3s ease;
94 | -moz-animation: fade-in 0.3s ease;
95 | -o-animation: fade-in 0.3s ease;
96 | animation: fade-in 0.3s ease;
97 | }
98 | .ChaZD-result-container #ChaZD-searching {
99 | border: none;
100 | padding: 0;
101 | margin: 0;
102 | }
103 | .ChaZD-result-container .title-container {
104 | background-color: #ffffdd;
105 | border: none;
106 | color: #222222;
107 | display: block;
108 | max-width: 100%;
109 | }
110 | .ChaZD-result-container .title-container .title-word {
111 | position: relative;
112 | max-width: 100%;
113 | text-align: left;
114 | font-size: 18px;
115 | }
116 | .ChaZD-result-container .title-container .title-word .voice-container {
117 | background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVQ4y2P4//8/AyUYQhAH3gNxA7IAIQPmo/H3g/QA8XkgFiBkwHyoYnRQABVfj88AmGZcTuuHyjlgMwBZM7IE3NlQGhQe65EN+I8Dw8MLGgYoFpFqADK/YUAMwOsFigORatFIlYRElaRMWmaiBAMAp0n+3U0kqkAAAAAASUVORK5CYII=");
118 | background-position: bottom center;
119 | background-repeat: no-repeat;
120 | cursor: pointer;
121 | opacity: 0.5;
122 | width: 16px;
123 | height: 16px;
124 | margin-left: 8px;
125 | display: inline-block;
126 | position: relative;
127 | top: 2px;
128 | }
129 | .ChaZD-result-container .title-container .title-word .voice-container:hover {
130 | opacity: 1;
131 | }
132 | .ChaZD-result-container .title-container .title-translation {
133 | display: none;
134 | color: #222222;
135 | margin-top: 10px;
136 | }
137 | .ChaZD-result-container .basic-container {
138 | background-color: #ffffdd;
139 | border: none;
140 | }
141 | .ChaZD-result-container .basic-container .phonetic-container .uk-phonetic-container, .ChaZD-result-container .basic-container .phonetic-container .us-phonetic-container {
142 | display: inline-block;
143 | color: red;
144 | margin-right: 5px;
145 | }
146 | .ChaZD-result-container .basic-container .phonetic-container .uk-phonetic-container:before {
147 | content: '英';
148 | color: #222222;
149 | font-size: 12px;
150 | margin-right: 2px;
151 | }
152 | .ChaZD-result-container .basic-container .phonetic-container .us-phonetic-container:before {
153 | content: '美';
154 | color: #222222;
155 | font-size: 12px;
156 | margin-right: 2px;
157 | }
158 | .ChaZD-result-container .basic-container .explains-container {
159 | font-size: 14px;
160 | margin-top: 10px;
161 | /*Result Block -- basic container -- explains container*/
162 | }
163 | .ChaZD-result-container .basic-container .explains-container .explains-list {
164 | list-style: none;
165 | margin: 0;
166 | padding: 0;
167 | }
168 | .ChaZD-result-container .basic-container .explains-container .explains-list .explains-item {
169 | padding: 0px;
170 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
171 | margin: 0 0 5px 0;
172 | list-style: none;
173 | font-size: 14px;
174 | background-color: transparent;
175 | }
176 | .ChaZD-result-container .basic-container .explains-container .explains-list .explains-item:before {
177 | display: none;
178 | }
179 | .ChaZD-result-container .basic-container .explains-container .explains-list .explains-item .property-container {
180 | display: block;
181 | float: left;
182 | font-weight: bold;
183 | color: #222222;
184 | margin-right: 5px;
185 | }
186 | .ChaZD-result-container .basic-container .explains-container .explains-list .explains-item .explains-item-value {
187 | display: block;
188 | overflow: hidden;
189 | }
190 | .ChaZD-result-container .basic-container .explains-container .voice-container {
191 | display: none;
192 | }
193 | .ChaZD-result-container .web-explains-container .web-title {
194 | font-weight: bold;
195 | opacity: 0.7;
196 | }
197 | .ChaZD-result-container .web-explains-container .web-explains-list {
198 | list-style: none;
199 | margin: 5px 0;
200 | padding: 0;
201 | }
202 | .ChaZD-result-container .web-explains-container .web-explains-list li .web-value {
203 | margin: 0 0 0 5px;
204 | }
205 | .ChaZD-result-container .unshow {
206 | display: none;
207 | }
208 |
209 | .ChaZD-arrow-main {
210 | position: absolute;
211 | z-index: 999997;
212 | -webkit-animation: fade-in 0.3s ease;
213 | -moz-animation: fade-in 0.3s ease;
214 | -o-animation: fade-in 0.3s ease;
215 | animation: fade-in 0.3s ease;
216 | }
217 |
218 | .ChaZD-arrow-outer-up, .ChaZD-arrow-outer-down {
219 | background: transparent;
220 | width: 0;
221 | border-left: 12px solid transparent;
222 | border-right: 12px solid transparent;
223 | position: absolute;
224 | left: 0;
225 | }
226 |
227 | .ChaZD-arrow-outer-up {
228 | border-bottom: 12px solid #999999;
229 | }
230 |
231 | .ChaZD-arrow-outer-down {
232 | border-top: 12px solid #999999;
233 | }
234 |
235 | .ChaZD-arrow-inner-up, .ChaZD-arrow-inner-down {
236 | background: transparent;
237 | width: 0;
238 | border-left: 10px solid transparent;
239 | border-right: 10px solid transparent;
240 | position: absolute;
241 | left: 2px;
242 | }
243 |
244 | .ChaZD-arrow-inner-up {
245 | border-bottom: 10px solid #ffffdd;
246 | top: 2px;
247 | }
248 |
249 | .ChaZD-arrow-inner-down {
250 | border-top: 10px solid #ffffdd;
251 | }
252 |
253 | a.ChaZD-link {
254 | text-decoration: none !important;
255 | cursor: text !important;
256 | }
257 |
258 | /*
259 | .ChaZD-result-container .voice-container::after {
260 | content: '\E803';
261 | font-family: "YDdict-Icon";
262 |
263 | -webkit-transition: color 0.2s linear;
264 | transition : color 0.2s linear;
265 | }
266 |
267 | .ChaZD-result-container .voice-container:hover {
268 | color: rgba(119, 110, 101, 1);
269 | }
270 | */
271 |
272 | /*# sourceMappingURL=inPage.css.map */
273 |
--------------------------------------------------------------------------------
/src/inPage.css.map:
--------------------------------------------------------------------------------
1 | {
2 | "version": 3,
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,OAAO,EAAE,CAAC;;EAChB,EAAG;IAAC,OAAO,EAAE,CAAC;;;AAGlB,kBAAmB;EACf,QAAQ,EAAE,gBAAgB;EAC1B,KAAK,EAAE,IAAI;EACX,GAAG,EAAE,IAAI;;;AAGb,uBAAwB;EACpB,KAAK,EAAE,KAAK;EACZ,QAAQ,EAAE,IAAI;EACd,WAAW,EAAE,IAAI;EACjB,gBAAgB,EArDA,OAAsB;EAsDtC,UAAU,EAAE,IAAI;EAChB,KAAK,EArDK,OAAmB;EAsD7B,OAAO,EAAE,IAAI;EACb,MAAM,EAAE,GAAG;EACX,OAAO,EAAE,CAAC;EACV,MAAM,EAAE,iBAAuB;EAC/B,aAAa,EAAE,GAAG;EAClB,OAAO,EAAE,MAAM;EACf,WAAW,EA/DA,8CAA8C;EAgEzD,WAAW,EAAE,MAAM;EACnB,SAAS,EA7DA,IAAI;EA8Db,QAAQ,EAAE,QAAQ;EAClB,eAAe,EAAE,IAAI;EACrB,WAAW,EAAE,MAAM;EA5DnB,UAAU,EAAE,+BAAoC;EAChD,kBAAkB,EAAE,+BAAoC;EAIxD,iBAAiB,EAAE,iBAAW;EAC9B,cAAc,EAAE,iBAAW;EAC3B,YAAY,EAAE,iBAAW;EACzB,SAAS,EAAE,iBAAW;;AAwDtB,wCAAiB;EACb,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,CAAC;EACV,MAAM,EAAE,CAAC;;AAGb,wCAAiB;EACb,gBAAgB,EA9EJ,OAAsB;EA+ElC,MAAM,EAAE,IAAI;EACZ,KAAK,EA9EC,OAAmB;EA+EzB,OAAO,EAAE,KAAK;EACd,SAAS,EAAE,IAAI;;AAEf,oDAAY;EACR,QAAQ,EAAE,QAAQ;EAClB,SAAS,EAAE,IAAI;EACf,UAAU,EAAE,IAAI;EAChB,SAAS,EAAE,IAAgB;;AAE3B,qEAAiB;EACb,gBAAgB,EAAE,iQAAiQ;EACnR,mBAAmB,EAAE,aAAa;EAClC,iBAAiB,EAAE,SAAS;EAC5B,MAAM,EAAE,OAAO;EACf,OAAO,EAAE,GAAG;EACZ,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;EACZ,WAAW,EAAE,GAAG;EAChB,OAAO,EAAE,YAAY;EACrB,QAAQ,EAAE,QAAQ;EAClB,GAAG,EAAE,GAAG;;AAER,2EAAQ;EACJ,OAAO,EAAE,CAAC;;AAKtB,2DAAmB;EACf,OAAO,EAAE,IAAI;EACb,KAAK,EA7GH,OAAmB;EA8GrB,UAAU,EA5GhB,IAAI;;AAgHN,wCAAiB;EACb,gBAAgB,EArHJ,OAAsB;EAsHlC,MAAM,EAAE,IAAI;;AAMR,wKAA+C;EAC3C,OAAO,EAAE,YAAY;EACrB,KAAK,EAAE,GAAG;EACV,YAAY,EAAE,GAAG;;AAGrB,0FAA8B;EAC1B,OAAO,EAAE,GAAG;EACZ,KAAK,EAlIP,OAAmB;EAmIjB,SAAS,EAAE,IAAgB;EAC3B,YAAY,EAAE,GAAG;;AAGrB,0FAA8B;EAC1B,OAAO,EAAE,GAAG;EACZ,KAAK,EAzIP,OAAmB;EA0IjB,SAAS,EAAE,IAAgB;EAC3B,YAAY,EAAE,GAAG;;AAKzB,4DAAoB;EAChB,SAAS,EAhJR,IAAI;EAiJL,UAAU,EAhJhB,IAAI;;;AAmJE,2EAAe;EACX,UAAU,EAAE,IAAI;EAChB,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;;AAEV,0FAAe;EAIX,OAAO,EAAE,GAAG;EACZ,WAAW,EAlKhB,8CAA8C;EAmKzC,MAAM,EAAE,SAAc;EACtB,UAAU,EAAE,IAAI;EAChB,SAAS,EAjKhB,IAAI;EAkKG,gBAAgB,EAAE,WAAW;;AAR7B,iGAAS;EACL,OAAO,EAAE,IAAI;;AASjB,8GAAoB;EAChB,OAAO,EAAE,KAAK;EACd,KAAK,EAAE,IAAI;EACX,WAAW,EAAE,IAAI;EACjB,KAAK,EAzKf,OAAmB;EA0KT,YAAY,EAAE,GAAG;;AAGrB,+GAAqB;EACjB,OAAO,EAAE,KAAK;EACd,QAAQ,EAAE,MAAM;;AAK5B,6EAAiB;EACb,OAAO,EAAE,IAAI;;AAOrB,0DAAW;EACP,WAAW,EAAE,IAAI;EACjB,OAAO,EAAE,GAAG;;AAGhB,kEAAmB;EACf,UAAU,EAAE,IAAI;EAChB,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,CAAC;;AAEN,gFAAW;EACP,MAAM,EAAE,SAAS;;AAMjC,+BAAQ;EACJ,OAAO,EAAE,IAAI;;;AAIrB,iBAAkB;EACd,QAAQ,EAAE,QAAQ;EAClB,OAAO,EAAE,MAAM;EA1Mf,iBAAiB,EAAE,iBAAW;EAC9B,cAAc,EAAE,iBAAW;EAC3B,YAAY,EAAE,iBAAW;EACzB,SAAS,EAAE,iBAAW;;;AA2M1B,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,CAAC;;;AAGX,qBAAsB;EAClB,aAAa,EAAE,kBAAwB;;;AAG3C,uBAAwB;EACpB,UAAU,EAAE,kBAAwB;;;AAGxC,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",
4 | "sources": ["sass/inPage.scss"],
5 | "names": [],
6 | "file": "inPage.css"
7 | }
8 |
--------------------------------------------------------------------------------
/src/javascript/background.js:
--------------------------------------------------------------------------------
1 | //字符串预处理,解析驼峰命名法和下划线命名法的单词、词组
2 | function preprocessWord (originWord) {
3 | if (originWord.indexOf(" ") === -1) {
4 | originWord = originWord.replace(/_/g, " ");
5 | if (/[a-z]+/.test(originWord)) {
6 | originWord = trim(originWord.replace(/([A-Z])/g, " $1"));
7 | }
8 | }
9 | return originWord;
10 | }
11 |
12 | /*
13 | ChaZD.prototype.parsePhrase = function (queryWord, key) {
14 | var words = [];
15 | words = queryWord.split(/\s+/);
16 | }
17 | */
18 | window.Notifications = window.Notifications || window.webkitNotifications;
19 |
20 | function showNotification(note) {
21 | if (!Notifications) {
22 | //console.log("[ChaZD] Your browse don't support notification.");
23 | return;
24 | }
25 | var notification = null, havePermission = Notifications.checkPermission();
26 | if (havePermission === 0) {
27 | notification = Notifications.createNotification(
28 | note.icon || chrome.extension.getURL("icons/icon128.png"),
29 | note.title || "ChaZD 查字典",
30 | note.content
31 | );
32 | notification.onclick = function () {
33 | window.open("https://chrome.google.com/webstore/detail/chazd/nkiipedegbhbjmajlhpegcpcaacbfggp");
34 | };
35 | notification.show();
36 | } else {
37 | Notifications.requestPermission();
38 | }
39 |
40 | return notification;
41 | }
42 |
43 | chrome.runtime.onInstalled.addListener(
44 | function (details) {
45 | if (details.reason === "install") {
46 | //console.log("[ChaZD] first install.");
47 | showNotification({
48 | title : "感谢支持 ChaZD !",
49 | content : "ChaZD 力求成为最简洁易用的 Chrome 词典扩展,欢迎提出您的意见或建议。" +
50 | "如果觉得 ChaZD 还不错,记得给5星好评哦:)"
51 | });
52 | //alert("Thank you for install my app:)");
53 | } else if (details.reason === "update") {
54 | //console.log("[ChaZD] update from version " + details.previousVersion);
55 | //alert("New version has updated!");
56 | chrome.storage.sync.set({"showTips" : true}, function() {
57 | //console.log("[ChaZD] Success update settings selectMode = mouseSelect");
58 | });
59 | showNotification({
60 | title : "ChaZD 更新到0.8.19版!",
61 | content : "修复若干 bug,如出现无法查词的问题,请在设置中关闭使用 HTTPS 接口"
62 | });
63 | }
64 | }
65 | );
66 |
67 | // chrome.contextMenus.create({"title": "在此页面禁用 ChaZD", "id": "deniedPage"});
68 | // chrome.contextMenus.create({"title": "在此站点禁用 ChaZD", "id": "deniedSite"});
69 | // chrome.contextMenus.create({"title": "管理禁用列表", "id": "deniedList"});
70 | // chrome.contextMenus.onClicked.addListener(function (info, tab){
71 | // console.log(JSON.stringify(info));
72 | // if (info.menuItemId === "deniedPage") {}
73 | // });
74 |
75 | chrome.storage.sync.get(null,function (items) {
76 | //console.log(JSON.stringify(items));
77 | if (items.showTips === undefined ) {
78 | //console.log("storage 是空的");
79 | chrome.storage.sync.set(settings);
80 | } else {
81 | //console.log("[ChaZD][Current Settings]");
82 | for (var key in items) {
83 | if (settings[key] === undefined) {
84 | chrome.storage.sync.remove(key);
85 | //console.log("Remove setting item '%s'", key);
86 | } else {
87 | settings[key] = items[key];
88 | }
89 | }
90 | chrome.storage.sync.set(settings);
91 | }
92 | });
93 |
94 | chrome.runtime.onMessage.addListener(
95 | function (message, sender, sendResponse) {
96 | var a = new api[currentSettings.apiName]();
97 | a.Query(preprocessWord(message.queryWord), message.source, sendResponse);
98 | return true;
99 | });
100 |
--------------------------------------------------------------------------------
/src/javascript/popup.js:
--------------------------------------------------------------------------------
1 | var $button = document.querySelector("#search");
2 | //var $tipsContainer = document.querySelector("#tips");
3 | var $input = document.querySelector("#query-word");
4 | var $queryResultContainer = document.querySelector("#query-result");
5 |
6 | if (-1 !== window.navigator.platform.toLowerCase().indexOf("mac")) {
7 | document.querySelector("#ctrl-option").firstChild.nodeValue = "Command";
8 | }
9 | // if (!$tipsContainer.classList.contains("unshow")){
10 | // $tipsContainer.classList.add("unshow");
11 | // }
12 |
13 |
14 | function queryInPopup(queryText) {
15 | //$input.select();
16 | if ($queryResultContainer.classList.contains("unshow")){
17 | $queryResultContainer.classList.remove("unshow");
18 | }
19 | if ($input.value !== "") {
20 | $queryResultContainer.innerHTML = "ψ(._. )>词典君正在翻译。。。";
21 | }
22 | //console.log("input value: " + $input.value);
23 | //console.log("quertText: " + queryText);
24 | if (queryText) {
25 | $input.value = queryText;
26 | chrome.extension.sendMessage({queryWord: queryText, source: "popup"}, buildResult);
27 | }
28 | else {
29 | chrome.extension.sendMessage({queryWord: $input.value, source: "popup"}, buildResult);
30 | }
31 | }
32 |
33 | var buildResult = function(response) {
34 | //alert("response from xhr: " + JSON.stringify(response));
35 | var resultObj = response;
36 | var resultBlock = "";
37 | if (resultObj.Code === 0) {
38 | resultBlock += resultObj.titleBlock;
39 | if (resultObj.basicBlock !== undefined) {
40 | resultBlock += resultObj.basicBlock;
41 | }
42 | if (resultObj.webBlock !== undefined) {
43 | resultBlock += resultObj.webBlock;
44 | }
45 | $queryResultContainer.innerHTML = resultBlock;
46 | var voiceCollection = document.querySelectorAll(".voice-container");
47 | var buildVoice = function (voice) {
48 | var src = voice.getAttribute("data-src");
49 | var audioBlock = document.createElement("audio");
50 | audioBlock.setAttribute("src", src);
51 | voice.appendChild(audioBlock);
52 | audioBlock.addEventListener("ended", function (event) {
53 | this.load();
54 | });
55 | voice.addEventListener("click", function (event) {
56 | audioBlock.play();
57 | });
58 | };
59 | var i, len;
60 | for (i = 0, len = voiceCollection.length; i < len; i++) {
61 | buildVoice(voiceCollection[i]);
62 | }
63 | } else {
64 | if (resultObj.Code == 20) {
65 | $queryResultContainer.innerHTML = "这段文字太长,词典君无能为力了(┬_┬)
试试短一点的吧~
";
66 | } else if (resultObj.Code == 40) {
67 | $queryResultContainer.innerHTML = "对不起,这段文字太高深了,请饶过词典君吧(┬_┬)
";
68 | } else {
69 | $queryResultContainer.innerHTML = "词典君罢工啦(┬_┬)
是不是网络不太好?
稍后再试一次吧
";
70 | }
71 | }
72 | };
73 |
74 | $button.addEventListener("click", function (event) {
75 | queryInPopup();
76 | });
77 |
78 | $input.select();
79 |
80 | $input.addEventListener("input", function (event) {
81 | var currentInput = $input.value;
82 | setTimeout(function () {
83 | if ($input.value === currentInput && $input.value !== "") {
84 | queryInPopup();
85 | }
86 | }, 500);
87 | });
88 |
89 | function createLink(link, url) {
90 | link.addEventListener("click", function (event) {
91 | chrome.tabs.create({"url": url});
92 | });
93 | }
94 |
95 | var issue = document.querySelector("#issue");
96 | var email = document.querySelector("#email");
97 | var source = document.querySelector("#source");
98 | var keySet = document.querySelector("#key-set");
99 | var score = document.querySelector("#score");
100 |
101 | createLink(email, "mailto:ververcpp@gmail.com");
102 | createLink(source, "https://github.com/ververcpp/ChaZD");
103 | createLink(issue, "https://github.com/ververcpp/ChaZD/issues/new");
104 | createLink(keySet, "chrome://extensions/configureCommands");
105 | createLink(score, "https://chrome.google.com/webstore/detail/chazd/nkiipedegbhbjmajlhpegcpcaacbfggp");
106 |
107 | document.querySelector("#setting-button").addEventListener("click", function (event) {
108 | var settingBlock = document.getElementById("settings");
109 | settingBlock.classList.toggle("active");
110 | if (settingBlock.classList.contains("active")) {
111 | settingBlock.style.height = blockHeight + "px";
112 | } else {
113 | settingBlock.style.height = 0;
114 | }
115 | });
116 |
117 | function totalHeight(className) {
118 | var divs = document.getElementsByClassName(className);
119 | var length = divs.length;
120 | var sum = 0;
121 | for (var i = 0; i < length; i++) {
122 | sum += divs[i].scrollHeight;
123 | }
124 | return sum + 10;
125 | }
126 |
127 | var blockHeight = totalHeight("top-menu") + totalHeight("sub-menu") + totalHeight("carved") + 52;
128 | var linkQuery = document.querySelector("#linkQuery");
129 | var noSelect = document.querySelector("#noSelect");
130 | var mouseSelect = document.querySelector("#mouseSelect");
131 | var useCtrl = document.querySelector("#useCtrl");
132 | var autoAudio = document.querySelector("#autoAudio");
133 | var human = document.querySelector("#human");
134 | var defaultUk = document.querySelector("#defaultUk");
135 | var defaultUs = document.querySelector("#defaultUs");
136 | var showPositionSide = document.querySelector("#showPositionSide");
137 | var showPositionNear = document.querySelector("#showPositionNear");
138 | var autoHide = document.querySelector("#autoHide");
139 | var showDuration = document.querySelector("#showDuration");
140 | var currentDuration = document.querySelector("#currentDuration");
141 | var turnOffTips = document.querySelector("#turn-off-tips");
142 | var tips = document.querySelector("#tips");
143 | var toggleKey = document.querySelector("#toggle-key");
144 | var useHttps = document.querySelector("#useHttps");
145 | var autoLearn = document.querySelector("#autoLearn");
146 | var openAPI = document.querySelector("#open-api");
147 |
148 | chrome.storage.sync.get(null, function (items) {
149 | if(items.currentWord !== "") {
150 | queryInPopup(items.currentWord);
151 | }
152 | if(items.linkQuery === true) {
153 | linkQuery.checked = true;
154 | linkQuery.nextSibling.classList.remove("unactive");
155 | } else {
156 | linkQuery.checked = false;
157 | linkQuery.nextSibling.classList.add("unactive");
158 | }
159 | if(items.useHttps === true) {
160 | useHttps.checked = true;
161 | useHttps.nextSibling.classList.remove("unactive");
162 | } else {
163 | useHttps.checked = false;
164 | useHttps.nextSibling.classList.add("unactive");
165 | }
166 | if(items.autoAudio === true) {
167 | autoAudio.checked = true;
168 | autoAudio.nextSibling.classList.remove("unactive");
169 | } else {
170 | autoAudio.checked = false;
171 | autoAudio.nextSibling.classList.add("unactive");
172 | }
173 | if(items.defaultVoice === 0) {
174 | human.checked = true;
175 | defaultUk.nextSibling.classList.remove("unactive");
176 | defaultUs.nextSibling.classList.remove("unactive");
177 | human.nextSibling.classList.add("unactive");
178 | }else if (items.defaultVoice === 1) {
179 | defaultUs.checked = true;
180 | human.nextSibling.classList.remove("unactive");
181 | defaultUs.nextSibling.classList.remove("unactive");
182 | defaultUk.nextSibling.classList.add("unactive");
183 | }else if (items.defaultVoice === 2) {
184 | defaultUs.checked = true;
185 | human.nextSibling.classList.remove("unactive");
186 | defaultUs.nextSibling.classList.remove("unactive");
187 | defaultUk.nextSibling.classList.add("unactive");
188 | }
189 | if (items.selectMode === "noSelect") {
190 | noSelect.checked = true;
191 | noSelect.nextSibling.classList.remove("unactive");
192 | mouseSelect.nextSibling.classList.add("unactive");
193 | useCtrl.nextSibling.classList.add("unactive");
194 |
195 | toggleKey.disabled = true;
196 | autoAudio.disabled = true;
197 | }
198 | if (items.selectMode === "mouseSelect") {
199 | mouseSelect.checked = true;
200 | mouseSelect.nextSibling.classList.remove("unactive");
201 | noSelect.nextSibling.classList.add("unactive");
202 | useCtrl.nextSibling.classList.add("unactive");
203 |
204 | toggleKey.disabled = true;
205 | autoAudio.disabled = false;
206 | }
207 | if (items.selectMode === "useCtrl") {
208 | useCtrl.checked = true;
209 | useCtrl.nextSibling.classList.remove("unactive");
210 | noSelect.nextSibling.classList.add("unactive");
211 | mouseSelect.nextSibling.classList.add("unactive");
212 |
213 | toggleKey.disabled = false;
214 | autoAudio.disabled = false;
215 | }
216 | if (items.showTips) {
217 | tips.classList.remove("unshow");
218 | }
219 | if (items.showPosition === "side") {
220 | showPositionSide.checked = true;
221 | showPositionSide.nextSibling.classList.remove("unactive");
222 | showPositionNear.nextSibling.classList.add("unactive");
223 | } else if (items.showPosition === "near") {
224 | showPositionNear.checked = true;
225 | showPositionSide.nextSibling.classList.add("unactive");
226 | showPositionNear.nextSibling.classList.remove("unactive");
227 | }
228 | if (items.toggleKey === "ctrl") {
229 | toggleKey.selectedIndex = 0;
230 | } else if (items.toggleKey === "alt") {
231 | toggleKey.selectedIndex = 1;
232 | } else if (items.toggleKey === "shift") {
233 | toggleKey.selectedIndex = 2;
234 | }
235 | if (items.apiName === "shanbay") {
236 | openAPI.selectedIndex = 0;
237 | } else if (items.apiName === "xyuu") {
238 | openAPI.selectedIndex = 1;
239 | } else if (items.apiName === "youdao") {
240 | openAPI.selectedIndex = 2;
241 | }
242 | if (items.autoHide === true) {
243 | autoHide.checked = true;
244 | autoHide.nextSibling.classList.remove("unactive");
245 | showDuration.disabled = false;
246 | } else {
247 | autoHide.checked = false;
248 | autoHide.nextSibling.classList.add("unactive");
249 | showDuration.disabled = true;
250 | }
251 | if(items.autoLearn === true) {
252 | autoLearn.checked = true;
253 | autoLearn.nextSibling.classList.remove("unactive");
254 | } else {
255 | autoLearn.checked = false;
256 | autoLearn.nextSibling.classList.add("unactive");
257 | }
258 | currentDuration.innerHTML = showDuration.value = items.showDuration;
259 | });
260 |
261 | linkQuery.addEventListener("click", function (event) {
262 | var currentLinkQuery = linkQuery.checked;
263 | linkQuery.nextSibling.classList.toggle("unactive");
264 | chrome.storage.sync.set({"linkQuery": currentLinkQuery}, function() {
265 | //console.log("[ChaZD] Success update settings linkQuery = " + currentLinkQuery);
266 | });
267 | });
268 |
269 | useHttps.addEventListener("click", function (event) {
270 | var currentUseHttps = useHttps.checked;
271 | useHttps.nextSibling.classList.toggle("unactive");
272 | chrome.storage.sync.set({"useHttps": currentUseHttps});
273 | });
274 |
275 | autoAudio.addEventListener("click", function (event) {
276 | var currentAutoAudio = autoAudio.checked;
277 | if (currentAutoAudio) {
278 | autoAudio.nextSibling.classList.remove("unactive");
279 | } else {
280 | autoAudio.nextSibling.classList.add("unactive");
281 | }
282 | chrome.storage.sync.set({"autoAudio": currentAutoAudio}, function() {
283 | //console.log("[ChaZD] Success update settings autoAudio = " + currentAutoAudio);
284 | });
285 | });
286 | //自动加入生词本
287 | autoLearn.addEventListener("click", function (event) {
288 | var currentAutoLearn = autoLearn.checked;
289 | if (currentAutoLearn) {
290 | autoLearn.nextSibling.classList.remove("unactive");
291 | } else {
292 | autoLearn.nextSibling.classList.add("unactive");
293 | }
294 | chrome.storage.sync.set({"autoLearn": currentAutoLearn}, function() {
295 | //console.log("[ChaZD] Success update settings autoLearn = " + currentAutoLearn);
296 | });
297 | });
298 |
299 | human.addEventListener("click", function (event) {
300 | human.nextSibling.classList.remove("unactive");
301 | human.nextSibling.classList.add("unactive");
302 | chrome.storage.sync.set({"defaultVoice": 0}, function() {
303 | //console.log("[ChaZD] Success update settings defaultVoice = 1");
304 | });
305 | });
306 |
307 | defaultUk.addEventListener("click", function (event) {
308 | defaultUk.nextSibling.classList.remove("unactive");
309 | defaultUs.nextSibling.classList.add("unactive");
310 | chrome.storage.sync.set({"defaultVoice": 1}, function() {
311 | //console.log("[ChaZD] Success update settings defaultVoice = 1");
312 | });
313 | });
314 |
315 | defaultUs.addEventListener("click", function (event) {
316 | defaultUs.nextSibling.classList.remove("unactive");
317 | defaultUk.nextSibling.classList.add("unactive");
318 | chrome.storage.sync.set({"defaultVoice": 2}, function() {
319 | //console.log("[ChaZD] Success update settings defaultVoice = 2");
320 | });
321 | });
322 |
323 | turnOffTips.addEventListener("click", function (event) {
324 | tips.classList.add("unshow");
325 | chrome.storage.sync.set({"showTips": false}, function() {
326 | //console.log("[ChaZD] Success update settings showTips = false");
327 | });
328 | });
329 |
330 | noSelect.addEventListener("click", function (event) {
331 | toggleKey.disabled = true;
332 | autoAudio.disabled = true;
333 |
334 | noSelect.nextSibling.classList.remove("unactive");
335 | mouseSelect.nextSibling.classList.add("unactive");
336 | useCtrl.nextSibling.classList.add("unactive");
337 | chrome.storage.sync.set({"selectMode" : "noSelect"}, function() {
338 | //console.log("[ChaZD] Success update settings selectMode = noSelect");
339 | });
340 | });
341 |
342 | mouseSelect.addEventListener("click", function (event) {
343 | toggleKey.disabled = true;
344 | autoAudio.disabled = false;
345 |
346 | noSelect.nextSibling.classList.add("unactive");
347 | mouseSelect.nextSibling.classList.remove("unactive");
348 | useCtrl.nextSibling.classList.add("unactive");
349 | chrome.storage.sync.set({"selectMode" : "mouseSelect"}, function() {
350 | //console.log("[ChaZD] Success update settings selectMode = mouseSelect");
351 | });
352 | });
353 |
354 | useCtrl.addEventListener("click", function (event) {
355 | //console.log(toggleKey.disabled);
356 | if (toggleKey.disabled) {
357 | toggleKey.disabled = false;
358 | }
359 | autoAudio.disabled = false;
360 | noSelect.nextSibling.classList.add("unactive");
361 | mouseSelect.nextSibling.classList.add("unactive");
362 | useCtrl.nextSibling.classList.remove("unactive");
363 | chrome.storage.sync.set({"selectMode" : "useCtrl"}, function() {
364 | //console.log("[ChaZD] Success update settings selectMode = useCtrl");
365 | });
366 | });
367 |
368 | showPositionSide.addEventListener("click", function (event) {
369 | showPositionSide.nextSibling.classList.remove("unactive");
370 | showPositionNear.nextSibling.classList.add("unactive");
371 | chrome.storage.sync.set({"showPosition" : "side"}, function() {
372 | //console.log("[ChaZD] Success update settings showPosition = side");
373 | });
374 | });
375 |
376 | showPositionNear.addEventListener("click", function (event) {
377 | showPositionSide.nextSibling.classList.add("unactive");
378 | showPositionNear.nextSibling.classList.remove("unactive");
379 | chrome.storage.sync.set({"showPosition" : "near"}, function() {
380 | //console.log("[ChaZD] Success update settings showPosition = near");
381 | });
382 | });
383 |
384 | autoHide.addEventListener("click", function (event) {
385 | var currentAutoHide = autoHide.checked;
386 | if (currentAutoHide) {
387 | autoHide.nextSibling.classList.remove("unactive");
388 | showDuration.disabled = false;
389 | } else {
390 | autoHide.nextSibling.classList.add("unactive");
391 | showDuration.disabled = true;
392 | }
393 | chrome.storage.sync.set({"autoHide" : currentAutoHide}, function() {
394 | //console.log("[ChaZD] Success update settings showPosition = near");
395 | });
396 | });
397 |
398 | showDuration.addEventListener("input", function (event) {
399 | currentDuration.innerHTML = showDuration.value;
400 | chrome.storage.sync.set({"showDuration" : showDuration.value}, function() {
401 | //console.log("[ChaZD] Success update settings toggleKey = " + this.value);
402 | });
403 | });
404 |
405 | toggleKey.onchange = function (event) {
406 | chrome.storage.sync.set({"toggleKey" : this.value}, function() {
407 | //console.log("[ChaZD] Success update settings toggleKey = " + this.value);
408 | });
409 | };
410 |
411 | openAPI.onchange = function (event) {
412 | chrome.storage.sync.set({"apiName" : this.value}, function() {
413 | //console.log("[ChaZD] Success update settings toggleKey = " + this.value);
414 | });
415 | };
416 | // showDuration.addEventListener("onclick", function (event) {
417 | // currentDuration.innerHTML = event.target.value;
418 | // updateSetting("duration", event.target.value);
419 | // })
--------------------------------------------------------------------------------
/src/javascript/selection.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | var preSelection = {
3 | top: 0,
4 | bottom: 0,
5 | left: 0,
6 | right: 0,
7 | again: 0
8 | };
9 |
10 | var timeout;
11 |
12 | var queryInPage = function(event) {
13 | var selection = window.getSelection && window.getSelection();
14 | if(selection && selection.rangeCount > 0) {
15 | var selectText = trim(selection.toString());
16 | var selectRange = selection.getRangeAt(0).getBoundingClientRect();
17 | if (isExist(selectRange, preSelection) && preSelection.again) {
18 | preSelection.again = 0;
19 | return;
20 | }
21 |
22 | if (selectText === "" || !(/^[^\u4e00-\u9fa5]+$/.test(selectText))) {return;}
23 | var haveResult = document.documentElement.querySelectorAll(".ChaZD-result-container");
24 | for (var i = 0, len = haveResult.length; i < len; i++) {
25 | if (haveResult[i].getAttribute("data-text").toLowerCase() === selectText.toLowerCase()){return;}
26 | }
27 | ////////if (currentQueryWord !== "" && selectText === currentQueryWord) {return;}
28 | chrome.storage.sync.set({"currentWord" : selectText}, function() {
29 | //console.log("[ChaZD] Success update settings currentWord = " + selectText);
30 | });
31 | for (var key in preSelection) {
32 | if (key == "again") {
33 | preSelection[key] = 1;
34 | }
35 | else {
36 | preSelection[key] = selectRange[key];
37 | }
38 | }
39 | if (currentSettings.showPosition === "side") {
40 | //console.log("in 1");
41 | showResultSide(selectText, currentSettings.useHttps);
42 | }
43 | if (currentSettings.showPosition === "near") {
44 | //console.log("in 2");
45 | showResultNear(selectText, currentSettings.useHttps, selectRange, event);
46 | }
47 | }
48 | };
49 |
50 | var showResultSide = function (text, useHttps) {
51 | //if(isExist(text)) return;
52 | var $resultSideContainer = makeResultContainer(text, useHttps);
53 | $resultSideContainer.classList.add("ChaZD-result-side");
54 | document.documentElement.appendChild($resultSideContainer);
55 |
56 | if (currentSettings.autoHide) {
57 | timeout = setTimeout(function () {
58 | if (document.querySelector(".ChaZD-result-container")) {
59 | document.documentElement.removeChild($resultSideContainer);
60 | ////////currentQueryWord = "";
61 | }
62 | }, 1000 * currentSettings.showDuration);
63 | }
64 | };
65 |
66 | var showResultNear = function (text, useHttps, range, event) {
67 | //if(isExist(text)) return;
68 | var resultNearContainer = makeResultContainer(text, useHttps);
69 | var arrowMain = makeArrowDiv();
70 | document.documentElement.appendChild(resultNearContainer);
71 | document.documentElement.appendChild(arrowMain);
72 |
73 | var showNearPosition = {};
74 | //文本框中选取的内容返回的left top 为0,此时采集鼠标的位置
75 | if (range.left === 0 && range.top === 0) {
76 | range = {
77 | left: event.clientX,
78 | top: event.clientY,
79 | height: 15
80 | };
81 | }
82 |
83 | var containerWidth = resultNearContainer.offsetWidth;
84 | //var arrowWidth = arrowMain.width();
85 | var rangeWidth = range.right - range.left;
86 | //console.log("arrow width: " + arrowWidth);
87 | var left = range.left + window.pageXOffset;
88 | var top = range.top + window.pageYOffset;
89 | var rangeMiddle = rangeWidth/2 + left;
90 | var containerLeft = left - (containerWidth - rangeWidth)/2;
91 | var arrowLeft = rangeMiddle - 12;
92 |
93 | if (containerLeft < window.pageXOffset) {
94 | containerLeft = window.pageXOffset;
95 | } else if (containerLeft + containerWidth > window.pageXOffset + document.documentElement.clientWidth) {
96 | containerLeft = window.pageXOffset + document.documentElement.clientWidth - containerWidth;
97 | }
98 |
99 | var clientHeight = 0;
100 | clientHeight = (document.documentElement.clientHeight > document.body.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
101 | if (clientHeight === 0) {
102 | clientHeight = document.documentElement.clientHeight;
103 | }
104 | //console.log("[ChaZD]clientHeight : " + clientHeight);
105 |
106 | if (range.top >= 150) {
107 | var bottom = clientHeight - top + 10;
108 | var arrowBottom = bottom + 1;
109 | showNearPosition = {
110 | left: containerLeft,
111 | bottom: bottom,
112 | arrowLeft: arrowLeft,
113 | arrowBottom: arrowBottom
114 | };
115 | } else {
116 | showNearPosition = {
117 | left: containerLeft,
118 | top: top + range.height + 12,
119 | arrowLeft: arrowLeft,
120 | arrowTop: top + range.height + 1
121 | };
122 | }
123 |
124 | // var arrowMain = $arrowMain;
125 | // var resultNearContainer = resultNearContainer[0];
126 | //resultNearContainer.style.position = "absolute";
127 | resultNearContainer.style.left = showNearPosition.left + "px";
128 | arrowMain.style.left = showNearPosition.arrowLeft + "px";
129 | var chazdArrowOuter = document.querySelectorAll(".ChaZD-arrow-outer");
130 | var chazdArrowInner = document.querySelectorAll(".ChaZD-arrow-inner");
131 | var i, len;
132 | if (showNearPosition.bottom) {
133 | resultNearContainer.style.bottom = showNearPosition.bottom + "px";
134 | arrowMain.style.bottom = showNearPosition.arrowBottom + "px";
135 | for (i = 0, len = chazdArrowOuter.length; i < len; i++) {
136 | chazdArrowOuter[i].classList.add("ChaZD-arrow-outer-down");
137 | chazdArrowInner[i].classList.add("ChaZD-arrow-inner-down");
138 | }
139 | }
140 | if (showNearPosition.top) {
141 | resultNearContainer.style.top = showNearPosition.top + "px";
142 | arrowMain.style.top = showNearPosition.arrowTop + "px";
143 | for (i = 0, len = chazdArrowOuter.length; i < len; i++) {
144 | chazdArrowOuter[i].classList.add("ChaZD-arrow-outer-up");
145 | chazdArrowInner[i].classList.add("ChaZD-arrow-inner-up");
146 | }
147 | }
148 |
149 | if (currentSettings.autoHide) {
150 | timeout = setTimeout(function () {
151 | if (document.querySelector(".ChaZD-result-container") && document.querySelector(".ChaZD-arrow-main")) {
152 | document.documentElement.removeChild(resultNearContainer);
153 | document.documentElement.removeChild(arrowMain);
154 | ////////currentQueryWord = "";
155 | }
156 | }, 1000 * currentSettings.showDuration);
157 | }
158 | // var t = setTimeout(function () {
159 | // document.body.removeChild(resultNearContainer);
160 | // }, 1000 * duration);
161 | };
162 |
163 | var makeArrowDiv = function () {
164 | // var arrowDivMain = document.createElement("div");
165 | // arrowDivMain.classList.add("ChaZD-arrow-main");
166 | var arrowDivMain = document.createElement("div");
167 | arrowDivMain.classList.add("ChaZD-arrow-main");
168 | var arrowDivOuter = document.createElement("div");
169 | arrowDivOuter.setAttribute("class", "ChaZD-arrow-outer");
170 | var arrowDivInner = document.createElement("div");
171 | arrowDivInner.setAttribute("class", "ChaZD-arrow-inner");
172 | arrowDivMain.appendChild(arrowDivOuter);
173 | arrowDivMain.appendChild(arrowDivInner);
174 |
175 | return arrowDivMain;
176 | };
177 |
178 | var makeResultContainer = function (text, useHttps) {
179 | var $resultContainer = document.createElement("div");
180 | $resultContainer.classList.add("ChaZD-result-container");
181 | $resultContainer.setAttribute("data-text", text);
182 | var $searchingNode = document.createElement("div");
183 | $searchingNode.setAttribute("id", "ChaZD-searching");
184 | $searchingNode.innerHTML = "ψ(._. )>划词君正在翻译。。。";
185 | $resultContainer.appendChild($searchingNode);
186 | chrome.runtime.sendMessage({
187 | queryWord: text,
188 | source: "select"
189 | }, function(response) {
190 | var resultObj = response;
191 | $searchingNode.innerHTML = "";
192 | if (resultObj.Code === 0) {
193 | $resultContainer.innerHTML = resultObj.titleBlock;
194 | var singleVoiceButton = $resultContainer.querySelector(".voice-container");
195 | var buildVoice = function (voice) {
196 | var src = voice.getAttribute("data-src");
197 | var audioBlock = document.createElement("audio");
198 | if(currentSettings.defaultVoice){
199 | src += "&type=" + currentSettings.defaultVoice;
200 | }
201 | audioBlock.setAttribute("src", src);
202 | voice.appendChild(audioBlock);
203 | if (currentSettings.autoAudio === true) {
204 | audioBlock.play();
205 | }
206 | audioBlock.addEventListener("ended", function (event) {
207 | this.load();
208 | });
209 | voice.addEventListener("click", function (event) {
210 | audioBlock.play();
211 | });
212 | };
213 | buildVoice(singleVoiceButton);
214 | var temp = document.createElement("div");
215 | if (resultObj.basicBlock) {
216 | temp.innerHTML = resultObj.basicBlock;
217 | $resultContainer.appendChild(temp);
218 | }
219 | else if (resultObj.haveTranslation) {
220 | $resultContainer.querySelector(".title-translation").style.display = "block";
221 | } else if (resultObj.haveWebTranslation) {
222 | temp.innerHTML = resultObj.webBlock;
223 | $resultContainer.appendChild(temp);
224 | $resultContainer.querySelector(".web-title").innerHTML = "网络释义";
225 | } else {
226 | $resultContainer.innerHTML = "╮(╯▽╰)╭划词君无能为力啊
还是右键问问谷歌君吧=>";
227 | }
228 | } else {
229 | if (resultObj.Code == 20) {
230 | $resultContainer.innerHTML = "这段文字太长,词典君无能为力了(┬_┬)
试试短一点的吧~
";
231 | } else if (resultObj.Code == 40) {
232 | $resultContainer.innerHTML = "对不起,这段文字太高深了,请饶过词典君吧(┬_┬)
";
233 | } else {
234 | $resultContainer.innerHTML = "词典君罢工啦(┬_┬)
是不是网络不太好?
稍后再试一次吧
";
235 | }
236 | }
237 | });
238 | return $resultContainer;
239 | };
240 |
241 | function isExist(newRange, oldRange) {
242 | if (newRange.top === oldRange.top &&
243 | newRange.bottom === oldRange.bottom &&
244 | newRange.left === oldRange.left &&
245 | newRange.right === oldRange.right) {
246 | return true;
247 | }
248 | return false;
249 | }
250 |
251 | 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"];
252 |
253 | document.documentElement.addEventListener("mousedown", function(event) {
254 | //console.log("event.target: " + event.target.className);
255 | for (var name in classNameCollection) {
256 | if (event.target.classList.contains(classNameCollection[name])) {
257 | //console.log("[ChaZD] don't remove");
258 | return;
259 | }
260 | }
261 | // var existResult = document.getElementsByClassName("ChaZD-result-container");
262 | // for (var i = 0; i < existResult.length; i++) {
263 | // existResult[i].parentNode.removeChild(existResult[i]);
264 | // }
265 | clearTimeout(timeout);
266 | var chazdResult = document.querySelectorAll(".ChaZD-result-container");
267 | var chazdArrow = document.querySelectorAll(".ChaZD-arrow-main");
268 | var i, len;
269 | if (chazdResult) {
270 | for (i = 0, len = chazdResult.length; i < len; i++) {
271 | document.documentElement.removeChild(chazdResult[i]);
272 | }
273 | }
274 | if (chazdArrow) {
275 | for (i = 0, len = chazdArrow.length; i < len; i++) {
276 | document.documentElement.removeChild(chazdArrow[i]);
277 | }
278 | }
279 | chrome.storage.sync.set({"currentWord" : ""});
280 | ////////currentQueryWord = "";
281 | //clearSelection(event);
282 | });
283 |
284 | window.addEventListener("resize", function(event) {
285 | var chazdResult = document.querySelector(".ChaZD-result-container");
286 | var chazdArrow = document.querySelector(".ChaZD-arrow-main");
287 | if (chazdResult) {
288 | document.documentElement.removeChild(chazdResult);
289 | }
290 | if (chazdArrow) {
291 | document.documentElement.removeChild(chazdArrow);
292 | }
293 | ////////currentQueryWord = "";
294 | });
295 |
296 | var queryEvent = function (event) {
297 | //console.log("[ChaZD] current useCtrl: " + useCtrl);
298 | if (currentSettings.selectMode === "noSelect") {return;}
299 | if (currentSettings.selectMode === "useCtrl") {
300 | //console.log("current togglekey: " + toggleKey);
301 | if (currentSettings.toggleKey === "ctrl") {
302 | //console.log("[ChaZD] In Ctrl");
303 | if (!event.ctrlKey && !event.metaKey) {
304 | //console.log("[ChaZD] Aho~~~");
305 | preSelection.again = 0;
306 | return;
307 | }
308 | } else if (currentSettings.toggleKey === "alt") {
309 | //console.log("[ChaZD] In Alt");
310 | if (!event.altKey) {
311 | preSelection.again = 0;
312 | //console.log("[ChaZD] Aho~~~");
313 | return;
314 | }
315 | } else if (currentSettings.toggleKey === "shift") {
316 | //console.log("[ChaZD] In Shift");
317 | if (!event.shiftKey) {
318 | preSelection.again = 0;
319 | //console.log("[ChaZD] Aho~~~");
320 | return;
321 | }
322 | }
323 | }
324 | queryInPage(event);
325 | };
326 |
327 | var link = null;
328 |
329 | var focusLink = function (event) {
330 | if (currentSettings.linkQuery) {
331 | //event.stopPropagation();
332 | //console.log("focusLink");
333 | link = event.target;
334 | //console.log(link);
335 | if(event.shiftKey) {
336 | // alert("have shift");
337 | disableLink(event);
338 | }
339 |
340 | }
341 | };
342 |
343 | var blurLink = function (event) {
344 | if (currentSettings.linkQuery) {
345 | //event.stopPropagation();
346 | if (link && link.classList.contains("ChaZD-link")) {
347 | enableLink(event, true);
348 | }
349 | link = null;
350 | }
351 | };
352 |
353 | var disableLink = function (event) {
354 | if (link && event.shiftKey) {
355 | clearSelection(event);
356 | link.setAttribute("ChaZD-href", link.getAttribute("href"));
357 | link.removeAttribute("href");
358 | link.classList.add("ChaZD-link");
359 | }
360 | };
361 |
362 | var enableLink = function (event, ignoreKey) {
363 | if (link && (ignoreKey || event.keyCode == 16)) {
364 | link.setAttribute("href", link.getAttribute("ChaZD-href"));
365 | link.removeAttribute("ChaZD-href");
366 | link.classList.remove("ChaZD-link");
367 | }
368 | };
369 |
370 | var clearSelection = function (event) {
371 | if (currentSettings.linkQuery && event.shiftKey) {
372 | window.getSelection().empty();
373 | }
374 | };
375 |
376 | document.documentElement.addEventListener("mouseup", queryEvent);
377 | document.documentElement.addEventListener("mouseover", function (e) {
378 | if (e.target.nodeName === "A" || e.target.nodeName === "a") {
379 | focusLink(e);
380 | }
381 | });
382 | document.documentElement.addEventListener("mouseout", function (e) {
383 | if (e.target.nodeName === "A" || e.target.nodeName === "a") {
384 | blurLink(e);
385 | }
386 | });
387 | // var links = document.querySelectorAll("a");
388 | // console.log(links);
389 | // for (var i = 0, len = links.length; i < len; i++) {
390 | // links[i].addEventListener("mouseover", function (e) {
391 | // console.log("heloo world");
392 | // });
393 | // //links[i].addEventListener("mouseleave", blurLink);
394 | // }
395 | document.documentElement.addEventListener("keydown", disableLink);
396 | document.documentElement.addEventListener("keyup", enableLink);
397 | document.documentElement.addEventListener("selectstart", queryEvent); //bug!!
398 | })();
399 |
--------------------------------------------------------------------------------
/src/javascript/utility.js:
--------------------------------------------------------------------------------
1 | function ajax(method,url,data,cb,before){
2 | var xhr = new XMLHttpRequest();
3 | xhr.open(method, url, true);
4 | xhr.onreadystatechange = function(){
5 | if (xhr.readyState != 4) {
6 | return;
7 | }
8 | cb(xhr);
9 | };
10 | if(before !== undefined) {
11 | before(xhr);
12 | }
13 | xhr.send(data);
14 | }
15 |
16 | var settings = {
17 | selectMode : "mouseSelect", //划词的形式:直接划词 or Ctrl + 划词
18 | showPosition : "near", //划词翻译结果显示的位置
19 | toggleKey : "ctrl",
20 | showTips : true, //是否显示 Tips
21 | currentWord: "", //当前划词查询的内容
22 | linkQuery: false, //在链接上划词
23 | autoAudio: false, //划词自动发音
24 | autoHide: false, //自动隐藏翻译结果
25 | showDuration: 3, //翻译结果显示持续时间
26 | defaultVoice: 0, //划词默认发音:0--真人发音;1--英音;2--美音
27 | useHttps: false, //是否使用 HTTPS 的接口
28 | autoLearn:true, //是否自动加入生词本
29 | apiName:"shanbay"
30 | };
31 | var currentSettings = settings;
32 | chrome.storage.sync.get(null, function(items) {
33 | for (var key in items) {
34 | currentSettings[key] = items[key];
35 | }
36 | });
37 | chrome.storage.onChanged.addListener(function(changes) {
38 | if (changes.linkQuery !== undefined) {
39 | currentSettings.linkQuery = changes.linkQuery.newValue;
40 | }
41 | if (changes.useHttps !== undefined) {
42 | currentSettings.useHttps = changes.useHttps.newValue;
43 | }
44 | if (changes.autoAudio !== undefined) {
45 | currentSettings.autoAudio = changes.autoAudio.newValue;
46 | }
47 | if (changes.defaultVoice !== undefined) {
48 | currentSettings.defaultVoice = changes.defaultVoice.newValue;
49 | }
50 | if (changes.selectMode !== undefined) {
51 | currentSettings.selectMode = changes.selectMode.newValue;
52 | }
53 | if (changes.toggleKey !== undefined) {
54 | currentSettings.toggleKey = changes.toggleKey.newValue;
55 | }
56 | if (changes.autoHide !== undefined) {
57 | currentSettings.autoHide = changes.autoHide.newValue;
58 | }
59 | if (changes.showDuration !== undefined) {
60 | currentSettings.showDuration = changes.showDuration.newValue;
61 | }
62 | if (changes.showPosition !== undefined) {
63 | currentSettings.showPosition = changes.showPosition.newValue;
64 | }
65 | if (changes.autoLearn !== undefined) {
66 | currentSettings.autoLearn = changes.autoLearn.newValue;
67 | }
68 | if (changes.apiName !== undefined) {
69 | currentSettings.apiName = changes.apiName.newValue;
70 | }
71 | });
72 | var frame = {
73 | //title frame
74 | titleContainer : "#{1}#{2}
",
75 | titleWord : "#{1}#{2}
",
76 | voiceContainer : "",
77 | titleTranslation : "#{1}
",
78 |
79 | //basic frame
80 | basicContainer : "#{1}#{2}
",
81 |
82 | //basic phonetic frame
83 | phoneticContainer : "#{1}#{2}
",
84 | ukPhoneticContainer : "#{1}
",
85 | usPhoneticContainer : "#{1}
",
86 |
87 | //basic explain frame
88 | explainsContainer : "#{1}
",
89 | explainsList : "",
90 | explain : "#{1}#{2}",
91 | propertyContainer : "#{2}",
92 |
93 | //web explain frame
94 | webExplainsContainer : "",
95 | webExplainsList : "",
96 | webExplain : "#{1}#{2}"
97 | };
98 | var youdao = function(){
99 | var config = {key: 1116151381,keyfrom : "youdaocidian"};
100 | var urls = {
101 | dict : "http://fanyi.youdao.com/openapi.do?keyfrom=" + config.keyfrom +"&key="+ config.key +"&type=data&doctype=json&version=1.1&q=",
102 | voice : "http://dict.youdao.com/dictvoice?audio=",
103 | dictHttps : "https://fanyi.youdao.com/openapi.do?keyfrom=" + config.keyfrom +"&key="+ config.key +"&type=data&doctype=json&version=1.1&q=",
104 | voiceHttps : "https://dict.youdao.com/dictvoice?audio="
105 | };
106 | var self = this;
107 | self.initVoice = function (src, type) {
108 | var title = "";
109 | if(type === 1){
110 | title = "英音";
111 | } else if (type === 2){
112 | title = "美音";
113 | } else {
114 | title = "真人发音";
115 | }
116 | return fmt(frame.voiceContainer, src, title);
117 | };
118 | self.checkCode = function (Code) {
119 | var response = {
120 | "message": "",
121 | "error": 0,
122 | "Code": 0
123 | };
124 | switch (Code) {
125 | case 0:
126 | response.Message = "查询成功";
127 | break;
128 | case 20:
129 | response.Message = "要翻译的文本过长";
130 | response.error = 1;
131 | response.Code = 20;
132 | break;
133 | case 30:
134 | response.Message = "无法进行有效的翻译";
135 | response.error = 1;
136 | response.Code = 30;
137 | break;
138 | case 40:
139 | response.Message = "不支持的语言类型";
140 | response.error = 1;
141 | response.Code = 40;
142 | break;
143 | case 50:
144 | response.Message = "无效的key";
145 | response.error = 1;
146 | response.Code = 50;
147 | break;
148 | case 60:
149 | response.Message = "无辞典结果";
150 | response.error = 1;
151 | response.Code = 60;
152 | break;
153 | default:
154 | }
155 | return response;
156 | };
157 | self.shortWord = function (longWord) {
158 | return longWord.slice(0, longWord.lastIndexOf(" ", 50)).concat(" ...");
159 | };
160 | self.getVoice = function(result, type){
161 | var src = (currentSettings.useHttps ? urls.voiceHttps : urls.voice) + result.query;
162 | if(type !== undefined) {
163 | src = src + "&type=" + type;
164 | }
165 | return src;
166 | };
167 | self.initTitle = function (result) {
168 | var translation = result.translation;
169 | var queryWord = result.query;
170 | var voiceContainer = self.initVoice(self.getVoice(result));
171 | queryWord = queryWord.length >= 50 && self.wordSource == "select" ? self.shortWord(queryWord) : queryWord;
172 | var titleWord = fmt(frame.titleWord, queryWord, voiceContainer);
173 | var titleTranslation = translation?fmt(frame.titleTranslation, translation.toString()): "";
174 | return {
175 | titleBlock : fmt(frame.titleContainer, titleWord, titleTranslation, queryWord.length >=50 ? "long-text" : "")
176 | };
177 | };
178 | self.haveTranslation = function (result) {
179 | if (self.checkCode(result.errorCode).error||!translation) {
180 | return false;
181 | }
182 | var translation = result.translation;
183 | var queryWord = result.query;
184 | if (trim(queryWord.toLowerCase()) === trim(translation.toString().toLowerCase())) {
185 | return false;
186 | }
187 | return true;
188 | };
189 | self.parseBasicPhonetic = function (result) {
190 | var basic = result.basic;
191 | var ukPhonetic = basic["uk-phonetic"];
192 | var usPhonetic = basic["us-phonetic"];
193 | if (ukPhonetic !== undefined && usPhonetic !== undefined) {
194 | var ukVoice = self.initVoice(self.getVoice(result,1), 1);
195 | var ukPhoneticContainer = fmt(frame.ukPhoneticContainer, "[" + ukPhonetic + "]" + ukVoice);
196 | var usVoice = self.initVoice(self.getVoice(result,2), 2);
197 | var usPhoneticContainer = fmt(frame.usPhoneticContainer, "[" + usPhonetic + "]" + usVoice);
198 | return fmt(frame.phoneticContainer, ukPhoneticContainer, usPhoneticContainer);
199 | }
200 | return fmt(frame.phoneticContainer, "", "");
201 | };
202 | self.parseProperty = function (property) {
203 | var propertyText = "";
204 | switch (property) {
205 | case "adj." :
206 | propertyText = "形容词";
207 | break;
208 | case "adv." :
209 | propertyText = "副词";
210 | break;
211 | case "n." :
212 | propertyText = "名词";
213 | break;
214 | case "vi." :
215 | propertyText = "不及物动词";
216 | break;
217 | case "vt." :
218 | propertyText = "及物动词";
219 | break;
220 | case "prep." :
221 | propertyText = "介词";
222 | break;
223 | case "conj." :
224 | propertyText = "连词";
225 | break;
226 | case "int." :
227 | propertyText = "感叹词";
228 | break;
229 | case "abbr." :
230 | propertyText = "代词";
231 | break;
232 | case "pron." :
233 | propertyText = "";
234 | break;
235 | default :
236 | }
237 | return propertyText;
238 | };
239 | self.parseBasicExplains = function (result) {
240 | var basic = result.basic;
241 | var explains = basic.explains;
242 | var i;
243 | var explainsContent = "";
244 | for (i = 0; i < explains.length; i++) {
245 | var currentExplain = explains[i];
246 | var haveProperty = currentExplain.indexOf(". ");
247 | var property = (haveProperty !== -1) ? currentExplain.slice(0, haveProperty + 1) : "";
248 | var propertyTitle = self.parseProperty(property);
249 | var propertyContainer = fmt(frame.propertyContainer, propertyTitle, property);
250 | var explainText = (haveProperty !== -1) ? currentExplain.slice(haveProperty + 1) : currentExplain;
251 | var explain = fmt(frame.explain, propertyContainer, explainText);
252 | explainsContent += explain;
253 | }
254 | return fmt(frame.explainsContainer, fmt(frame.explainsList, explainsContent));
255 | };
256 | self.parseBasicResult = function (result) {
257 | var phoneticBlock = self.parseBasicPhonetic(result);
258 | var explainsBlock = self.parseBasicExplains(result);
259 | var basicContainer = fmt(frame.basicContainer, phoneticBlock, explainsBlock);
260 | return basicContainer;
261 | };
262 | self.parseWebResult = function (result) {
263 | var web = result.web;
264 | var webExplainsContent = "";
265 | var i;
266 | for (i = 0; i < web.length ; i++) {
267 | var webExplain = fmt(frame.webExplain, web[i].key, web[i].value);
268 | webExplainsContent += webExplain;
269 | }
270 | return fmt(frame.webExplainsContainer, fmt(frame.webExplainsList, webExplainsContent));
271 | };
272 | self.parseResult = function (result) {
273 | //console.log("Response Text: \n" + responseText);
274 | var resultObj = self.checkCode(result.errorCode);
275 | resultObj.haveWebTranslation = false;
276 | if (!resultObj.error) {
277 | var title = self.initTitle(result);
278 | resultObj.titleBlock = title.titleBlock;
279 | resultObj.haveTranslation = self.haveTranslation(result);
280 | if (result.basic !== undefined) {
281 | var basicBlock = self.parseBasicResult(result);
282 | resultObj.basicBlock = basicBlock;
283 | }
284 | if (result.web !== undefined) {
285 | var webBlock = self.parseWebResult(result);
286 | resultObj.haveWebTranslation = true;
287 | resultObj.webBlock = webBlock;
288 | }
289 | }
290 | return resultObj;
291 | };
292 | var Query = function(queryWord, wordSource, sendResponse) {
293 | self.wordSource = wordSource;
294 | var url = (currentSettings.useHttps ? urls.dictHttps : urls.dict) + queryWord;
295 | ajax("GET", url, null, function (xhr) {
296 | var result = JSON.parse(xhr.responseText);
297 | if (queryWord.indexOf("-") != -1 && !self.checkCode(result.errorCode).error && !self.haveTranslation(result)) {
298 | //优化使用连字符的词的查询结果
299 | new Query(queryWord.replace(/-/g, " "), wordSource, sendResponse);
300 | } else {
301 | var ret = self.parseResult(result);
302 | sendResponse(ret);
303 | }
304 | });
305 | };
306 | self.Query = Query;
307 | };
308 |
309 | var shanbay = function(){
310 | var self = this;
311 | self.dict = "http://www.shanbay.com/api/v1/bdc/search/?word=";
312 | self.learn = "http://www.shanbay.com/api/v1/bdc/learning/";
313 | self.login = "http://www.shanbay.com/accounts/login/";
314 | youdao.call(this);
315 |
316 | /*jshint camelcase: false */
317 | self.getVoice = function(result,type){
318 | var basic = result.basic;
319 | var src = basic.audio;
320 | if(type == 1) {
321 | src = basic.uk_audio;
322 | }else if(type == 2){
323 | src = basic.us_audio;
324 | }
325 | return src;
326 | };
327 | self.parseBasicPhonetic = function (result) {
328 | var basic = result.basic;
329 | if (basic.pronunciations) {
330 | var ukPhonetic = basic.pronunciations.uk;
331 | var usPhonetic = basic.pronunciations.us;
332 | if(ukPhonetic !== undefined && usPhonetic !== undefined){
333 | var ukVoice = self.initVoice(self.getVoice(result,1), 1);
334 | var ukPhoneticContainer = fmt(frame.ukPhoneticContainer, "[" + ukPhonetic + "]" + ukVoice);
335 | var usVoice = self.initVoice(self.getVoice(result,2), 2);
336 | var usPhoneticContainer = fmt(frame.usPhoneticContainer, "[" + usPhonetic + "]" + usVoice);
337 | return fmt(frame.phoneticContainer, ukPhoneticContainer, usPhoneticContainer);
338 | }
339 | }
340 | var voice = self.initVoice(self.getVoice(result));
341 | var phoneticContainer = fmt(frame.usPhoneticContainer, "[" + basic.phonetic + "]" + voice);
342 | return fmt(frame.phoneticContainer, phoneticContainer, "");
343 | };
344 | self.parseBasicExplains = function (result) {
345 | var basic = result.basic;
346 | var definition = basic.definition;
347 | var i;
348 | var explainsContent = "";
349 | var explains = definition.split("\n");
350 | for (i = 0; i < explains.length; i++) {
351 | var currentExplain = explains[i];
352 | var haveProperty = currentExplain.indexOf(".");
353 | var property = (haveProperty !== -1) ? currentExplain.slice(0, haveProperty + 1) : "";
354 | var propertyTitle = self.parseProperty(property);
355 | var propertyContainer = fmt(frame.propertyContainer, propertyTitle, property);
356 | var explainText = (haveProperty !== -1) ? currentExplain.slice(haveProperty + 1) : currentExplain;
357 | var explain = fmt(frame.explain, propertyContainer, explainText);
358 | explainsContent += explain;
359 | }
360 | return fmt(frame.explainsContainer, fmt(frame.explainsList, explainsContent));
361 | };
362 | self.Query = function(queryWord, wordSource, sendResponse) {
363 | var url = self.dict + queryWord;
364 | /*jshint camelcase: false */
365 | ajax("GET", url, null, function (xhr) {
366 | var result = JSON.parse(xhr.responseText);
367 | var data = result.data;
368 | if (result.status_code === 0) {
369 | data = {basic:{
370 | pronunciations:data.pronunciations,
371 | phonetic:data.pron,
372 | audio:data.audio,
373 | us_audio:data.us_audio,
374 | uk_audio:data.uk_audio,
375 | cn_definition:data.cn_definition,
376 | en_definition:data.en_definition,
377 | definition:data.definition
378 | },query:data.content,errorCode:0};
379 | var ret = self.parseResult(data);
380 | sendResponse(ret);
381 | data = {id: result.data.id, content_type: "vocabulary"};
382 | //加入生词本
383 | if(currentSettings.autoLearn){
384 | ajax("POST", self.learn, JSON.stringify(data), function (xhr) {
385 | var result = JSON.parse(xhr.responseText);
386 | if(xhr.status == 401){
387 | if (confirm(result.msg+"\n你选择了自动加入生词本,但你没有登陆扇贝网或登陆已失效,是否现在登陆?")){
388 | chrome.tabs.create({ url: self.login });
389 | }else{
390 | currentSettings.autoLearn = false;
391 | }
392 | }
393 | }, function (xhr) {
394 | xhr.setRequestHeader("Content-Type", "application/json");
395 | });
396 | }
397 | } else if (result.status_code === 1) {
398 | var y = new youdao();
399 | y.Query(queryWord, wordSource, sendResponse);
400 | }
401 | });
402 | };
403 | };
404 |
405 | var xyuu = function(){
406 | shanbay.call(this);
407 | this.dict ="http://dict.xyuu.com.cn/search/?word=";
408 | };
409 |
410 | var api = {
411 | youdao:youdao,
412 | shanbay:shanbay,
413 | xyuu:xyuu
414 | };
415 |
416 | //判断一个初始化后的对象是否为空
417 | function isEmpty(obj) {
418 | for (var name in obj) {
419 | return false;
420 | }
421 | return true;
422 | }
423 |
424 | /*
425 | * 文本模板函数fmt, @greatghoul
426 | * 参考TransIt。
427 | */
428 | function fmt() {
429 | var args = arguments;
430 | return args[0].replace(/#{(.*?)}/g, function (match, prop) {
431 | return function (obj, props) {
432 | var prop = /\d+/.test(props[0]) ? parseInt(props[0]) : props[0];
433 | if (props.length > 1) {
434 | return arguments.callee(obj[prop], props.slice(1));
435 | } else {
436 | return obj[prop];
437 | }
438 | }(typeof args[1] === "object" ? args[1] : args, prop.split(/\.|\[|\]\[|\]\./));
439 | });
440 | }
441 |
442 | function trim(str) {
443 | return str.replace(/(^\s*)|(\s*$)/g, "");
444 | }
--------------------------------------------------------------------------------
/src/sass/inPage.scss:
--------------------------------------------------------------------------------
1 | $font-family : "Helvetica Neue", Helvetica, Arial, sans-serif;
2 | $background-color : rgba(255, 255, 221, 1);
3 | $border-color : rgba(153, 153, 153, 1);
4 | $text-color : rgba(34, 34, 34, 1);
5 | $font-size : 14px;
6 | $gap: 10px;
7 |
8 | @mixin box-shadow($horizontal, $vertical, $radius, $color) {
9 | box-shadow: $horizontal $vertical $radius $color;
10 | -webkit-box-shadow: $horizontal $vertical $radius $color;
11 | }
12 |
13 | @mixin animation($animate) {
14 | -webkit-animation: #{$animate};
15 | -moz-animation: #{$animate};
16 | -o-animation: #{$animate};
17 | animation: #{$animate};
18 | }
19 |
20 | @mixin keyframes($animationName) {
21 | @-webkit-keyframes #{$animationName} {
22 | @content;
23 | }
24 | @-moz-keyframes #{$animationName} {
25 | @content;
26 | }
27 | @-o-keyframes #{$animationName} {
28 | @content;
29 | }
30 | @keyframes #{$animationName} {
31 | @content;
32 | }
33 | }
34 |
35 | @include keyframes(fade-in) {
36 | from {opacity: 0;}
37 | to {opacity: 1;}
38 | }
39 |
40 | @include keyframes(fade-out) {
41 | from {opacity: 1;}
42 | to {opacity: 0;}
43 | }
44 |
45 | .ChaZD-result-side {
46 | position: fixed !important;
47 | right: 10px;
48 | top: 80px;
49 | }
50 |
51 | .ChaZD-result-container {
52 | width: 250px;
53 | overflow: auto;
54 | text-shadow: none;
55 | background-color: $background-color;
56 | text-align: left;
57 | color: $text-color;
58 | padding: 10px;
59 | margin: 0px;
60 | opacity: 1;
61 | border: 1px solid $border-color;
62 | border-radius: 4px;
63 | z-index: 999997;
64 | font-family: $font-family;
65 | font-weight: normal;
66 | font-size: $font-size;
67 | position: absolute;
68 | text-decoration: none;
69 | line-height: normal;
70 | @include box-shadow(0px, 0px, 20px,rgba(0, 0, 0, 0.5));
71 | @include animation("fade-in 0.3s ease");
72 |
73 | #ChaZD-searching {
74 | border: none;
75 | padding: 0;
76 | margin: 0;
77 | }
78 |
79 | .title-container {
80 | background-color: $background-color;
81 | border: none;
82 | color: $text-color;
83 | display: block;
84 | max-width: 100%;
85 |
86 | .title-word {
87 | position: relative;
88 | max-width: 100%;
89 | text-align: left;
90 | font-size: $font-size + 4px;
91 |
92 | .voice-container {
93 | background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAcUlEQVQ4y2P4//8/AyUYQhAH3gNxA7IAIQPmo/H3g/QA8XkgFiBkwHyoYnRQABVfj88AmGZcTuuHyjlgMwBZM7IE3NlQGhQe65EN+I8Dw8MLGgYoFpFqADK/YUAMwOsFigORatFIlYRElaRMWmaiBAMAp0n+3U0kqkAAAAAASUVORK5CYII=");
94 | background-position: bottom center;
95 | background-repeat: no-repeat;
96 | cursor: pointer;
97 | opacity: 0.5;
98 | width: 16px;
99 | height: 16px;
100 | margin-left: 8px;
101 | display: inline-block;
102 | position: relative;
103 | top: 2px;
104 |
105 | &:hover {
106 | opacity: 1;
107 | }
108 | }
109 | }
110 |
111 | .title-translation {
112 | display: none;
113 | color: $text-color;
114 | margin-top: $gap;
115 | }
116 | }
117 |
118 | .basic-container {
119 | background-color: $background-color;
120 | border: none;
121 | //margin-top: $gap;
122 |
123 | .phonetic-container {
124 |
125 | //display: none;
126 | .uk-phonetic-container, .us-phonetic-container {
127 | display: inline-block;
128 | color: red;
129 | margin-right: 5px;
130 | }
131 |
132 | .uk-phonetic-container:before {
133 | content: '英';
134 | color: $text-color;
135 | font-size: $font-size - 2px;
136 | margin-right: 2px;
137 | }
138 |
139 | .us-phonetic-container:before {
140 | content: '美';
141 | color: $text-color;
142 | font-size: $font-size - 2px;
143 | margin-right: 2px;
144 | }
145 |
146 | }
147 |
148 | .explains-container {
149 | font-size: $font-size;
150 | margin-top: $gap;
151 |
152 | /*Result Block -- basic container -- explains container*/
153 | .explains-list {
154 | list-style: none;
155 | margin: 0;
156 | padding: 0;
157 |
158 | .explains-item {
159 | &:before {
160 | display: none;
161 | }
162 | padding: 0px;
163 | font-family: $font-family;
164 | margin: 0 0 $gap / 2 0;
165 | list-style: none;
166 | font-size: $font-size;
167 | background-color: transparent;
168 |
169 | .property-container {
170 | display: block;
171 | float: left;
172 | font-weight: bold;
173 | color: $text-color;
174 | margin-right: 5px;
175 | }
176 |
177 | .explains-item-value {
178 | display: block;
179 | overflow: hidden;
180 | }
181 | }
182 | }
183 |
184 | .voice-container {
185 | display: none;
186 | }
187 | }
188 | }
189 |
190 | .web-explains-container {
191 |
192 | .web-title {
193 | font-weight: bold;
194 | opacity: 0.7;
195 | }
196 |
197 | .web-explains-list {
198 | list-style: none;
199 | margin: 5px 0;
200 | padding: 0;
201 | li {
202 | .web-value {
203 | margin: 0 0 0 5px;
204 | }
205 | }
206 | }
207 | }
208 |
209 | .unshow {
210 | display: none;
211 | }
212 | }
213 |
214 | .ChaZD-arrow-main {
215 | position: absolute;
216 | z-index: 999997;
217 | @include animation("fade-in 0.3s ease");
218 | }
219 |
220 | .ChaZD-arrow-outer-up, .ChaZD-arrow-outer-down {
221 | background: transparent;
222 | width: 0;
223 | border-left: 12px solid transparent;
224 | border-right: 12px solid transparent;
225 | position: absolute;
226 | left: 0;
227 | }
228 |
229 | .ChaZD-arrow-outer-up {
230 | border-bottom: 12px solid $border-color;
231 | }
232 |
233 | .ChaZD-arrow-outer-down {
234 | border-top: 12px solid $border-color;
235 | }
236 |
237 | .ChaZD-arrow-inner-up, .ChaZD-arrow-inner-down {
238 | background: transparent;
239 | width: 0;
240 | border-left: 10px solid transparent;
241 | border-right: 10px solid transparent;
242 | position: absolute;
243 | left: 2px;
244 | // z-index: 999999;
245 | }
246 |
247 | .ChaZD-arrow-inner-up {
248 | border-bottom: 10px solid $background-color;
249 | top: 2px;
250 | }
251 |
252 | .ChaZD-arrow-inner-down {
253 | border-top: 10px solid $background-color;
254 | }
255 |
256 | a.ChaZD-link {
257 | text-decoration: none !important;
258 | cursor: text !important;
259 | }
260 | /*
261 | .ChaZD-result-container .voice-container::after {
262 | content: '\E803';
263 | font-family: "YDdict-Icon";
264 |
265 | -webkit-transition: color 0.2s linear;
266 | transition : color 0.2s linear;
267 | }
268 |
269 | .ChaZD-result-container .voice-container:hover {
270 | color: rgba(119, 110, 101, 1);
271 | }
272 | */
--------------------------------------------------------------------------------
/src/style.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: "YDdict-Icon";
3 | src: url("fonts/YDdict-Icon-font.eot");
4 | src: url("fonts/YDdict-Icon-font.svg") format("svg"),
5 | url("fonts/YDdict-Icon-font.woff") format("woff");
6 | font-weight: normal;
7 | font-style: normal;
8 | }
9 |
10 | @keyframes slide-down {
11 | from {
12 | transform: scaleY(0);
13 | -webkit-transform: scaleY(0);
14 | }
15 | to {
16 | transform: scaleY(1);
17 | -webkit-transform: scaleY(1);
18 | }
19 | }
20 |
21 | @-webkit-keyframes slide-down {
22 | from {
23 | transform: scaleY(0);
24 | -webkit-transform: scaleY(0);
25 | }
26 | to {
27 | transform: scaleY(1);
28 | -webkit-transform: scaleY(1);
29 | }
30 | }
31 |
32 | @keyframes fade-in {
33 | from {
34 | opacity: 0;
35 | }
36 | to {
37 | opacity: 1;
38 | }
39 | }
40 |
41 | @-webkit-keyframes fade-in {
42 | from {
43 | opacity: 0;
44 | }
45 | to {
46 | opacity: 1;
47 | }
48 | }
49 |
50 | @keyframes fade-out {
51 | from {
52 | opacity: 1;
53 | }
54 | to {
55 | opacity: 0;
56 | visibility: hidden;
57 | }
58 | }
59 |
60 | @-webkit-keyframes fade-out {
61 | from {
62 | opacity: 1;
63 | }
64 | to {
65 | opacity: 0;
66 | visibility: hidden;
67 | }
68 | }
69 |
70 | @keyframes slide-up {
71 | from {
72 | transform: scaleY(1);
73 | -webkit-transform: scaleY(1);
74 | }
75 | to {
76 | transform: scaleY(0);
77 | -webkit-transform: scaleY(0);
78 | }
79 | }
80 |
81 | @-webkit-keyframes slide-up {
82 | from {
83 | transform: scaleY(1);
84 | -webkit-transform: scaleY(1);
85 | }
86 | to {
87 | transform: scaleY(0);
88 | -webkit-transform: scaleY(0);
89 | }
90 | }
91 |
92 | body {
93 | margin: 0.5em;
94 | padding: 0;
95 | width: 300px;
96 | background-color: #faf8ef;
97 | color: #776e65;
98 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
99 | font-size: 14px;
100 | }
101 |
102 | ul {
103 | list-style: none;
104 | margin: 0;
105 | padding: 0;
106 | }
107 |
108 | .input-container{
109 | position: relative;
110 | margin: 0;
111 | border: 1px solid #dbd8e4;
112 | box-shadow: -0.2px -0.2px 0.2px 0.2px ;
113 | border-radius: 3px;
114 | }
115 |
116 | .input-container:after {
117 | content: "";
118 | display: block;
119 | clear: both;
120 | }
121 |
122 | .input-area {
123 | display: block;
124 | padding: 2px;
125 | border: none;
126 | font-size: 1.3em;
127 | width: 270px;
128 | margin: 1px 0 0 20px;
129 | border-radius: 3px;
130 | }
131 |
132 | .input-area:focus {
133 | outline: none;
134 | }
135 |
136 | .query-button {
137 | display: block;
138 | height: 100%;
139 | position: absolute;
140 | top:0;
141 | left: 0;
142 | border: 0;
143 | border-radius: 1px;
144 | margin: 0;
145 | padding: 4px;
146 | background-color: transparent;
147 | line-height: 19px;
148 | color: rgba(0, 0, 0, 0.2);
149 |
150 | }
151 |
152 | .query-button:focus {
153 | outline-color: transparent;
154 | }
155 |
156 | .query-button:hover {
157 | color: rgba(0, 0, 0, 1);
158 | }
159 |
160 | .query-button:active {
161 | color: rgba(235, 0, 0, 1);
162 | }
163 |
164 | .query-button::after {
165 | content: '\E800';
166 | -webkit-transition: color 0.2s linear;
167 | transition: color 0.2s linear;
168 | font-size: 0.8em;
169 | font-family: "YDdict-Icon";
170 | }
171 |
172 |
173 |
174 | /*Result Block*/
175 | .result-container {
176 | margin-top: 10px;
177 | padding: 4px;
178 | }
179 |
180 | .unshow {
181 | display: none;
182 | }
183 |
184 | /*Result Block -- title contaniner*/
185 | .title-container {
186 | margin-left: 10px;
187 | display: flex;
188 | min-width: 50%;
189 | max-width: 100%;
190 | font-size: 22px;
191 | }
192 |
193 | .title-container.long-text {
194 | font-size: 16px;
195 | }
196 |
197 | .title-container .title-phonetic {
198 | display: none;
199 | }
200 |
201 | .title-container .title-word {
202 | position: relative;
203 | max-width: 50%;
204 | text-align: left;
205 | }
206 |
207 | .title-container .title-word .voice-container {
208 | display: inline-block;
209 | margin-left: 10px;
210 |
211 | }
212 |
213 | .title-container .title-word .voice-container::after {
214 | content: '\E804';
215 | font-family: "YDdict-Icon";
216 | font-size: 70%;
217 | }
218 |
219 | .title-container .title-translation {
220 | flex:1;
221 | margin-left: 10px;
222 | text-align: justify;
223 | max-width: 50%;
224 | }
225 |
226 |
227 | /*Result Block -- basic container*/
228 | .basic-container {
229 | margin-top: 10px;
230 | }
231 |
232 | /*Result Block -- basic container -- phonetic container*/
233 | .phonetic-container {
234 | margin-left: 10px;
235 | font-size: 1em;
236 | }
237 |
238 | .uk-phonetic-container::before {
239 | content: "英 ";
240 | color: #776e65;
241 | }
242 |
243 | .us-phonetic-container::before {
244 | content: "美 ";
245 | color: #776e65;
246 | }
247 |
248 | .uk-phonetic-container, .us-phonetic-container {
249 | display: inline-block;
250 | margin-right: 10px;
251 | color: red;
252 | }
253 |
254 | .voice-container {
255 | cursor: pointer;
256 | display: inline-block;
257 | margin-left: 10px;
258 | color: rgba(119, 110, 101, 0.2);
259 | }
260 |
261 | .voice-container::after {
262 | content: '\E803';
263 | font-family: "YDdict-Icon";
264 |
265 | -webkit-transition: color 0.2s linear;
266 | transition : color 0.2s linear;
267 | }
268 |
269 | .voice-container:hover {
270 | color: rgba(119, 110, 101, 1);
271 | }
272 |
273 |
274 | /*Result Block -- basic container -- explains container*/
275 | .explains-container {
276 | font-size: 14px;
277 | margin-top: 10px;
278 | }
279 |
280 | .explains-list {
281 | border: 1px solid #F0EFF0;
282 | border-radius: 1px;
283 | padding: 10px;
284 | }
285 |
286 | .explains-list li {
287 | margin-bottom: 5px;
288 | }
289 |
290 | .property-container {
291 | margin-right: 5px;
292 | }
293 |
294 | /*Result Block -- web explains container*/
295 | .web-explains-container {
296 | font-size: 14px;
297 | margin-top: 20px;
298 | position: relative;
299 | }
300 |
301 | .web-title {
302 | position: absolute;
303 | top: -5px;
304 | left: 10px;
305 | background-color: #faf8ef;
306 | font-weight: bold;
307 | }
308 |
309 | .web-title::before {
310 | content: '\E802';
311 | font-family: "YDdict-Icon";
312 | margin-right: 5px;
313 | color: #ccbb1e;
314 | }
315 |
316 | .web-explains-list {
317 | border: 1px solid #F0EFF0;
318 | border-radius: 1px;
319 | padding: 10px;
320 | padding-top: 20px;
321 | }
322 |
323 | .web-explains-list li {
324 | margin-bottom: 5px;
325 | }
326 |
327 | .web-explains-list li .web-key {
328 | font-weight: bold;
329 | }
330 |
331 | .web-explains-list li .web-value {
332 | margin-left: 5px;
333 | }
334 |
335 | .tips-container {
336 | position: relative;
337 | padding: 5px;
338 | font-size: 0.4em;
339 | color: rgba(0, 0, 0, 0.4);
340 | }
341 |
342 | .tips-container p {
343 | margin: 0;
344 | margin-top: 5px;
345 | padding: 0;
346 | }
347 |
348 | .tips-container .link {
349 | color: rgba(0, 161, 194, 1);
350 | cursor: pointer;
351 | -webkit-transition: color 0.2s linear;
352 | transition : color 0.2s linear;
353 | }
354 |
355 | #turn-off-tips {
356 | position: absolute;
357 | right: 5px;
358 | bottom: 5px;
359 | cursor: pointer;
360 | text-decoration: underline;
361 | }
362 |
363 | footer {
364 | font-size: 0.3em;
365 | text-align: center;
366 | position: relative;
367 | color: rgba(0, 0, 0, 0.2);
368 | }
369 |
370 | footer img {
371 | position: relative;
372 | top:4px;
373 | width: 50px;
374 | opacity: 0.6;
375 | }
376 |
377 | .contact-info {
378 | font-size: 0.3em;
379 | font-family: "YDdict-Icon";
380 | position: absolute;
381 | bottom:0;
382 | right: 0;
383 | }
384 |
385 | .link {
386 | cursor: pointer;
387 | text-decoration: none;
388 | color: rgba(0, 0, 0, 0.6);
389 | opacity: 0.5;
390 | }
391 |
392 | .link:hover {
393 | color: rgba(0, 0, 0, 1);
394 | }
395 |
396 | #score::after {
397 | content: '\E80B';
398 | -webkit-transition: color 0.2s linear;
399 | transition: color 0.2s linear;
400 | }
401 |
402 | #email::after {
403 | content: '\E806';
404 | -webkit-transition: color 0.2s linear;
405 | transition : color 0.2s linear;
406 | }
407 |
408 | #issue::after {
409 | content: '\E805';
410 |
411 | -webkit-transition: color 0.2s linear;
412 | transition : color 0.2s linear;
413 | }
414 |
415 | #source::after {
416 | content: '\E807';
417 |
418 | -webkit-transition: color 0.2s linear;
419 | transition : color 0.2s linear;
420 | }
421 |
422 | .setting-button {
423 | position: absolute;
424 | bottom:0;
425 | left: 0;
426 | cursor: pointer;
427 | font-size: 0.3em;
428 | font-family: "YDdict-Icon";
429 | }
430 |
431 | .setting-button-clicked {
432 | color: #000000;
433 | }
434 |
435 | .setting-button::after {
436 | content: "\E80A";
437 | -webkit-transition: color 0.2s linear;
438 | transition : color 0.2s linear;
439 | }
440 |
441 | .setting-block {
442 | margin: 5px 0;
443 | text-align: justify;
444 | border: 0px solid #F0EFF0;
445 | border-radius: 1px;
446 | background-color: #f2ecd4;
447 | max-height: 0;
448 | height: 0;
449 | overflow-y: hidden;
450 | color: #6e665e;
451 | transition: all .5s cubic-bezier(0, 1, 0.5, 1);
452 | -webkit-transition: all .5s cubic-bezier(0, 1, 0.5, 1);
453 | }
454 |
455 | .active {
456 | border: 1px solid #F0EFF0;
457 | max-height: 800px;
458 | }
459 |
460 | .setting-slide-up {
461 | animation: fade-out 0.4s ease forwards;
462 | -webkit-animation: fade-out 0.4s ease forwards;
463 | }
464 |
465 | .setting-slide-down {
466 | display: block;
467 | animation: fade-in 0.4s ease forwards;
468 | -webkit-animation: fade-in 0.4s ease forwards;
469 | }
470 |
471 | .setting-block div {
472 | margin-top: 5px;
473 | padding: 1px 10px;
474 | }
475 |
476 | .setting-block .top-menu {
477 | margin-bottom: 5px;
478 | }
479 |
480 | .setting-block .sub-menu {
481 | margin-top: 5px;
482 | }
483 |
484 | .setting-block .link-query {
485 | margin-left: 5px;
486 | }
487 |
488 | .setting-block .help {
489 | font-size: 12px;
490 | cursor: help;
491 | }
492 |
493 | .setting-block label {
494 | margin-left: 5px;
495 | }
496 |
497 | .setting-block label.unactive {
498 | color: rgba(0, 0, 0, 0.5);
499 | }
500 |
501 | .setting-block input {
502 | margin: 0;
503 | }
504 |
505 | .setting-block .sub-title {
506 | margin-left: 17px;
507 | font-size: 90%;
508 | }
509 |
510 | .setting-block .sub-button {
511 | margin-left: 5px;
512 | }
513 |
514 | .setting-block .sub-label{
515 | font-size: 90%;
516 | }
517 |
518 | #currentDuration {
519 | display: inline-block;
520 | width: 14px;
521 | text-align: center;
522 | }
523 |
524 | input[type="range"] {
525 | width: 100px;
526 | position: relative;
527 | top:3px;
528 | }
529 |
530 | #save {
531 | position: absolute;
532 | top: 0;
533 | right: 0;
534 | }
535 |
536 | #cancel {
537 | position: absolute;
538 | top: 25px;
539 | right: 0;
540 | }
541 |
542 | hr.carved {
543 | clear: both;
544 | float: none;
545 | width: 100%;
546 | height: 2px;
547 | line-height: 2px;
548 | font-size: 0;
549 | margin: 1.4em 0;
550 | border: none 0;
551 | background: #ddd;
552 | background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0.5, rgb(221,221,221)),color-stop(0.5, rgb(255,255,255)));
553 | background-image: -webkit-linear-gradient(center top,rgb(221,221,221) 50%,rgb(255,255,255) 50%);
554 | background-image: -o-linear-gradient(center top,rgb(221,221,221) 50%,rgb(255,255,255) 50%);
555 | background-image: -moz-linear-gradient(center top,rgb(221,221,221) 50%,rgb(255,255,255) 50%);
556 | }
--------------------------------------------------------------------------------