Reader.vue 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. <template>
  2. <div class="column no-wrap">
  3. <div v-show="toolBarActive" ref="header" class="header">
  4. <div ref="buttons" class="row justify-between no-wrap">
  5. <div>
  6. <button ref="loader" v-ripple class="tool-button" :class="buttonActiveClass('loader')" @click="buttonClick('loader')">
  7. <q-icon name="la la-arrow-left" size="32px" />
  8. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  9. {{ rstore.readerActions['loader'] }}
  10. </q-tooltip>
  11. </button>
  12. <button v-show="showToolButton['loadFile']" ref="loadFile" v-ripple class="tool-button" :class="buttonActiveClass('loadFile')" @click="buttonClick('loadFile')">
  13. <q-icon name="la la-caret-square-up" size="32px" />
  14. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  15. {{ rstore.readerActions['loadFile'] }}
  16. </q-tooltip>
  17. </button>
  18. <button v-show="showToolButton['help']" ref="help" v-ripple class="tool-button" :class="buttonActiveClass('help')" @click="buttonClick('help')">
  19. <q-icon name="la la-question" size="32px" />
  20. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  21. {{ rstore.readerActions['help'] }}
  22. </q-tooltip>
  23. </button>
  24. </div>
  25. <div>
  26. <button v-show="showToolButton['undoAction']" ref="undoAction" v-ripple class="tool-button" :class="buttonActiveClass('undoAction')" @click="buttonClick('undoAction')">
  27. <q-icon name="la la-angle-left" size="32px" />
  28. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  29. {{ rstore.readerActions['undoAction'] }}
  30. </q-tooltip>
  31. </button>
  32. <button v-show="showToolButton['redoAction']" ref="redoAction" v-ripple class="tool-button" :class="buttonActiveClass('redoAction')" @click="buttonClick('redoAction')">
  33. <q-icon name="la la-angle-right" size="32px" />
  34. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  35. {{ rstore.readerActions['redoAction'] }}
  36. </q-tooltip>
  37. </button>
  38. <div class="space"></div>
  39. <button v-show="showToolButton['fullScreen']" ref="fullScreen" v-ripple class="tool-button" :class="buttonActiveClass('fullScreen')" @click="buttonClick('fullScreen')">
  40. <q-icon :name="(fullScreenActive ? 'la la-compress-arrows-alt': 'la la-expand-arrows-alt')" size="32px" />
  41. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  42. {{ rstore.readerActions['fullScreen'] }}
  43. </q-tooltip>
  44. </button>
  45. <button v-show="showToolButton['scrolling']" ref="scrolling" v-ripple class="tool-button" :class="buttonActiveClass('scrolling')" @click="buttonClick('scrolling')">
  46. <q-icon name="la la-film" size="32px" />
  47. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  48. {{ rstore.readerActions['scrolling'] }}
  49. </q-tooltip>
  50. </button>
  51. <button v-show="showToolButton['setPosition']" ref="setPosition" v-ripple class="tool-button" :class="buttonActiveClass('setPosition')" @click="buttonClick('setPosition')">
  52. <q-icon name="la la-angle-double-right" size="32px" />
  53. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  54. {{ rstore.readerActions['setPosition'] }}
  55. </q-tooltip>
  56. </button>
  57. <button v-show="showToolButton['search']" ref="search" v-ripple class="tool-button" :class="buttonActiveClass('search')" @click="buttonClick('search')">
  58. <q-icon name="la la-search" size="32px" />
  59. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  60. {{ rstore.readerActions['search'] }}
  61. </q-tooltip>
  62. </button>
  63. <button v-show="showToolButton['copyText']" ref="copyText" v-ripple class="tool-button" :class="buttonActiveClass('copyText')" @click="buttonClick('copyText')">
  64. <q-icon name="la la-copy" size="32px" />
  65. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  66. {{ rstore.readerActions['copyText'] }}
  67. </q-tooltip>
  68. </button>
  69. <button v-show="showToolButton['convOptions']" ref="convOptions" v-ripple class="tool-button" :class="buttonActiveClass('convOptions')" @click="buttonClick('convOptions')">
  70. <q-icon name="la la-magic" size="32px" />
  71. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  72. {{ rstore.readerActions['convOptions'] }}
  73. </q-tooltip>
  74. </button>
  75. <button v-show="showToolButton['refresh']" ref="refresh" v-ripple class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')">
  76. <q-icon name="la la-sync" size="32px" :class="{clear: !showRefreshIcon}" />
  77. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  78. {{ rstore.readerActions['refresh'] }}
  79. </q-tooltip>
  80. </button>
  81. <div class="space"></div>
  82. <button v-show="showToolButton['contents']" ref="contents" v-ripple class="tool-button" :class="buttonActiveClass('contents')" @click="buttonClick('contents')">
  83. <q-icon name="la la-list" size="32px" />
  84. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  85. {{ rstore.readerActions['contents'] }}
  86. </q-tooltip>
  87. </button>
  88. <button v-show="mode == 'liberama.top' && showToolButton['libs']" ref="libs" v-ripple class="tool-button" :class="buttonActiveClass('libs')" @click="buttonClick('libs')">
  89. <q-icon name="la la-sitemap" size="32px" />
  90. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  91. {{ rstore.readerActions['libs'] }}
  92. </q-tooltip>
  93. </button>
  94. <button v-show="showToolButton['recentBooks']" ref="recentBooks" v-ripple class="tool-button" :class="buttonActiveClass('recentBooks')" @click="buttonClick('recentBooks')">
  95. <q-icon name="la la-book-open" size="32px" />
  96. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  97. {{ rstore.readerActions['recentBooks'] }}
  98. </q-tooltip>
  99. </button>
  100. </div>
  101. <div>
  102. <button v-show="showToolButton['offlineMode']" ref="offlineMode" v-ripple class="tool-button" :class="buttonActiveClass('offlineMode')" @click="buttonClick('offlineMode')">
  103. <q-icon name="la la-unlink" size="32px" />
  104. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  105. {{ rstore.readerActions['offlineMode'] }}
  106. </q-tooltip>
  107. </button>
  108. <button ref="settings" v-ripple class="tool-button" :class="buttonActiveClass('settings')" @click="buttonClick('settings')">
  109. <q-icon name="la la-cog" size="32px" />
  110. <q-tooltip :delay="1500" anchor="bottom left" content-style="font-size: 80%">
  111. {{ rstore.readerActions['settings'] }}
  112. </q-tooltip>
  113. </button>
  114. </div>
  115. </div>
  116. </div>
  117. <div class="main col row relative-position">
  118. <keep-alive>
  119. <component
  120. :is="activePage"
  121. ref="page"
  122. class="col"
  123. @load-book="loadBook"
  124. @load-file="loadFile"
  125. @book-pos-changed="bookPosChanged"
  126. @do-action="doAction"
  127. ></component>
  128. </keep-alive>
  129. <SetPositionPage v-if="setPositionActive" ref="setPositionPage" @set-position-toggle="setPositionToggle" @book-pos-changed="bookPosChanged"></SetPositionPage>
  130. <SearchPage
  131. v-show="searchActive"
  132. ref="searchPage"
  133. @do-action="doAction"
  134. @book-pos-changed="bookPosChanged"
  135. @start-text-search="startTextSearch"
  136. @stop-text-search="stopTextSearch"
  137. ></SearchPage>
  138. <CopyTextPage v-if="copyTextActive" ref="copyTextPage" @do-action="doAction"></CopyTextPage>
  139. <LibsPage v-show="hidden" ref="libsPage" @load-book="loadBook" @libs-close="libsClose" @do-action="doAction"></LibsPage>
  140. <RecentBooksPage v-show="recentBooksActive" ref="recentBooksPage" @load-book="loadBook" @recent-books-close="recentBooksClose"></RecentBooksPage>
  141. <SettingsPage v-show="settingsActive" ref="settingsPage" @do-action="doAction"></SettingsPage>
  142. <HelpPage v-if="helpActive" ref="helpPage" @do-action="doAction"></HelpPage>
  143. <ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
  144. <ContentsPage v-show="contentsActive" ref="contentsPage" :book-pos="bookPos" :is-visible="contentsActive" @do-action="doAction" @book-pos-changed="bookPosChanged"></ContentsPage>
  145. <ServerStorage v-show="hidden" ref="serverStorage"></ServerStorage>
  146. <ReaderDialogs ref="dialogs" @donate-toggle="donateToggle" @version-history-toggle="versionHistoryToggle"></ReaderDialogs>
  147. </div>
  148. </div>
  149. </template>
  150. <script>
  151. //-----------------------------------------------------------------------------
  152. import vueComponent from '../vueComponent.js';
  153. import _ from 'lodash';
  154. import {Buffer} from 'safe-buffer';
  155. import LoaderPage from './LoaderPage/LoaderPage.vue';
  156. import TextPage from './TextPage/TextPage.vue';
  157. import ProgressPage from './ProgressPage/ProgressPage.vue';
  158. import SetPositionPage from './SetPositionPage/SetPositionPage.vue';
  159. import SearchPage from './SearchPage/SearchPage.vue';
  160. import CopyTextPage from './CopyTextPage/CopyTextPage.vue';
  161. import LibsPage from './LibsPage/LibsPage.vue';
  162. import RecentBooksPage from './RecentBooksPage/RecentBooksPage.vue';
  163. import SettingsPage from './SettingsPage/SettingsPage.vue';
  164. import HelpPage from './HelpPage/HelpPage.vue';
  165. import ClickMapPage from './ClickMapPage/ClickMapPage.vue';
  166. import ContentsPage from './ContentsPage/ContentsPage.vue';
  167. import ServerStorage from './ServerStorage/ServerStorage.vue';
  168. import ReaderDialogs from './ReaderDialogs/ReaderDialogs.vue';
  169. import bookManager from './share/bookManager';
  170. import wallpaperStorage from './share/wallpaperStorage';
  171. import dynamicCss from '../../share/dynamicCss';
  172. import rstore from '../../store/modules/reader';
  173. import readerApi from '../../api/reader';
  174. import miscApi from '../../api/misc';
  175. import {versionHistory} from './versionHistory';
  176. import * as utils from '../../share/utils';
  177. const componentOptions = {
  178. components: {
  179. LoaderPage,
  180. TextPage,
  181. ProgressPage,
  182. SetPositionPage,
  183. SearchPage,
  184. CopyTextPage,
  185. LibsPage,
  186. RecentBooksPage,
  187. SettingsPage,
  188. HelpPage,
  189. ClickMapPage,
  190. ContentsPage,
  191. ServerStorage,
  192. ReaderDialogs,
  193. },
  194. watch: {
  195. bookPos: function(newValue) {
  196. if (newValue !== undefined && this.activePage == 'TextPage') {
  197. const textPage = this.$refs.page;
  198. if (textPage.bookPos != newValue) {
  199. textPage.bookPos = newValue;
  200. }
  201. if (!this.scrollingActive)
  202. this.debouncedSetRecentBook(newValue);
  203. else
  204. this.scrollingSetRecentBook(newValue);
  205. }
  206. },
  207. routeParamPos: function(newValue) {
  208. if (!this.paramPosIgnore && newValue !== undefined && newValue != this.bookPos) {
  209. this.bookPos = newValue;
  210. }
  211. },
  212. routeParamUrl: function(newValue) {
  213. if (newValue !== '' && newValue !== this.mostRecentBook().url) {
  214. this.loadBook({url: newValue, bookPos: this.routeParamPos});
  215. }
  216. },
  217. settings: function() {
  218. this.loadSettings();
  219. this.updateRoute();
  220. },
  221. loaderActive: function(newValue) {
  222. (async() => {
  223. const recent = this.mostRecentBook();
  224. if (!newValue && !this.loading && recent && !await bookManager.hasBookParsed(recent)) {
  225. this.loadBook(recent);
  226. }
  227. })();
  228. },
  229. dualPageMode(newValue) {
  230. if (newValue)
  231. this.stopScrolling();
  232. },
  233. },
  234. };
  235. class Reader {
  236. _options = componentOptions;
  237. rstore = {};
  238. loaderActive = false;
  239. loadFileActive = false;
  240. fullScreenActive = false;
  241. setPositionActive = false;
  242. searchActive = false;
  243. copyTextActive = false;
  244. convOptionsActive = false;
  245. refreshActive = false;
  246. contentsActive = false;
  247. libsActive = false;
  248. recentBooksActive = false;
  249. offlineModeActive = false;
  250. settingsActive = false;
  251. clickMapActive = false;
  252. helpActive = false;
  253. scrollingActive = false;
  254. progressActive = false;
  255. bookPos = null;
  256. allowUrlParamBookPos = false;
  257. showRefreshIcon = true;
  258. mostRecentBookReactive = null;
  259. showToolButton = {};
  260. actionList = [];
  261. actionCur = -1;
  262. hidden = false;
  263. whatsNewVisible = false;
  264. whatsNewContent = '';
  265. donationVisible = false;
  266. dualPageMode = false;
  267. created() {
  268. this.rstore = rstore;
  269. this.loading = true;
  270. this.commit = this.$store.commit;
  271. this.reader = this.$store.state.reader;
  272. this.config = this.$store.state.config;
  273. this.$root.addEventHook('key', this.keyHook);
  274. this.lastActivePage = false;
  275. this.$watch(
  276. () => this.$route.path,
  277. (newValue) => {
  278. if (newValue == '/reader') {
  279. this.updateRoute();
  280. }
  281. }
  282. );
  283. this.debouncedSetRecentBook = _.debounce(async(newValue) => {
  284. const recent = this.mostRecentBook();
  285. if (recent && (recent.bookPos != newValue || recent.bookPosSeen !== this.bookPosSeen)) {
  286. await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
  287. if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
  288. this.addAction(newValue);
  289. this.paramPosIgnore = true;
  290. this.updateRoute();
  291. await this.$nextTick();
  292. this.paramPosIgnore = false;
  293. }
  294. }, 250, {maxWait: 5000});
  295. this.scrollingSetRecentBook = _.debounce((newValue) => {
  296. this.debouncedSetRecentBook(newValue);
  297. }, 15000, {maxWait: 20000});
  298. document.addEventListener('fullscreenchange', () => {
  299. this.fullScreenActive = (document.fullscreenElement !== null);
  300. });
  301. this.loadSettings();
  302. }
  303. mounted() {
  304. this.updateHeaderMinWidth();
  305. (async() => {
  306. await wallpaperStorage.init();
  307. await bookManager.init(this.settings);
  308. bookManager.addEventListener(this.bookManagerEvent);
  309. if (this.$root.getRootRoute() == '/reader') {
  310. if (this.routeParamUrl) {
  311. await this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos, force: this.routeParamRefresh});
  312. } else {
  313. this.loaderActive = true;
  314. }
  315. }
  316. await this.$refs.serverStorage.init();
  317. this.checkSetStorageAccessKey();
  318. this.checkActivateDonateHelpPage();
  319. this.loading = false;
  320. //проверим состояние Settings, и обновим, если надо
  321. const newSettings = rstore.addDefaultsToSettings(this.settings);
  322. if (newSettings) {
  323. this.commit('reader/setSettings', newSettings);
  324. }
  325. this.updateRoute();
  326. await this.$refs.dialogs.init();
  327. })();
  328. (async() => {
  329. this.isFirstNeedUpdateNotify = true;
  330. //вечный цикл, запрашиваем периодически конфиг для проверки выхода новой версии читалки
  331. while (true) {// eslint-disable-line no-constant-condition
  332. await this.checkNewVersionAvailable();
  333. await utils.sleep(3600*1000); //каждый час
  334. }
  335. //дальше кода нет
  336. })();
  337. }
  338. loadSettings() {
  339. const settings = this.settings;
  340. this.allowUrlParamBookPos = settings.allowUrlParamBookPos;
  341. this.copyFullText = settings.copyFullText;
  342. this.showClickMapPage = settings.showClickMapPage;
  343. this.clickControl = settings.clickControl;
  344. this.blinkCachedLoad = settings.blinkCachedLoad;
  345. this.showToolButton = settings.showToolButton;
  346. this.enableSitesFilter = settings.enableSitesFilter;
  347. this.showNeedUpdateNotify = settings.showNeedUpdateNotify;
  348. this.splitToPara = settings.splitToPara;
  349. this.djvuQuality = settings.djvuQuality;
  350. this.pdfAsText = settings.pdfAsText;
  351. this.pdfQuality = settings.pdfQuality;
  352. this.dualPageMode = settings.dualPageMode;
  353. this.userWallpapers = settings.userWallpapers;
  354. this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
  355. this.$root.readerActionByKeyEvent = (event) => {
  356. return this.readerActionByKeyCode[utils.keyEventToCode(event)];
  357. }
  358. this.updateHeaderMinWidth();
  359. this.loadWallpapers();//no await
  360. }
  361. showHelpOnErrorIfNeeded(errorMessage) {
  362. //небольшая эвристика
  363. let i = errorMessage.indexOf('http://');
  364. if (i < 0)
  365. i = errorMessage.indexOf('https://');
  366. errorMessage = errorMessage.substring(i + 7);
  367. const perCount = errorMessage.split('%').length - 1;
  368. if (perCount > errorMessage.length/3.2) {
  369. this.$refs.dialogs.showUrlHelp();
  370. return true;
  371. }
  372. return false;
  373. }
  374. //wallpaper css
  375. async loadWallpapers() {
  376. const wallpaperDataLength = await wallpaperStorage.getLength();
  377. if (wallpaperDataLength !== this.wallpaperDataLength) {//оптимизация
  378. this.wallpaperDataLength = wallpaperDataLength;
  379. let newCss = '';
  380. for (const wp of this.userWallpapers) {
  381. const data = await wallpaperStorage.getData(wp.cssClass);
  382. if (!data) {
  383. //здесь будем восстанавливать данные с сервера
  384. }
  385. if (data) {
  386. newCss += `.${wp.cssClass} {background: url(${data}) center; background-size: 100% 100%;}`;
  387. }
  388. }
  389. dynamicCss.replace('wallpapers', newCss);
  390. }
  391. }
  392. async checkNewVersionAvailable() {
  393. if (!this.checkingNewVersion && this.showNeedUpdateNotify) {
  394. this.checkingNewVersion = true;
  395. try {
  396. await utils.sleep(15*1000); //подождем 15 секунд, чтобы прогрузился ServiceWorker при выходе новой версии
  397. const config = await miscApi.loadConfig();
  398. this.commit('config/setConfig', config);
  399. let againMes = '';
  400. if (this.isFirstNeedUpdateNotify) {
  401. againMes = ' еще один раз';
  402. }
  403. if (this.version != this.clientVersion)
  404. this.$root.notify.info(`Вышла новая версия (v${this.version}) читалки.<br>Пожалуйста, обновите страницу${againMes}.`, 'Обновление');
  405. } catch(e) {
  406. console.error(e);
  407. } finally {
  408. this.checkingNewVersion = false;
  409. }
  410. this.isFirstNeedUpdateNotify = false;
  411. }
  412. }
  413. updateHeaderMinWidth() {
  414. const showButtonCount = Object.values(this.showToolButton).reduce((a, b) => a + (b ? 1 : 0), 0);
  415. if (this.$refs.buttons)
  416. this.$refs.buttons.style.minWidth = 65*showButtonCount + 'px';
  417. (async() => {
  418. await utils.sleep(1000);
  419. if (this.$refs.header)
  420. this.$refs.header.style.overflowX = 'auto';
  421. })();
  422. }
  423. checkSetStorageAccessKey() {
  424. const q = this.$route.query;
  425. if (q['setStorageAccessKey']) {
  426. this.$router.replace(`/reader`);
  427. this.settingsToggle();
  428. this.$nextTick(() => {
  429. this.$refs.settingsPage.enterServerStorageKey(
  430. Buffer.from(utils.fromBase58(q['setStorageAccessKey'])).toString()
  431. );
  432. });
  433. }
  434. }
  435. checkActivateDonateHelpPage() {
  436. const q = this.$route.query;
  437. if (q['donate']) {
  438. this.$router.replace(`/reader`);
  439. this.helpToggle();
  440. this.$nextTick(() => {
  441. this.$refs.helpPage.activateDonateHelpPage();
  442. });
  443. }
  444. }
  445. checkBookPosPercent() {
  446. const q = this.$route.query;
  447. if (q['__pp']) {
  448. let pp = q['__pp'];
  449. if (pp) {
  450. pp = parseFloat(pp) || 0;
  451. const recent = this.mostRecentBook();
  452. (async() => {
  453. await utils.sleep(100);
  454. this.bookPos = Math.floor(recent.textLength*pp/100);
  455. })();
  456. }
  457. }
  458. }
  459. get routeParamPos() {
  460. let result = undefined;
  461. const q = this.$route.query;
  462. if (q['__p']) {
  463. result = q['__p'];
  464. if (Array.isArray(result))
  465. result = result[0];
  466. }
  467. return (result ? parseInt(result, 10) || 0 : result);
  468. }
  469. updateRoute(isNewRoute) {
  470. if (this.loading)
  471. return;
  472. const recent = this.mostRecentBook();
  473. const pos = (recent && recent.bookPos && this.allowUrlParamBookPos ? `__p=${recent.bookPos}&` : '');
  474. const url = (recent ? `url=${recent.url}` : '');
  475. if (isNewRoute)
  476. this.$router.push(`/reader?${pos}${url}`).catch(() => {});
  477. else
  478. this.$router.replace(`/reader?${pos}${url}`).catch(() => {});
  479. }
  480. get mode() {
  481. return this.$store.state.config.mode;
  482. }
  483. get version() {
  484. return this.$store.state.config.version;
  485. }
  486. get clientVersion() {
  487. return versionHistory[0].version;
  488. }
  489. get routeParamUrl() {
  490. let result = '';
  491. const path = this.$route.fullPath;
  492. const i = path.indexOf('url=');
  493. if (i >= 0) {
  494. result = path.substr(i + 4);
  495. }
  496. return decodeURIComponent(result);
  497. }
  498. get routeParamRefresh() {
  499. const q = this.$route.query;
  500. return !!q['__refresh'];
  501. }
  502. bookPosChanged(event) {
  503. if (event.bookPosSeen !== undefined)
  504. this.bookPosSeen = event.bookPosSeen;
  505. this.bookPos = event.bookPos;
  506. }
  507. async bookManagerEvent(eventName, value) {
  508. if (eventName == 'set-recent' || eventName == 'recent-deleted') {
  509. const oldBook = (this.textPage ? this.textPage.lastBook : null);
  510. const oldPos = (this.textPage ? this.textPage.bookPos : null);
  511. const newBook = bookManager.mostRecentBook();
  512. if (!(oldBook && newBook && oldBook.key == newBook.key)) {
  513. this.mostRecentBook();
  514. }
  515. if (oldBook && newBook) {
  516. if (oldBook.key != newBook.key || oldBook.path != newBook.path) {
  517. this.loadingBook = true;
  518. try {
  519. await this.loadBook(newBook);
  520. } finally {
  521. this.loadingBook = false;
  522. }
  523. } else if (oldPos != newBook.bookPos) {
  524. while (this.loadingBook) await utils.sleep(100);
  525. this.bookPosChanged({bookPos: newBook.bookPos});
  526. }
  527. }
  528. }
  529. if (eventName == 'recent-changed') {
  530. if (this.recentBooksActive) {
  531. await this.$refs.recentBooksPage.updateTableData();
  532. }
  533. //сохранение в serverStorage
  534. if (value) {
  535. await utils.sleep(500);
  536. let timer = setTimeout(() => {
  537. if (!this.offlineModeActive)
  538. this.$root.notify.error('Таймаут соединения');
  539. }, 10000);
  540. try {
  541. await this.$refs.serverStorage.saveRecent(value);
  542. } catch (e) {
  543. if (!this.offlineModeActive)
  544. this.$root.notify.error(e.message);
  545. } finally {
  546. clearTimeout(timer);
  547. }
  548. }
  549. }
  550. }
  551. get toolBarActive() {
  552. return this.reader.toolBarActive;
  553. }
  554. mostRecentBook() {
  555. const result = bookManager.mostRecentBook();
  556. this.mostRecentBookReactive = result;
  557. return result;
  558. }
  559. get settings() {
  560. return this.$store.state.reader.settings;
  561. }
  562. addAction(pos) {
  563. let a = this.actionList;
  564. if (!a.length || a[a.length - 1] != pos) {
  565. a.push(pos);
  566. if (a.length > 20)
  567. a.shift();
  568. this.actionCur = a.length - 1;
  569. }
  570. }
  571. toolBarToggle() {
  572. this.commit('reader/setToolBarActive', !this.toolBarActive);
  573. this.$root.eventHook('resize');
  574. }
  575. fullScreenToggle() {
  576. this.fullScreenActive = !this.fullScreenActive;
  577. if (this.fullScreenActive) {
  578. this.$q.fullscreen.request();
  579. } else {
  580. this.$q.fullscreen.exit();
  581. }
  582. }
  583. closeAllWindows() {
  584. this.setPositionActive = false;
  585. this.copyTextActive = false;
  586. this.recentBooksActive = false;
  587. this.settingsActive = false;
  588. this.stopScrolling();
  589. this.stopSearch();
  590. this.helpActive = false;
  591. this.contentsActive = false;
  592. }
  593. loaderToggle() {
  594. this.loaderActive = !this.loaderActive;
  595. if (this.loaderActive) {
  596. this.closeAllWindows();
  597. }
  598. }
  599. loadFileToggle() {
  600. if (!this.loaderActive)
  601. this.loaderToggle();
  602. this.$nextTick(() => {
  603. const page = this.$refs.page;
  604. if (this.activePage == 'LoaderPage' && page.loadFileClick) {
  605. page.loadFileClick();
  606. }
  607. });
  608. }
  609. setPositionToggle() {
  610. this.setPositionActive = !this.setPositionActive;
  611. const page = this.$refs.page;
  612. if (this.setPositionActive && this.activePage == 'TextPage' && page.parsed) {
  613. this.closeAllWindows();
  614. this.setPositionActive = true;
  615. this.$nextTick(() => {
  616. const recent = this.mostRecentBook();
  617. this.$refs.setPositionPage.init(recent.bookPos, recent.textLength - 1);
  618. });
  619. } else {
  620. this.setPositionActive = false;
  621. }
  622. }
  623. stopScrolling() {
  624. if (this.scrollingActive)
  625. this.scrollingToggle();
  626. }
  627. scrollingToggle() {
  628. this.scrollingActive = !this.scrollingActive;
  629. if (this.activePage == 'TextPage') {
  630. const page = this.$refs.page;
  631. if (this.scrollingActive) {
  632. page.startTextScrolling();
  633. } else {
  634. page.stopTextScrolling();
  635. }
  636. }
  637. if (!this.scrollingActive) {
  638. this.scrollingSetRecentBook.flush();
  639. }
  640. }
  641. stopSearch() {
  642. if (this.searchActive)
  643. this.searchToggle();
  644. }
  645. startTextSearch(opts) {
  646. if (this.activePage == 'TextPage')
  647. this.$refs.page.startSearch(opts.needle);
  648. }
  649. stopTextSearch() {
  650. if (this.activePage == 'TextPage')
  651. this.$refs.page.stopSearch();
  652. }
  653. searchToggle() {
  654. this.searchActive = !this.searchActive;
  655. const page = this.$refs.page;
  656. if (this.searchActive && this.activePage == 'TextPage' && page.parsed) {
  657. this.closeAllWindows();
  658. this.searchActive = true;
  659. this.$nextTick(() => {
  660. this.$refs.searchPage.init(page.parsed);
  661. });
  662. } else {
  663. this.stopTextSearch();
  664. this.searchActive = false;
  665. }
  666. }
  667. copyTextToggle() {
  668. this.copyTextActive = !this.copyTextActive;
  669. const page = this.$refs.page;
  670. if (this.copyTextActive && this.activePage == 'TextPage' && page.parsed) {
  671. this.closeAllWindows();
  672. this.copyTextActive = true;
  673. this.$nextTick(() => {
  674. this.$refs.copyTextPage.init(this.mostRecentBook().bookPos, page.parsed, this.copyFullText);
  675. });
  676. } else {
  677. this.copyTextActive = false;
  678. }
  679. }
  680. recentBooksClose() {
  681. this.recentBooksActive = false;
  682. }
  683. recentBooksToggle() {
  684. this.recentBooksActive = !this.recentBooksActive;
  685. if (this.recentBooksActive) {
  686. this.closeAllWindows();
  687. this.$refs.recentBooksPage.init();
  688. this.recentBooksActive = true;
  689. } else {
  690. this.recentBooksActive = false;
  691. }
  692. }
  693. contentsPageToggle() {
  694. this.contentsActive = !this.contentsActive;
  695. const page = this.$refs.page;
  696. if (this.contentsActive && this.activePage == 'TextPage' && page.parsed) {
  697. this.closeAllWindows();
  698. this.contentsActive = true;
  699. this.$nextTick(() => {
  700. this.$refs.contentsPage.init(this.mostRecentBook(), page.parsed);
  701. });
  702. } else {
  703. this.contentsActive = false;
  704. }
  705. }
  706. libsClose() {
  707. if (this.libsActive)
  708. this.libsToogle();
  709. }
  710. libsToogle() {
  711. this.libsActive = !this.libsActive;
  712. if (this.libsActive) {
  713. this.$refs.libsPage.init();
  714. } else {
  715. this.$refs.libsPage.done();
  716. }
  717. }
  718. offlineModeToggle() {
  719. this.offlineModeActive = !this.offlineModeActive;
  720. this.$refs.serverStorage.offlineModeActive = this.offlineModeActive;
  721. }
  722. settingsToggle() {
  723. this.settingsActive = !this.settingsActive;
  724. if (this.settingsActive) {
  725. this.closeAllWindows();
  726. this.settingsActive = true;
  727. this.$nextTick(() => {
  728. this.$refs.settingsPage.init();
  729. });
  730. } else {
  731. this.settingsActive = false;
  732. }
  733. }
  734. convOptionsToggle() {
  735. this.settingsToggle();
  736. if (this.settingsActive)
  737. this.$refs.settingsPage.selectedTab = 'convert';
  738. }
  739. helpToggle() {
  740. this.helpActive = !this.helpActive;
  741. if (this.helpActive) {
  742. this.closeAllWindows();
  743. this.helpActive = true;
  744. }
  745. }
  746. donateToggle() {
  747. this.helpToggle();
  748. if (this.helpActive) {
  749. this.$nextTick(() => {
  750. this.$refs.helpPage.activateDonateHelpPage();
  751. });
  752. }
  753. }
  754. versionHistoryToggle() {
  755. this.helpToggle();
  756. if (this.helpActive) {
  757. this.$nextTick(() => {
  758. this.$refs.helpPage.activateVersionHistoryHelpPage();
  759. });
  760. }
  761. }
  762. refreshBook() {
  763. const mrb = this.mostRecentBook();
  764. this.loadBook({url: mrb.url, uploadFileName: mrb.uploadFileName, force: true});
  765. }
  766. undoAction() {
  767. if (this.actionCur > 0) {
  768. this.actionCur--;
  769. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  770. }
  771. }
  772. redoAction() {
  773. if (this.actionCur < this.actionList.length - 1) {
  774. this.actionCur++;
  775. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  776. }
  777. }
  778. buttonClick(action) {
  779. const activeClass = this.buttonActiveClass(action);
  780. this.$refs[action].blur();
  781. if (activeClass['tool-button-disabled'])
  782. return;
  783. this.doAction({action});
  784. }
  785. buttonActiveClass(action) {
  786. const classActive = { 'tool-button-active': true, 'tool-button-active:hover': true };
  787. const classDisabled = { 'tool-button-disabled': true, 'tool-button-disabled:hover': true };
  788. let classResult = {};
  789. switch (action) {
  790. case 'loader':
  791. case 'help':
  792. case 'fullScreen':
  793. case 'setPosition':
  794. case 'search':
  795. case 'copyText':
  796. case 'convOptions':
  797. case 'refresh':
  798. case 'contents':
  799. case 'libs':
  800. case 'recentBooks':
  801. case 'offlineMode':
  802. case 'settings':
  803. if (this.progressActive) {
  804. classResult = classDisabled;
  805. } else if (this[`${action}Active`]) {
  806. classResult = classActive;
  807. }
  808. break;
  809. case 'scrolling':
  810. if (this.progressActive || this.dualPageMode) {
  811. classResult = classDisabled;
  812. } else if (this[`${action}Active`]) {
  813. classResult = classActive;
  814. }
  815. break;
  816. case 'undoAction':
  817. if (this.actionCur <= 0)
  818. classResult = classDisabled;
  819. break;
  820. case 'redoAction':
  821. if (this.actionCur == this.actionList.length - 1)
  822. classResult = classDisabled;
  823. break;
  824. }
  825. if (this.activePage == 'LoaderPage' || !this.mostRecentBookReactive) {
  826. switch (action) {
  827. case 'undoAction':
  828. case 'redoAction':
  829. case 'setPosition':
  830. case 'scrolling':
  831. case 'search':
  832. case 'copyText':
  833. case 'contents':
  834. classResult = classDisabled;
  835. break;
  836. case 'refresh':
  837. case 'recentBooks':
  838. if (!this.mostRecentBookReactive)
  839. classResult = classDisabled;
  840. break;
  841. }
  842. }
  843. return classResult;
  844. }
  845. async activateClickMapPage() {
  846. if (this.clickControl && this.showClickMapPage && !this.clickMapActive) {
  847. this.clickMapActive = true;
  848. await this.$refs.clickMapPage.slowDisappear();
  849. this.clickMapActive = false;
  850. }
  851. }
  852. get activePage() {
  853. let result = undefined;
  854. if (this.progressActive)
  855. result = 'ProgressPage';
  856. else if (this.loaderActive)
  857. result = 'LoaderPage';
  858. else if (this.mostRecentBookReactive)
  859. result = 'TextPage';
  860. if (!result && !this.loading) {
  861. this.loaderActive = true;
  862. result = 'LoaderPage';
  863. }
  864. if (result != 'TextPage') {
  865. this.$root.setAppTitle();
  866. }
  867. // на LoaderPage всегда показываем toolBar
  868. if (result == 'LoaderPage' && !this.toolBarActive) {
  869. this.toolBarToggle();
  870. }
  871. if (this.lastActivePage != result && result == 'TextPage') {
  872. //акивируем страницу с текстом
  873. this.$nextTick(async() => {
  874. const last = this.mostRecentBookReactive;
  875. const isParsed = await bookManager.hasBookParsed(last);
  876. if (!isParsed) {
  877. this.$root.setAppTitle();
  878. return;
  879. }
  880. this.updateRoute();
  881. const textPage = this.$refs.page;
  882. if (textPage.showBook) {
  883. this.textPage = textPage;
  884. textPage.lastBook = last;
  885. textPage.bookPos = (last.bookPos !== undefined ? last.bookPos : 0);
  886. textPage.showBook();
  887. }
  888. });
  889. }
  890. this.lastActivePage = result;
  891. return result;
  892. }
  893. async loadBook(opts) {
  894. if (!opts || !opts.url) {
  895. this.mostRecentBook();
  896. return;
  897. }
  898. this.closeAllWindows();
  899. let url = encodeURI(decodeURI(opts.url));
  900. //TODO: убрать конвертирование 'file://' после 06.2021
  901. if (url.length == 71 && url.indexOf('file://') == 0)
  902. url = url.replace(/^file/, 'disk');
  903. if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0) &&
  904. (url.indexOf('disk://') != 0))
  905. url = 'http://' + url;
  906. // уже просматривается сейчас
  907. const lastBook = (this.textPage ? this.textPage.lastBook : null);
  908. if (!opts.force && lastBook && lastBook.url == url &&
  909. (!opts.path || opts.path == lastBook.path) &&
  910. await bookManager.hasBookParsed(lastBook)) {
  911. this.loaderActive = false;
  912. return;
  913. }
  914. this.progressActive = true;
  915. await this.$nextTick();
  916. const progress = this.$refs.page;
  917. this.actionList = [];
  918. this.actionCur = -1;
  919. try {
  920. progress.show();
  921. progress.setState({state: 'parse'});
  922. // есть ли среди недавних
  923. const key = bookManager.keyFromUrl(url);
  924. let wasOpened = await bookManager.getRecentBook({key});
  925. wasOpened = (wasOpened ? wasOpened : {});
  926. const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
  927. const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
  928. const uploadFileName = (opts.uploadFileName ? opts.uploadFileName : '');
  929. let book = null;
  930. if (!opts.force) {
  931. // пытаемся загрузить и распарсить книгу в менеджере из локального кэша
  932. const bookParsed = await bookManager.getBook({url, path: opts.path}, (prog) => {
  933. progress.setState({progress: prog});
  934. });
  935. // если есть в локальном кэше
  936. if (bookParsed) {
  937. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookParsed));
  938. this.mostRecentBook();
  939. this.addAction(bookPos);
  940. this.loaderActive = false;
  941. progress.hide(); this.progressActive = false;
  942. this.blinkCachedLoadMessage();
  943. this.checkBookPosPercent();
  944. await this.activateClickMapPage();
  945. return;
  946. }
  947. // иначе идем на сервер
  948. // пытаемся загрузить готовый файл с сервера
  949. if (wasOpened.path) {
  950. progress.setState({totalSteps: 5});
  951. try {
  952. const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
  953. progress.setState(state);
  954. });
  955. book = Object.assign({}, wasOpened, {data: resp.data});
  956. } catch (e) {
  957. //молчим
  958. }
  959. }
  960. }
  961. progress.setState({totalSteps: 5});
  962. // не удалось, скачиваем книгу полностью с конвертацией
  963. let loadCached = true;
  964. if (!book) {
  965. book = await readerApi.loadBook({
  966. url,
  967. uploadFileName,
  968. enableSitesFilter: this.enableSitesFilter,
  969. skipHtmlCheck: (this.splitToPara ? true : false),
  970. isText: (this.splitToPara ? true : false),
  971. djvuQuality: this.djvuQuality,
  972. pdfAsText: this.pdfAsText,
  973. pdfQuality: this.pdfQuality,
  974. },
  975. (state) => {
  976. progress.setState(state);
  977. }
  978. );
  979. loadCached = false;
  980. }
  981. // добавляем в bookManager
  982. progress.setState({state: 'parse', step: 5});
  983. const addedBook = await bookManager.addBook(book, (prog) => {
  984. progress.setState({progress: prog});
  985. });
  986. // добавляем в историю
  987. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, uploadFileName}, addedBook));
  988. this.mostRecentBook();
  989. this.addAction(bookPos);
  990. this.updateRoute(true);
  991. this.loaderActive = false;
  992. progress.hide(); this.progressActive = false;
  993. if (loadCached) {
  994. this.blinkCachedLoadMessage();
  995. } else
  996. this.stopBlink = true;
  997. this.checkBookPosPercent();
  998. await this.activateClickMapPage();
  999. } catch (e) {
  1000. progress.hide(); this.progressActive = false;
  1001. this.loaderActive = true;
  1002. if (!this.showHelpOnErrorIfNeeded(e.message)) {
  1003. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1004. }
  1005. } finally {
  1006. this.checkNewVersionAvailable();
  1007. }
  1008. }
  1009. async loadFile(opts) {
  1010. this.progressActive = true;
  1011. await this.$nextTick();
  1012. const progress = this.$refs.page;
  1013. try {
  1014. progress.show();
  1015. progress.setState({state: 'upload'});
  1016. const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
  1017. progress.setState(state);
  1018. });
  1019. progress.hide(); this.progressActive = false;
  1020. await this.loadBook({url, uploadFileName: opts.file.name, force: true});
  1021. } catch (e) {
  1022. progress.hide(); this.progressActive = false;
  1023. this.loaderActive = true;
  1024. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1025. }
  1026. }
  1027. blinkCachedLoadMessage() {
  1028. if (!this.blinkCachedLoad)
  1029. return;
  1030. this.blinkCount = 30;
  1031. if (!this.inBlink) {
  1032. this.inBlink = true;
  1033. this.stopBlink = false;
  1034. this.$nextTick(async() => {
  1035. let page = this.$refs.page;
  1036. while (this.blinkCount) {
  1037. this.showRefreshIcon = !this.showRefreshIcon;
  1038. if (page && page.blinkCachedLoadMessage)
  1039. page.blinkCachedLoadMessage(this.showRefreshIcon);
  1040. await utils.sleep(500);
  1041. if (this.stopBlink)
  1042. break;
  1043. this.blinkCount--;
  1044. page = this.$refs.page;
  1045. }
  1046. this.showRefreshIcon = true;
  1047. this.inBlink = false;
  1048. if (page && page.blinkCachedLoadMessage)
  1049. page.blinkCachedLoadMessage('finish');
  1050. });
  1051. }
  1052. }
  1053. doAction(opts) {
  1054. let result = true;
  1055. let {action = '', event = false} = opts;
  1056. switch (action) {
  1057. case 'loader':
  1058. this.loaderToggle();
  1059. break;
  1060. case 'loadFile':
  1061. this.loadFileToggle();
  1062. break;
  1063. case 'help':
  1064. this.helpToggle();
  1065. break;
  1066. case 'undoAction':
  1067. this.undoAction();
  1068. break;
  1069. case 'redoAction':
  1070. this.redoAction();
  1071. break;
  1072. case 'fullScreen':
  1073. this.fullScreenToggle();
  1074. break;
  1075. case 'scrolling':
  1076. this.scrollingToggle();
  1077. break;
  1078. case 'stopScrolling':
  1079. this.stopScrolling();
  1080. break;
  1081. case 'setPosition':
  1082. this.setPositionToggle();
  1083. break;
  1084. case 'search':
  1085. this.searchToggle();
  1086. break;
  1087. case 'copyText':
  1088. this.copyTextToggle();
  1089. break;
  1090. case 'convOptions':
  1091. this.convOptionsToggle();
  1092. break;
  1093. case 'refresh':
  1094. this.refreshBook();
  1095. break;
  1096. case 'contents':
  1097. this.contentsPageToggle();
  1098. break;
  1099. case 'libs':
  1100. this.libsToogle();
  1101. break;
  1102. case 'recentBooks':
  1103. this.recentBooksToggle();
  1104. break;
  1105. case 'offlineMode':
  1106. this.offlineModeToggle();
  1107. break;
  1108. case 'settings':
  1109. this.settingsToggle();
  1110. break;
  1111. case 'switchToolbar':
  1112. this.toolBarToggle();
  1113. break;
  1114. case 'donate':
  1115. this.donateToggle();
  1116. break;
  1117. default:
  1118. result = false;
  1119. break;
  1120. }
  1121. if (!result && this.activePage == 'TextPage' && this.$refs.page) {
  1122. result = true;
  1123. const textPage = this.$refs.page;
  1124. switch (action) {
  1125. case 'bookBegin':
  1126. textPage.doHome();
  1127. break;
  1128. case 'bookEnd':
  1129. textPage.doEnd();
  1130. break;
  1131. case 'pageBack':
  1132. textPage.doPageUp();
  1133. break;
  1134. case 'pageForward':
  1135. textPage.doPageDown();
  1136. break;
  1137. case 'lineBack':
  1138. textPage.doUp();
  1139. break;
  1140. case 'lineForward':
  1141. textPage.doDown();
  1142. break;
  1143. case 'incFontSize':
  1144. textPage.doFontSizeInc();
  1145. break;
  1146. case 'decFontSize':
  1147. textPage.doFontSizeDec();
  1148. break;
  1149. case 'scrollingSpeedUp':
  1150. textPage.doScrollingSpeedUp();
  1151. break;
  1152. case 'scrollingSpeedDown':
  1153. textPage.doScrollingSpeedDown();
  1154. break;
  1155. default:
  1156. result = false;
  1157. break;
  1158. }
  1159. }
  1160. if (result && event) {
  1161. event.preventDefault();
  1162. event.stopPropagation();
  1163. }
  1164. return result;
  1165. }
  1166. keyHook(event) {
  1167. let result = false;
  1168. if (this.$root.getRootRoute() == '/reader') {
  1169. if (this.$root.stdDialog.active)
  1170. return result;
  1171. if (!result)
  1172. result = this.$refs.dialogs.keyHook(event);
  1173. if (!result && this.helpActive)
  1174. result = this.$refs.helpPage.keyHook(event);
  1175. if (!result && this.settingsActive)
  1176. result = this.$refs.settingsPage.keyHook(event);
  1177. if (!result && this.recentBooksActive)
  1178. result = this.$refs.recentBooksPage.keyHook(event);
  1179. if (!result && this.setPositionActive)
  1180. result = this.$refs.setPositionPage.keyHook(event);
  1181. if (!result && this.searchActive)
  1182. result = this.$refs.searchPage.keyHook(event);
  1183. if (!result && this.copyTextActive)
  1184. result = this.$refs.copyTextPage.keyHook(event);
  1185. if (!result && this.contentsActive)
  1186. result = this.$refs.contentsPage.keyHook(event);
  1187. if (!result && this.$refs.page && this.$refs.page.keyHook)
  1188. result = this.$refs.page.keyHook(event);
  1189. if (!result && event.type == 'keydown') {
  1190. const action = this.$root.readerActionByKeyEvent(event);
  1191. if (action == 'loader') {
  1192. result = this.doAction({action, event});
  1193. }
  1194. if (!result && this.activePage == 'TextPage') {
  1195. result = this.doAction({action, event});
  1196. }
  1197. }
  1198. }
  1199. return result;
  1200. }
  1201. }
  1202. export default vueComponent(Reader);
  1203. //-----------------------------------------------------------------------------
  1204. </script>
  1205. <style scoped>
  1206. .header {
  1207. padding-left: 5px;
  1208. padding-right: 5px;
  1209. background-color: #1B695F;
  1210. color: #000;
  1211. overflow: hidden;
  1212. height: 50px;
  1213. }
  1214. .main {
  1215. background-color: #EBE2C9;
  1216. color: #000;
  1217. }
  1218. .tool-button {
  1219. margin: 0px 2px 0 2px;
  1220. padding: 0;
  1221. color: #3E843E;
  1222. background-color: #E6EDF4;
  1223. margin-top: 5px;
  1224. height: 38px;
  1225. width: 38px;
  1226. border: 0;
  1227. border-radius: 6px;
  1228. box-shadow: 3px 3px 5px black;
  1229. outline: 0;
  1230. }
  1231. .tool-button:hover {
  1232. background-color: white;
  1233. cursor: pointer;
  1234. }
  1235. .tool-button-active {
  1236. box-shadow: 0 0 0;
  1237. color: white;
  1238. background-color: #8AB45F;
  1239. position: relative;
  1240. top: 1px;
  1241. left: 1px;
  1242. }
  1243. .tool-button-active:hover {
  1244. color: white;
  1245. background-color: #81C581;
  1246. cursor: pointer;
  1247. }
  1248. .tool-button-disabled {
  1249. color: lightgray;
  1250. background-color: gray;
  1251. cursor: default;
  1252. }
  1253. .tool-button-disabled:hover {
  1254. color: lightgray;
  1255. background-color: gray;
  1256. cursor: default;
  1257. }
  1258. .space {
  1259. width: 10px;
  1260. display: inline-block;
  1261. }
  1262. .clear {
  1263. color: rgba(0,0,0,0);
  1264. }
  1265. </style>