Skip to content

Commit

Permalink
修复翻译含有“%”文本时出错的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
axipo committed Nov 7, 2019
1 parent 12d3709 commit 048388c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ const { youdao, baidu, google } = require('translation.js')
const port = 3000;

app.use(express.static(path.resolve(__dirname)));
app.use(express.json());
// app.use(express.static(path.resolve(__dirname, 'build')));

app.get('/', (req, res) => res.redirect(301, '/web/viewer.html'));
app.get('/query', (req, res) => {
app.post('/query', (req, res) => {
google.translate({
text: req.query.word,
text: req.body.word,
to: 'zh-CN'
}).then(result => {
res.send(result.result.join(""));
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ win端直接[下载](https://github.com/axipo/pdfTranslator/releases),双击

如果默认浏览器是ie,那么可以在其他受支持的浏览器中输入[http://127.0.0.1:3000](http://127.0.0.1:3000/) 使用。

后续会加入翻译引擎的选择功能,敬请期待
后续会加入对ie的支持

2. 为什么我划词之后没有自动翻译?

Expand Down
68 changes: 64 additions & 4 deletions web/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ const getTransRes = function(queryWord) {
}
};
const client = new XMLHttpRequest();
client.open("GET", '/query?word=' + queryWord);
client.open("POST", '/query');
client.onreadystatechange = handler;
client.responseType = "text";
client.send();
client.setRequestHeader("Content-Type", "application/json");
client.send(JSON.stringify({
word: queryWord
}));
});
return promise;
}
Expand All @@ -42,10 +45,67 @@ function clickFun(event){
if(selectedText === ''){
showPop('');
}else{
console.log(selectedText);
getTransRes(selectedText).then(res =>{
showPop(res);
})
}
}
document.addEventListener('click', clickFun);
document.addEventListener('click', clickFun);



// 彩蛋

(function() {
'use strict';

function fire(){
'use strict'
var bg = document.getElementsByTagName('canvas');
var wd = document.getElementsByTagName('span');
var textLayer = document.getElementsByClassName('textLayer');
var timeSep = '300'; //ms
var timeDurition = 2;
bg = Array.prototype.slice.call(bg);
wd = Array.prototype.slice.call(wd);
for(let ind = 0; ind < textLayer.length; ind++){
var aNode = textLayer[ind];
aNode.style.opacity = 1;
}
for(let ind = 0; ind < wd.length; ind++){
var aNode = wd[ind];
aNode.style.color = 'black';
aNode.style.opacity = 1;
}
for(var ind = 0; ind < bg.length; ind++){
bg[ind].style.visibility = 'hidden';
}
for(let ind = 0; ind < wd.length; ind++){
let aNode = wd[ind];
setTimeout(() =>{
aNode.style.transition='transform ' + timeDurition + 's' + ',opacity ' + timeDurition + 's';
aNode.style.transform = 'rotate(180deg) scale(0, 0)';
aNode.style.opacity = '0';
}, timeSep * (ind + 1))
}
}


var timeSeq = ['X', 'X', 'X', 'X'];
var threeClick = function (event){
'use strict'
var MININTERVAL = 400;
var keypressed = String.fromCharCode(event.keyCode);
console.log(keypressed);
timeSeq.push(keypressed);
timeSeq.shift();
if(timeSeq.join('') === 'XBDL'){
fire()
console.log('别问我怎么恢复显示,刷新页面吧')
}
};

document.addEventListener('keydown',threeClick);
})();

console.log('哦豁,你找到一个彩蛋,以此按下xbdl(学不动了)触发自暴自弃行为, 从第一页开始')
1 change: 1 addition & 0 deletions web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
width: 33%;
max-height: 300px;
overflow-y: auto;
overflow-x: hidden;
padding: 1.5rem;
border-radius: 1.2rem;
left: 33%;
Expand Down

0 comments on commit 048388c

Please sign in to comment.