Reader.vue 53 KB

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