From e3efe2a64435f0aaf35a8752b60f5966c6cbb9dc Mon Sep 17 00:00:00 2001 From: troyeguo <13820674+troyeguo@users.noreply.github.com> Date: Sat, 30 Oct 2021 14:24:02 +0800 Subject: [PATCH] fix bug Former-commit-id: 6fe88fa3171a5a640d27a9e56c4c5e0352dd1915 --- README.md | 6 -- README_cn.md | 6 -- main.js | 2 +- public/lib/kookit/kookit.umd.js | 2 +- src/assets/locales/cn/translation.json | 8 +- src/assets/locales/en/translation.json | 6 +- src/assets/locales/ru/translation.json | 2 +- .../backgroundWidget/background.css | 2 +- src/components/backgroundWidget/component.tsx | 5 +- .../dialogs/settingDialog/component.tsx | 4 +- .../readerSettings/dropdownList/component.tsx | 6 +- .../readerSettings/dropdownList/interface.tsx | 2 +- .../settingSwitch/component.tsx | 15 +-- .../settingSwitch/interface.tsx | 5 +- .../readerSettings/sliderList/component.tsx | 2 +- .../readerSettings/sliderList/interface.tsx | 2 +- .../readerSettings/themeList/component.tsx | 8 +- .../readerSettings/themeList/interface.tsx | 2 +- src/constants/settingList.tsx | 26 ----- src/containers/epubReader/index.css | 4 +- src/containers/htmlViewer/component.tsx | 96 ++++++++++++------- src/containers/htmlViewer/index.css | 9 ++ src/containers/htmlViewer/interface.tsx | 2 + .../panels/settingPanel/component.tsx | 35 +++---- src/pages/htmlReader/component.tsx | 20 ++++ src/pages/htmlReader/index.tsx | 1 + src/pages/htmlReader/interface.tsx | 2 + src/utils/readUtils/styleUtil.tsx | 18 ++-- 28 files changed, 155 insertions(+), 143 deletions(-) create mode 100644 src/containers/htmlViewer/index.css diff --git a/README.md b/README.md index 25678d56..dfa49596 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,6 @@ - Stable Version (Recommended): [Download](https://koodo.960960.xyz/en/download) - Developer Version: [Download](https://github.com/troyeguo/koodo-reader/releases/latest) ( With new feature and bug fix, but may induce some unknown bugs) - Web Version:[Preview](https://koodo-reader.vercel.app/) -- Install with Chocolatey: - -```shell -choco install koodo-reader -``` - - Install with Homebrew: ```shell diff --git a/README_cn.md b/README_cn.md index 10e2a673..6e64dd81 100644 --- a/README_cn.md +++ b/README_cn.md @@ -59,12 +59,6 @@ - 稳定版 (推荐下载):[官网](https://koodo.960960.xyz/zh/download)(感谢 [GitHub Proxy](https://ghproxy.com/) 提供下载加速服务) - 开发版:[Github Release](https://github.com/troyeguo/koodo-reader/releases/latest) (包含新功能和 bug 修复,但也可能引入更多未知 bug) - 网页版:[前往](https://koodo-reader.vercel.app/) -- 使用 Chocolatey 安装: - -```shell -choco install koodo-reader -``` - - 使用 Homebrew 安装: ```shell diff --git a/main.js b/main.js index 14c8bd0b..7fcd0392 100644 --- a/main.js +++ b/main.js @@ -17,7 +17,7 @@ let mainWin; let readerWindow; const singleInstance = app.requestSingleInstanceLock(); var filePath = null; -if (process.platform == "win32" && process.argv.length >= 2) { +if (process.platform != "darwin" && process.argv.length >= 2) { filePath = process.argv[1]; } let options = { diff --git a/public/lib/kookit/kookit.umd.js b/public/lib/kookit/kookit.umd.js index cfed8e69..5e72a606 100644 --- a/public/lib/kookit/kookit.umd.js +++ b/public/lib/kookit/kookit.umd.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Kookit={})}(this,function(t){"use strict";function n(t,u,s,a){return new(s=s||Promise)(function(n,e){function r(t){try{o(a.next(t))}catch(t){e(t)}}function i(t){try{o(a.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(r,i)}o((a=a.apply(t,u||[])).next())})}function o(n,r){var i,o,u,s={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]},t={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,o&&(u=2&e[0]?o.return:e[0]?o.throw||((u=o.return)&&u.call(o),0):o.next)&&!(u=u.call(o,e[1])).done)return u;switch(o=0,(e=u?[2&e[0],u.value]:e)[0]){case 0:case 1:u=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,o=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(u=0<(u=s.trys).length&&u[u.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!u||e[1]>u[0]&&e[1]":">",'"':""","'":"'","`":"`"},qt=Kt($t),Vt=Kt(Lt($t)),Xt=ot.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g},Jt=/(.)^/,Yt={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},Zt=/\\|'|\r|\n|\u2028|\u2029/g;function Gt(t){return"\\"+Yt[t]}var Qt=/^\s*(\w|\$)+\s*$/;var te=0;function ee(t,e,n,r,i){if(!(r instanceof e))return t.apply(n,i);n=Ot(t.prototype),i=t.apply(n,i);return T(i)?i:n}var ne=_(function(i,o){function u(){for(var t=0,e=o.length,n=Array(e),r=0;r=t.scrollTop&&i<=t.scrollTop+t.offsetHeight),r},un=function(t,e){var n,r=document.getElementsByTagName("iframe")[0];"continuous"===e?(n=r.contentWindow.document.body,e=r.contentWindow.document.documentElement,r.height=2*Math.max(n.scrollHeight,n.offsetHeight,e.clientHeight,e.scrollHeight,e.offsetHeight),setTimeout(function(){var t=document.getElementsByTagName("iframe")[0],e=t.contentWindow.document.body,n=e.lastElementChild,r=e.lastChild,i=e.querySelectorAll("a"),o=e.querySelectorAll("p"),u=e.querySelectorAll("img"),e=i[i.length-1],i=o[o.length-1],o=o[u.length-1],u=i||e||o;Fe.isElement(e)&&Fe.isElement(i)&&(u=e.clientHeight+e.offsetTop>i.clientHeight+i.offsetTop?e:i),Fe.isElement(o)&&o.clientHeight+o.offsetTop>u.clientHeight+u.offsetTop&&(u=o);i=0;(n||u||r)&&(3!==r.nodeType||n||u)&&(3===r.nodeType&&document.createRange&&((o=document.createRange()).selectNodeContents(r),!o.getBoundingClientRect||(o=o.getBoundingClientRect())&&(i=o.bottom-o.top)),t.height=Math.max(Fe.isElement(n)?n.clientHeight+n.offsetTop:0,Fe.isElement(r)?r.clientHeight+r.offsetTop:0,Fe.isElement(u)?u.clientHeight+u.offsetTop:0)+600+(3===r.nodeType?i:0))},500)):r.height=t.offsetHeight},sn=function(t,e){var n=document.getElementsByTagName("iframe")[0];if(n){n=n.contentDocument;if(n)for(var r,i,o="double"===e?2:1,u=0,s=n.getElementsByTagName("img");ut.offsetHeight/t.offsetWidth?i=(r=t.offsetHeight)*a.width/a.height:r=(i=(t.offsetWidth-88)/o)*a.height/a.width),a.setAttribute("style","max-width: "+i+"px;max-height:"+r+"px")}}},an=function(t,e,n,r){void 0===t&&(t=""),window.frames[0].document.body.innerHTML="",window.frames[0].document.body.innerHTML=e[-1===Fe.findIndex(e,{title:t})?0:Fe.findIndex(e,{title:t})].text,Je.setKookitConfig("chapterTitle",t),un(n,r),sn(n,r),cn(n,r)},cn=function(t,e,n,r){void 0===r&&(r="0");var i,o,u=(n=void 0===n?"":n)||Je.getKookitConfig("text")||"";u?(n=(o=(i=Array.from(window.frames[0].document.body.getElementsByTagName("*"))).filter(function(t){return t.innerText===u}))[0],1")?this.bookStr.split(""):this.bookStr.split("
"),e=[],n=[],r="",i=0;i "),e=0;e=this.capacity)&&(this.buffer[this.size]=t,this.size+=1,!0)},xn.prototype.full=function(){return this.size===this.capacity},xn.prototype.get=function(t){return this.buffer[t]},xn);function xn(t){this.buffer=new Uint8Array(t),this.capacity=t,this.size=0}var wn=(Ln.prototype.parse=function(){},Ln.prototype.getUint8=function(){var t=this.view.getUint8(this.offset);return this.offset+=1,t},Ln.prototype.getUint16=function(){var t=this.view.getUint16(this.offset);return this.offset+=2,t},Ln.prototype.getUint32=function(){var t=this.view.getUint32(this.offset);return this.offset+=4,t},Ln.prototype.getStr=function(t){var e=gn(this.buffer.slice(this.offset,this.offset+t));return this.offset+=t,e},Ln.prototype.skip=function(t){this.offset+=t},Ln.prototype.setoffset=function(t){this.offset=t},Ln.prototype.get_record_extrasize=function(t,e){for(var n,r,i,o=t.length-1,u=0,s=15;0>3&2047,a=3+(7&u),c=r.size(),f=0;fpagebreak"),e=[],n=0;n"+o+""):e+="

"+o+"

")}return e}(n),this.bookStr=e,this.element=i,n=new Dn(this.bookStr),this.chapterList=n.getChapter(),this.chapterDocList=n.getChapterDoc(),e=Je.getKookitConfig("chapterTitle")||this.chapterDocList[0].title,n=-1===Fe.findIndex(this.chapterDocList,{title:e})?0:Fe.findIndex(this.chapterDocList,{title:e}),Ze(i),window.frames[0].document.body.innerHTML=this.chapterDocList[n].text,Je.setKookitConfig("chapterTitle",e),en(i,this.mode),un(i,this.mode),cn(i,this.mode),Ge(i,this.chapterList,this.chapterDocList,this.mode),r(),[2]})})})},An.prototype.getChapter=function(){return this.chapterList},An.prototype.goToChapter=function(t){an(t,this.chapterDocList,this.element,this.mode)},An.prototype.goToPosition=function(t,e,n){an(e,this.chapterDocList,this.element,this.mode),cn(this.element,this.mode,t,n)},$t=An;function An(t,e,n){void 0===n&&(n="utf-8"),this.txtBuffer=t,this.encoding=n,this.mode=e,this.chapterList=[],this.chapterDocList=[],this.bookStr="",this.element=""}t.Azw3Render=F,t.MobiRender=mt,t.StrRender=dt,t.TxtRender=$t,Object.defineProperty(t,"__esModule",{value:!0})}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Kookit={})}(this,function(t){"use strict";function o(t,s,u,a){return new(u=u||Promise)(function(n,e){function r(t){try{o(a.next(t))}catch(t){e(t)}}function i(t){try{o(a.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(r,i)}o((a=a.apply(t,s||[])).next())})}function s(n,r){var i,o,s,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},t={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,(e=s?[2&e[0],s.value]:e)[0]){case 0:case 1:s=e;break;case 4:return u.label++,{value:e[1],done:!1};case 5:u.label++,o=e[1],e=[0];continue;case 7:e=u.ops.pop(),u.trys.pop();continue;default:if(!(s=0<(s=u.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){u=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]":">",'"':""","'":"'","`":"`"},qt=Rt($t),Vt=Rt(Lt($t)),Xt=ot.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g},Jt=/(.)^/,Yt={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},Zt=/\\|'|\r|\n|\u2028|\u2029/g;function Gt(t){return"\\"+Yt[t]}var Qt=/^\s*(\w|\$)+\s*$/;var te=0;function ee(t,e,n,r,i){if(!(r instanceof e))return t.apply(n,i);n=At(t.prototype),i=t.apply(n,i);return T(i)?i:n}var ne=D(function(i,o){function s(){for(var t=0,e=o.length,n=Array(e),r=0;ri.clientHeight+i.offsetTop?e:i),Pe.isElement(o)&&o.clientHeight+o.offsetTop>s.clientHeight+s.offsetTop&&(s=o);i=0;(n||s||r)&&(3!==r.nodeType||n||s)&&(3===r.nodeType&&document.createRange&&((o=document.createRange()).selectNodeContents(r),!o.getBoundingClientRect||(o=o.getBoundingClientRect())&&(i=o.bottom-o.top)),t.height=Math.max(Pe.isElement(n)?n.clientHeight+n.offsetTop:0,Pe.isElement(r)?r.clientHeight+r.offsetTop:0,Pe.isElement(s)?s.clientHeight+s.offsetTop:0)+600+(3===r.nodeType?i:0))},500)):r.height=t.offsetHeight}function Ge(t){var e=document.createElement("iframe");e.style.width=t.offsetWidth+"px",e.style.border="0",e.style.margin="0",e.style.padding="0",e.style.fontSize="100%",e.style.font="inherit",e.style.verticalAlign="baseline",t.appendChild(e)}function Qe(e,n,r,i){var t=document.getElementsByTagName("iframe")[0];!t||(t=t.contentDocument)&&(-1t.offsetHeight/((t.offsetWidth-88)/o)?i=(r=t.offsetHeight)*a.width/a.height:r=(i=(t.offsetWidth-88)/o)*a.height/a.width:(i=(t.offsetWidth-88)/o,r=t.offsetHeight),a.setAttribute("style","max-width: "+i+"px;max-height:"+r+"px")}}}function rn(t,e,n,r){void 0===r&&(r="0");var i,o,s=(n=void 0===n?"":n)||Je.getKookitConfig("text")||"";s?(n=(o=(i=Array.from(window.frames[0].document.body.getElementsByTagName("*"))).filter(function(t){return t.innerText===s}))[0],1=t.scrollTop&&i<=t.scrollTop+t.offsetHeight),r},cn=function(t,e,n,r){void 0===t&&(t=""),window.frames[0].document.body.innerHTML="",window.frames[0].document.body.innerHTML=e[-1===Pe.findIndex(e,{title:t})?0:Pe.findIndex(e,{title:t})].text,Je.setKookitConfig("chapterTitle",t),Ze(n,r),nn(n,r),rn(n,r)},hn=function(t,e,n,r){var i=Je.getKookitConfig("chapterTitle"),i=Pe.findIndex(e,{label:i});0!==i&&-1!==i&&(Je.setKookitConfig("chapterTitle",e[i-1].label),cn(e[i-1].label,n,t,r))},fn=(ln.prototype.getChapterDoc=function(){for(var t=-1")?this.bookStr.split(""):this.bookStr.split("
"),e=[],n=[],r="",i=0;i "),e=0;e=this.capacity)&&(this.buffer[this.size]=t,this.size+=1,!0)},wn.prototype.full=function(){return this.size===this.capacity},wn.prototype.get=function(t){return this.buffer[t]},wn);function wn(t){this.buffer=new Uint8Array(t),this.capacity=t,this.size=0}var Ln=(Dn.prototype.parse=function(){},Dn.prototype.getUint8=function(){var t=this.view.getUint8(this.offset);return this.offset+=1,t},Dn.prototype.getUint16=function(){var t=this.view.getUint16(this.offset);return this.offset+=2,t},Dn.prototype.getUint32=function(){var t=this.view.getUint32(this.offset);return this.offset+=4,t},Dn.prototype.getStr=function(t){var e=mn(this.buffer.slice(this.offset,this.offset+t));return this.offset+=t,e},Dn.prototype.skip=function(t){this.offset+=t},Dn.prototype.setoffset=function(t){this.offset=t},Dn.prototype.get_record_extrasize=function(t,e){for(var n,r,i,o=t.length-1,s=0,u=15;0>3&2047,a=3+(7&s),c=r.size(),h=0;hpagebreak"),e=[],n=0;n"+o+""):e+="

"+o+"

")}return e}(e),this.bookStr=e,this.element=r,e=new kn(this.bookStr),this.chapterList=e.getChapter(),this.chapterDocList=e.getChapterDoc(),e=Je.getKookitConfig("chapterTitle")||this.chapterDocList[0].title,e=-1===Pe.findIndex(this.chapterDocList,{title:e})?0:Pe.findIndex(this.chapterDocList,{title:e}),Ge(r),window.frames[0].document.body.innerHTML=this.chapterDocList[e].text,Je.setKookitConfig("chapterTitle",this.chapterDocList[e].title),on(r,this.mode),Ze(r,this.mode),rn(r,this.mode),Qe(r,this.chapterList,this.chapterDocList,this.mode),n(),[2]})})})},An.prototype.getChapter=function(){return this.chapterList},An.prototype.goToChapter=function(t){cn(t,this.chapterDocList,this.element,this.mode)},An.prototype.goToPosition=function(t,e,n){cn(e,this.chapterDocList,this.element,this.mode),rn(this.element,this.mode,t,n)},An.prototype.prevPage=function(){0===window.frames[0].document.body.scrollLeft?hn(this.element,this.chapterList,this.chapterDocList,this.mode):sn(this.element,this.chapterList,this.chapterDocList,this.mode,1)},An.prototype.nextPage=function(){Math.abs(window.frames[0].document.body.scrollWidth-window.frames[0].document.body.scrollLeft-window.frames[0].document.body.clientWidth)<10?tn(this.element,this.chapterList,this.chapterDocList,this.mode):sn(this.element,this.chapterList,this.chapterDocList,this.mode,-1)},An.prototype.getPosition=function(){return{text:Je.getKookitConfig("text"),chapterTitle:Je.getKookitConfig("chapterTitle"),count:Je.getKookitConfig("count")}},An.prototype.setStyle=function(t){window.frames[0].document.body.setAttribute("style",t+window.frames[0].document.body.getAttribute("style"))},$t=An;function An(t,e,n){void 0===n&&(n="utf-8"),this.txtBuffer=t,this.encoding=n,this.mode=e,this.chapterList=[],this.chapterDocList=[],this.bookStr="",this.element=""}t.Azw3Render=P,t.MobiRender=mt,t.StrRender=dt,t.TxtRender=$t,Object.defineProperty(t,"__esModule",{value:!0})}); diff --git a/src/assets/locales/cn/translation.json b/src/assets/locales/cn/translation.json index ea173c8e..0375e242 100644 --- a/src/assets/locales/cn/translation.json +++ b/src/assets/locales/cn/translation.json @@ -187,8 +187,8 @@ "Auto open last-read book": "自动打开上次阅读的图书", "Open books in the main window": "直接在主窗口打开图书", "Book won't be opened in a seperate window but directly opened in the main window": "图书不会在一个单独的窗口打开,而是直接在主窗口打开", - "Please turn off open books in main window": "请关闭直接在主窗口打开图书", - "Please turn off merge with word": "请关闭摸鱼模式", + "Please turn off open books in the main window first": "请关闭直接在主窗口打开图书", + "Please turn off merge with word first": "请关闭摸鱼模式", "Project link": "开源地址", "View Mode": "视图模式", "Book not exsits": "图书文件不存在", @@ -246,7 +246,7 @@ "Line Height": "行间距", "Tips": "提示", "How sync works": "同步是如何实现的?", - "You need to manually change the storage location to the same sync folder on different computers. When you click the sync button, Koodo Reader will automatically upload or download the data from this folder according the timestamp.": "同步功能需要配合第三方同步盘实现,在不同电脑上把数据存储位置修改为同一个网盘文件夹。当在其中一台电脑上点击同步后,Koodo中的数据就会更新到这个文件夹中,另外一台电脑中检测到数据变化,同步的按钮就会变蓝,提示有数据可以更新,点击同步按钮后,就会把同步文件夹中的数据更新到Koodo中,从而实现同步。前往设置->修改数据存储位置处修改", + "You need to manually change the storage location to the same sync folder on different computers. When you click the sync button, Koodo Reader will automatically upload or download the data from this folder according the timestamp.": "同步功能需要配合第三方同步盘实现,在不同电脑上把数据存储位置修改为同一个网盘文件夹。当在其中一台电脑上点击同步后,Koodo中的数据就会更新到这个文件夹中。经过网盘同步后,在另一台电脑上打开Koodo,点击同步按钮,数据就会同步到Koodo中。具体操作方法请查看帮助文档。", "Please choose an empty folder": "请选择空文件夹", "Data change detected, whether to update?": "检测到数据变化,是否更新", "Empty Library": "图书库为空", @@ -296,7 +296,7 @@ "Download Desktop Version": "下载客户端", "Download": "前往下载", "Sync": "同步", - "Help": "需要帮助", + "Help": "帮助文档", "Feedback": "反馈建议", "Text Align": "文字对齐", "left": "左对齐", diff --git a/src/assets/locales/en/translation.json b/src/assets/locales/en/translation.json index 31ff5cd9..81244de8 100644 --- a/src/assets/locales/en/translation.json +++ b/src/assets/locales/en/translation.json @@ -203,7 +203,7 @@ "Collapse sidebar": "Collapse sidebar", "Show sidebar": "Show sidebar", "Sync": "Sync", - "Help": "Need Help", + "Help": "Document", "Feedback": "Feedback", "Github Repo": "Github Repo", "Speak the text": "Speak the text", @@ -232,8 +232,10 @@ "Tips": "Tips", "Brightness": "Brightness", "How sync works": "How sync works", - "You need to manually change the storage location to the same sync folder on different computers. When you click the sync button, Koodo Reader will automatically upload or download the data from this folder according the timestamp.": "You need to change the storage location to the same cloud drive folder on different computers. When you click the sync button, Koodo Reader will automatically upload or download your data from this folder and keep data synchronized across all you computers. Please change storage location in Setting->Change storage location", + "You need to manually change the storage location to the same sync folder on different computers. When you click the sync button, Koodo Reader will automatically upload or download the data from this folder according the timestamp.": "You need to change the storage location to the same cloud drive folder on different computers. When you click the sync button, Koodo Reader will automatically upload or download your data from this folder and keep data synchronized across all you computers. Visit our document for more instructions.", "Line Height": "Line Height", + "Please turn off open books in the main window first": "Please turn off open books in the main window first", + "Please turn off merge with word first": "Please turn off merge with word first", "Please choose an empty folder": "Please choose an empty folder", "Data change detected, whether to update?": "Data change detected, whether to update?", "Empty Library": "Empty Library", diff --git a/src/assets/locales/ru/translation.json b/src/assets/locales/ru/translation.json index 9081d31e..456dcad8 100644 --- a/src/assets/locales/ru/translation.json +++ b/src/assets/locales/ru/translation.json @@ -235,7 +235,7 @@ "View Mode": "View Mode", "Show sidebar": "Show sidebar", "Sync": "Sync", - "Help": "Need Help", + "Help": "Document", "Feedback": "Feedback", "Github Repo": "Github Repo", "left": "Left", diff --git a/src/components/backgroundWidget/background.css b/src/components/backgroundWidget/background.css index 50bb42d4..3a23a27c 100644 --- a/src/components/backgroundWidget/background.css +++ b/src/components/backgroundWidget/background.css @@ -41,7 +41,7 @@ border: 2px solid rgba(191, 191, 191, 1); border-left: none; box-sizing: border-box; - z-index: 15; + z-index: 10; } .spine-shadow-left { diff --git a/src/components/backgroundWidget/component.tsx b/src/components/backgroundWidget/component.tsx index 1712c4d1..bb6aab87 100644 --- a/src/components/backgroundWidget/component.tsx +++ b/src/components/backgroundWidget/component.tsx @@ -9,9 +9,8 @@ class Background extends React.Component { super(props); this.state = { isSingle: - (StorageUtil.getReaderConfig("readerMode") && - StorageUtil.getReaderConfig("readerMode") !== "double") || - this.props.currentBook.description === "readonly", + StorageUtil.getReaderConfig("readerMode") && + StorageUtil.getReaderConfig("readerMode") !== "double", scale: StorageUtil.getReaderConfig("scale") || 1, }; this.isFirst = true; diff --git a/src/components/dialogs/settingDialog/component.tsx b/src/components/dialogs/settingDialog/component.tsx index 7d2a121e..dbbe41c1 100644 --- a/src/components/dialogs/settingDialog/component.tsx +++ b/src/components/dialogs/settingDialog/component.tsx @@ -179,14 +179,14 @@ class SettingDialog extends React.Component< }; handleMergeWord = () => { if (this.state.isOpenInMain && !this.state.isMergeWord) { - toast("Please turn off open books in the main window"); + toast(this.props.t("Please turn off open books in the main window")); return; } this.handleSetting("isMergeWord"); }; handleOpenInMain = () => { if (this.state.isMergeWord && !this.state.isOpenInMain) { - toast("Please turn off merge with word"); + toast(this.props.t("Please turn off merge with word first")); return; } this.handleSetting("isOpenInMain"); diff --git a/src/components/readerSettings/dropdownList/component.tsx b/src/components/readerSettings/dropdownList/component.tsx index 0f5a09b0..9a01dd14 100644 --- a/src/components/readerSettings/dropdownList/component.tsx +++ b/src/components/readerSettings/dropdownList/component.tsx @@ -75,9 +75,7 @@ class DropdownList extends React.Component< this.state.currentTextAlignIndex ].setAttribute("selected", "selected"); } - handleRest = () => { - this.props.renderFunc("html-render"); - }; + //切换不同的样式 handleView(event: any, option: string) { let arr = event.target.value.split(","); @@ -105,7 +103,7 @@ class DropdownList extends React.Component< default: break; } - this.handleRest(); + this.props.renderFunc(); } render() { const renderParagraphCharacter = () => { diff --git a/src/components/readerSettings/dropdownList/interface.tsx b/src/components/readerSettings/dropdownList/interface.tsx index 3778924c..5a8c0c3e 100644 --- a/src/components/readerSettings/dropdownList/interface.tsx +++ b/src/components/readerSettings/dropdownList/interface.tsx @@ -1,7 +1,7 @@ export interface DropdownListProps { currentEpub: any; t: (title: string) => string; - renderFunc: (id: string) => void; + renderFunc: () => void; } export interface DropdownListState { currentFontFamilyIndex: number; diff --git a/src/components/readerSettings/settingSwitch/component.tsx b/src/components/readerSettings/settingSwitch/component.tsx index bd43683f..77f3584f 100644 --- a/src/components/readerSettings/settingSwitch/component.tsx +++ b/src/components/readerSettings/settingSwitch/component.tsx @@ -3,10 +3,7 @@ import { SettingSwitchProps, SettingSwitchState } from "./interface"; import { Trans } from "react-i18next"; import TextToSpeech from "../../textToSpeech"; import StorageUtil from "../../../utils/storageUtil"; -import { - readerSettingList, - htmlSettingList, -} from "../../../constants/settingList"; +import { readerSettingList } from "../../../constants/settingList"; import { isElectron } from "react-device-detect"; import toast from "react-hot-toast"; class SettingSwitch extends React.Component< @@ -33,9 +30,6 @@ class SettingSwitch extends React.Component< }; } - handleRest = () => { - this.props.renderFunc("html-render"); - }; _handleRest = () => { if (isElectron) { toast(this.props.t("Take effect at next startup")); @@ -51,7 +45,7 @@ class SettingSwitch extends React.Component< this.state[stateName] ? "yes" : "no" ); setTimeout(() => { - this.handleRest(); + this.props.renderFunc(); }, 500); }); }; @@ -72,10 +66,7 @@ class SettingSwitch extends React.Component< return ( <> {Object.keys(this.props.currentEpub).length !== 0 && } - {(this.props.currentBook.description !== "readonly" - ? readerSettingList - : htmlSettingList - ).map((item) => ( + {readerSettingList.map((item) => (
{item.title} diff --git a/src/components/readerSettings/settingSwitch/interface.tsx b/src/components/readerSettings/settingSwitch/interface.tsx index e74747d8..2c903884 100644 --- a/src/components/readerSettings/settingSwitch/interface.tsx +++ b/src/components/readerSettings/settingSwitch/interface.tsx @@ -1,11 +1,12 @@ import BookModel from "../../../model/Book"; +import HtmlBook from "../../../model/HtmlBook"; export interface SettingSwitchProps { currentEpub: any; currentBook: BookModel; locations: any; isReading: boolean; - htmlBook; - renderFunc: (id: string) => void; + htmlBook: HtmlBook; + renderFunc: () => void; t: (title: string) => string; } export interface SettingSwitchState { diff --git a/src/components/readerSettings/sliderList/component.tsx b/src/components/readerSettings/sliderList/component.tsx index c7bf847f..f4b6abb7 100644 --- a/src/components/readerSettings/sliderList/component.tsx +++ b/src/components/readerSettings/sliderList/component.tsx @@ -32,7 +32,7 @@ class SliderList extends React.Component { } return; } - this.props.renderFunc("html-render"); + this.props.renderFunc(); }; onValueChange = (event: any) => { if (this.props.mode === "fontSize") { diff --git a/src/components/readerSettings/sliderList/interface.tsx b/src/components/readerSettings/sliderList/interface.tsx index 238fa684..725959b2 100644 --- a/src/components/readerSettings/sliderList/interface.tsx +++ b/src/components/readerSettings/sliderList/interface.tsx @@ -7,7 +7,7 @@ export interface SliderListProps { title: string; minLabel: string; maxLabel: string; - renderFunc: (id: string) => void; + renderFunc: () => void; t: (title: string) => string; } export interface SliderListState { diff --git a/src/components/readerSettings/themeList/component.tsx b/src/components/readerSettings/themeList/component.tsx index ed63507b..47976610 100644 --- a/src/components/readerSettings/themeList/component.tsx +++ b/src/components/readerSettings/themeList/component.tsx @@ -68,14 +68,12 @@ class ThemeList extends React.Component { }); } if (!this.props.currentEpub.rendition) { - this.handleRest(); + this.props.renderFunc(); } else { StyleUtil.addDefaultCss(); } }; - handleRest = () => { - this.props.renderFunc("html-render"); - }; + handleChooseBgColor = (color) => { StorageUtil.setReaderConfig("backgroundColor", color.color); StyleUtil.addDefaultCss(); @@ -128,7 +126,7 @@ class ThemeList extends React.Component { } !important`, }, }); - this.handleRest(); + this.props.renderFunc(); }; render() { const renderBackgroundColorList = () => { diff --git a/src/components/readerSettings/themeList/interface.tsx b/src/components/readerSettings/themeList/interface.tsx index 8ad6eae1..aa4539f8 100644 --- a/src/components/readerSettings/themeList/interface.tsx +++ b/src/components/readerSettings/themeList/interface.tsx @@ -1,7 +1,7 @@ export interface ThemeListProps { currentEpub: any; t: (title: string) => string; - renderFunc: (id: string) => void; + renderFunc: () => void; } export interface ThemeListState { diff --git a/src/constants/settingList.tsx b/src/constants/settingList.tsx index 9627a8e2..0019bdcf 100644 --- a/src/constants/settingList.tsx +++ b/src/constants/settingList.tsx @@ -143,29 +143,3 @@ export const readerSettingList = [ propName: "isHideMenuButton", }, ]; -export const htmlSettingList = [ - { - title: "Text Indent", - propName: "isIndent", - }, - { - title: "Bold Font", - propName: "isBold", - }, - { - title: "Italic", - propName: "isItalic", - }, - { - title: "Text Underline", - propName: "isUnderline", - }, - { - title: "Text Shadow", - propName: "isShadow", - }, - { - title: "Dont't use mimical background", - propName: "isHideBackground", - }, -]; diff --git a/src/containers/epubReader/index.css b/src/containers/epubReader/index.css index 2bdc07f0..5fe540df 100644 --- a/src/containers/epubReader/index.css +++ b/src/containers/epubReader/index.css @@ -176,7 +176,7 @@ bottom: 25px; /* width: calc(100% - 100px); height: calc(100% - 100px); */ - z-index: 0; + z-index: 5; user-select: text; } .previous-chapter-single-container { @@ -208,7 +208,7 @@ display: flex; justify-content: center; align-items: center; - z-index: 5; + z-index: 10; } .next-chapter-single-container:hover { opacity: 0.7; diff --git a/src/containers/htmlViewer/component.tsx b/src/containers/htmlViewer/component.tsx index b2c1780f..a3e5aeef 100644 --- a/src/containers/htmlViewer/component.tsx +++ b/src/containers/htmlViewer/component.tsx @@ -13,6 +13,8 @@ import RecordLocation from "../../utils/readUtils/recordLocation"; import { mimetype } from "../../constants/mimetype"; import BackgroundWidget from "../../components/backgroundWidget"; import toast from "react-hot-toast"; +import StyleUtil from "../../utils/readUtils/styleUtil"; +import "./index.css"; declare var window: any; @@ -30,11 +32,18 @@ class Viewer extends React.Component { chapterTitle: RecordLocation.getScrollHeight(this.props.currentBook.key) .chapterTitle || "", + readerMode: StorageUtil.getReaderConfig("readerMode") || "double", + margin: parseInt(StorageUtil.getReaderConfig("margin")) || 30, }; this.lock = false; } componentDidMount() { + this.handleRenderBook(); + + this.props.handleRenderFunc(this.handleRenderBook); + } + handleRenderBook = () => { let { key, path, format, name } = this.props.currentBook; BookUtil.fetchBook(key, true, path).then((result) => { if (!result) { @@ -69,10 +78,10 @@ class Viewer extends React.Component { RecentBooks.setRecent(this.props.currentBook.key); document.title = name + " - Koodo Reader"; }); - - // this.props.handleRenderFunc(this.handleRenderHtml); - } + }; handleRest = (rendition: any) => { + StyleUtil.addDefaultCss(); + rendition.setStyle(StyleUtil.getCustomCss(true)); let bookLocation = RecordLocation.getScrollHeight( this.props.currentBook.key ); @@ -87,20 +96,22 @@ class Viewer extends React.Component { this.props.handleLeaveReader("top"); this.props.handleLeaveReader("bottom"); }); + let iframe = document.getElementsByTagName("iframe")[0]; if (!iframe) return; let doc = iframe.contentDocument; if (!doc) return; let isFirefox = navigator.userAgent.indexOf("Firefox") > -1; + let postion = rendition.getPosition(); if (isFirefox) { doc.addEventListener( "DOMMouseScroll", (event) => { RecordLocation.recordScrollHeight( this.props.htmlBook.key, - StorageUtil.getKookitConfig("text"), - StorageUtil.getKookitConfig("chapterTitle"), - StorageUtil.getKookitConfig("count") + postion.text, + postion.chapterTitle, + postion.count ); }, false @@ -127,16 +138,16 @@ class Viewer extends React.Component { }); }; handleMobi = async (result: ArrayBuffer) => { - let rendition = new MobiRender(result, "single"); + let rendition = new MobiRender(result, this.state.readerMode); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }; handleAzw3 = async (result: ArrayBuffer) => { - let rendition = new Azw3Render(result, "continuous"); + let rendition = new Azw3Render(result, this.state.readerMode); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }; @@ -164,11 +175,11 @@ class Viewer extends React.Component { } let rendition = new TxtRender( result, - "single", + this.state.readerMode, this.props.currentBook.charset || charset || "utf8" ); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }; @@ -177,9 +188,9 @@ class Viewer extends React.Component { var reader = new FileReader(); reader.onload = async (evt) => { let docStr = window.marked(evt.target?.result as any); - let rendition = new StrRender(docStr, "continuous"); + let rendition = new StrRender(docStr, this.state.readerMode); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }; @@ -196,9 +207,9 @@ class Viewer extends React.Component { ); rtfToHTML.fromString(text, async (err: any, html: any) => { - let rendition = new StrRender(html, "continuous"); + let rendition = new StrRender(html, this.state.readerMode); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }); @@ -207,9 +218,9 @@ class Viewer extends React.Component { window.mammoth .convertToHtml({ arrayBuffer: result }) .then(async (res: any) => { - let rendition = new StrRender(res.value, "continuous"); + let rendition = new StrRender(res.value, this.state.readerMode); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }); @@ -225,9 +236,9 @@ class Viewer extends React.Component { ); let bookObj = xmlBookToObj(Buffer.from(result)); bookObj += xmlBookTagFilter(fb2Str); - let rendition = new StrRender(bookObj, "continuous"); + let rendition = new StrRender(bookObj, this.state.readerMode); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }; @@ -238,28 +249,49 @@ class Viewer extends React.Component { var reader = new FileReader(); reader.onload = async (evt) => { const html = evt.target?.result as any; - let rendition = new StrRender(html, "continuous"); + let rendition = new StrRender(html, this.state.readerMode); await rendition.renderTo( - document.getElementsByClassName("ebook-viewer")[0] + document.getElementsByClassName("html-viewer-page")[0] ); this.handleRest(rendition); }; reader.readAsText(blob, "UTF-8"); }; render() { - console.log(parseFloat(this.state.scale)); return ( <>
{StorageUtil.getReaderConfig("isHideBackground") === "yes" ? null : this .props.currentBook.key ? ( diff --git a/src/containers/htmlViewer/index.css b/src/containers/htmlViewer/index.css new file mode 100644 index 00000000..e7755cf0 --- /dev/null +++ b/src/containers/htmlViewer/index.css @@ -0,0 +1,9 @@ +.html-viewer-page { + position: absolute; + left: 20px; + right: 20px; + top: 40px; + bottom: 40px; + z-index: 5; + user-select: text; +} diff --git a/src/containers/htmlViewer/interface.tsx b/src/containers/htmlViewer/interface.tsx index f6f6d2b0..53c523f2 100644 --- a/src/containers/htmlViewer/interface.tsx +++ b/src/containers/htmlViewer/interface.tsx @@ -21,4 +21,6 @@ export interface ViewerState { scale: string; isFirst: boolean; chapterTitle: string; + margin: number; + readerMode: string; } diff --git a/src/containers/panels/settingPanel/component.tsx b/src/containers/panels/settingPanel/component.tsx index c73a423d..33dd0f56 100644 --- a/src/containers/panels/settingPanel/component.tsx +++ b/src/containers/panels/settingPanel/component.tsx @@ -56,7 +56,7 @@ class SettingPanel extends React.Component< Reading Option
- {Object.keys(this.props.currentEpub).length !== 0 && } + - {Object.keys(this.props.currentEpub).length !== 0 && ( + + {this.state.readerMode && this.state.readerMode === "double" && ( )} + - {Object.keys(this.props.currentEpub).length !== 0 && ( - - )} - {(this.state.readerMode && this.state.readerMode !== "double") || - this.props.currentBook.description === "readonly" ? ( + + + + {this.state.readerMode && this.state.readerMode !== "double" ? ( { }; return (
+ {StorageUtil.getReaderConfig("isHidePageButton") !== "yes" && ( + <> +
{ + this.props.htmlBook.rendition.prevPage(); + }} + > + +
+
{ + this.props.htmlBook.rendition.nextPage(); + }} + > + +
+ + )} {StorageUtil.getReaderConfig("isHideMenuButton") !== "yes" && (
{ currentEpub: state.book.currentEpub, currentBook: state.book.currentBook, percentage: state.progressPanel.percentage, + htmlBook: state.reader.htmlBook, }; }; const actionCreator = { diff --git a/src/pages/htmlReader/interface.tsx b/src/pages/htmlReader/interface.tsx index 8c2a232d..45159da6 100644 --- a/src/pages/htmlReader/interface.tsx +++ b/src/pages/htmlReader/interface.tsx @@ -1,9 +1,11 @@ import BookModel from "../../model/Book"; +import HtmlBookModel from "../../model/HtmlBook"; export interface ReaderProps { currentEpub: any; currentBook: BookModel; percentage: number; t: (title: string) => string; + htmlBook: HtmlBookModel; handleFetchNotes: () => void; handleFetchBooks: () => void; handleFetchBookmarks: () => void; diff --git a/src/utils/readUtils/styleUtil.tsx b/src/utils/readUtils/styleUtil.tsx index ce6a954c..f6f62aca 100644 --- a/src/utils/readUtils/styleUtil.tsx +++ b/src/utils/readUtils/styleUtil.tsx @@ -3,13 +3,10 @@ import StorageUtil from "../storageUtil"; class styleUtil { // 为 iframe 添加默认的样式 static addDefaultCss() { - let iframe = document.getElementsByTagName("iframe")[0]; - if (!iframe) return; - let doc = iframe.contentDocument; + let doc = window.frames[0].document; if (!doc) return; let css = this.getDefaultCss(); - let style = doc.getElementById("default-style"); - let background = document.querySelector(".background"); + let background = document.querySelector(".viewer"); if (!background) return; background.setAttribute( "style", @@ -22,14 +19,11 @@ class styleUtil { if (!doc.head) { return; } - if (!style) { - style = doc.createElement("style"); - style.id = "default-style"; - style.textContent = css; - doc.head.appendChild(style); - return; - } + + let style = doc.createElement("style"); + style.id = "default-style"; style.textContent = css; + doc.head.appendChild(style); } // 获取为文档默认应用的css样式 static getDefaultCss() {