Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
axipo committed Nov 5, 2019
1 parent 6da3552 commit 070fa41
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
Binary file modified node_google_translate.exe
Binary file not shown.
57 changes: 57 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# pdfTranslator

一个具有划词翻译功能的pdf阅读器,用着挺好用开源一下帮助众科研狗,欢迎star

阅读论文并且想用翻译的时候,经常面临的一个问题就是要在pdf阅读器和谷歌翻译之间切换,非常容易打乱思绪,有一个良好的工具可以实现更好的工作流。

常用的几种解决方案有本地监控剪切板变化,本地监控快捷键,浏览器油猴插件等等。

所有本地监控类型的都不推荐:对系统入侵太大,尤其是那些具有划词功能的词典,居然大部分是不断触发ctrl+c来实现的,经常导致我命令行程序强制退出。

浏览器插件要更优雅一些,比如[这个油猴插件](https://greasyfork.org/en/scripts/374339-google-translate-utils),对双屏用户极其友好,无系统入侵并且跨平台。

更好的方案是在pdf阅读器上进行扩展,实现划词翻译,这样视线不用移动多少,更舒服。比如 [这个项目](https://github.com/do-something-for-fun/thesis-helper)。本项目灵感正是来自于它, 感觉挺有用并且想要加一些特性进去,于是就重新造了这个轮子。

## 特点

- 划词后自动翻译,工作流更加简单,简单是最重要的,**keep it simple stupid**
- 支持google翻译,相对于百度必应和有道,仍然是更喜欢谷歌翻译的结果
- 跨平台支持(win/linux/mac),使用webui也就是直接用浏览器作为前台,更加干净整洁


## 效果图

![效果图](https://cdn.0x00.eu.org/d/iV0Vi3kHUe.gif)

## 技术栈

- express 实现后端
- google 翻译
- pdfjs 作为前端

## 使用方法

### windows

win端直接[下载](https://github.com/axipo/pdfTranslator/releases)使用即可

### Linux & Mac OS

git clone https://github.com/axipo/pdfTranslator.git
cd pdfTranslator
npm install
node index.js

## 打包方法

git clone https://github.com/axipo/pdfTranslator.git
cd pdfTranslator
npm install
npx pkg ./package.json

## To-Do

有时间把有道翻译和必应翻译也加上吧(咕咕咕
有时间把Linux和mac的打包版本也导出好(咕咕咕+1
↑估计要等空闲一点搞,最近真的忙...

12 changes: 9 additions & 3 deletions web/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ const getTransRes = function(queryWord) {
return promise;
}


var toolbarContainer = document.getElementById('toolbarContainer');
var transResEle = document.getElementById('transRes');
var transResEleContainer = document.getElementById('transResContainer');
var showRes = false;
function showPop(value){
if(value === ''){
if(value === '' && showRes === true){
transResEleContainer.remove();
transResEle.style.visibility = 'hidden';
}else{
showRes = false;
}else if(value !== '' && showRes === false){
transResEle.style.visibility = 'visible';
toolbarContainer.insertBefore(transResEleContainer, toolbarContainer.firstChild);
transResEle.innerHTML = value;
showRes = true;
}
}
function clickFun(event){
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@

<div class="toolbar">
<div id="toolbarContainer">
<div style="position: fixed; top:45px; left:0; width: 100%; z-index: 99999;">
<div id="transResContainer" style="position: fixed; top:45px; left:0; width: 100%; z-index: 99999;">
<div id="transRes" style="width: 30%; background-color:cyan; margin: 0 auto;
color: rgba(0,0,0,.75);
background-color: rgb(200,230,240);
Expand Down

0 comments on commit 070fa41

Please sign in to comment.