Reader.vue 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  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({url: mrb.url, uploadFileName: mrb.uploadFileName, 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. const key = bookManager.keyFromUrl(url);
  946. let wasOpened = await bookManager.getRecentBook({key});
  947. wasOpened = (wasOpened ? wasOpened : {});
  948. const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
  949. const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
  950. const uploadFileName = (opts.uploadFileName ? opts.uploadFileName : '');
  951. let book = null;
  952. if (!opts.force) {
  953. // пытаемся загрузить и распарсить книгу в менеджере из локального кэша
  954. const bookParsed = await bookManager.getBook({url, path: opts.path}, (prog) => {
  955. progress.setState({progress: prog});
  956. });
  957. // если есть в локальном кэше
  958. if (bookParsed) {
  959. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookParsed));
  960. this.mostRecentBook();
  961. this.addAction(bookPos);
  962. this.loaderActive = false;
  963. progress.hide(); this.progressActive = false;
  964. this.blinkCachedLoadMessage();
  965. this.checkBookPosPercent();
  966. await this.activateClickMapPage();
  967. return;
  968. }
  969. // иначе идем на сервер
  970. // пытаемся загрузить готовый файл с сервера
  971. if (wasOpened.path) {
  972. progress.setState({totalSteps: 5});
  973. try {
  974. const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
  975. progress.setState(state);
  976. });
  977. book = Object.assign({}, wasOpened, {data: resp.data});
  978. } catch (e) {
  979. //молчим
  980. }
  981. }
  982. }
  983. progress.setState({totalSteps: 5});
  984. // не удалось, скачиваем книгу полностью с конвертацией
  985. let loadCached = true;
  986. if (!book) {
  987. book = await readerApi.loadBook({
  988. url,
  989. uploadFileName,
  990. enableSitesFilter: this.enableSitesFilter,
  991. skipHtmlCheck: (this.splitToPara ? true : false),
  992. isText: (this.splitToPara ? true : false),
  993. djvuQuality: this.djvuQuality,
  994. pdfAsText: this.pdfAsText,
  995. pdfQuality: this.pdfQuality,
  996. },
  997. (state) => {
  998. progress.setState(state);
  999. }
  1000. );
  1001. loadCached = false;
  1002. }
  1003. // добавляем в bookManager
  1004. progress.setState({state: 'parse', step: 5});
  1005. const addedBook = await bookManager.addBook(book, (prog) => {
  1006. progress.setState({progress: prog});
  1007. });
  1008. // добавляем в историю
  1009. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, uploadFileName}, addedBook));
  1010. this.mostRecentBook();
  1011. this.addAction(bookPos);
  1012. this.updateRoute(true);
  1013. this.loaderActive = false;
  1014. progress.hide(); this.progressActive = false;
  1015. if (loadCached) {
  1016. this.blinkCachedLoadMessage();
  1017. } else
  1018. this.stopBlink = true;
  1019. this.checkBookPosPercent();
  1020. await this.activateClickMapPage();
  1021. } catch (e) {
  1022. progress.hide(); this.progressActive = false;
  1023. this.loaderActive = true;
  1024. if (!this.showHelpOnErrorIfNeeded(url)) {
  1025. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1026. }
  1027. } finally {
  1028. this.checkNewVersionAvailable();
  1029. }
  1030. }
  1031. async loadBook(opts) {
  1032. await this.lock.get();
  1033. try {
  1034. await this._loadBook(opts);
  1035. } finally {
  1036. this.lock.ret();
  1037. }
  1038. }
  1039. async _loadFile(opts) {
  1040. this.progressActive = true;
  1041. await this.$nextTick();
  1042. const progress = this.$refs.page;
  1043. try {
  1044. progress.show();
  1045. progress.setState({state: 'upload'});
  1046. const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
  1047. progress.setState(state);
  1048. });
  1049. progress.hide(); this.progressActive = false;
  1050. await this.loadBook({url, uploadFileName: opts.file.name, force: true});
  1051. } catch (e) {
  1052. progress.hide(); this.progressActive = false;
  1053. this.loaderActive = true;
  1054. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1055. }
  1056. }
  1057. async loadFile(opts) {
  1058. await this.lock.get();
  1059. try {
  1060. await this._loadFile(opts);
  1061. } finally {
  1062. this.lock.ret();
  1063. }
  1064. }
  1065. blinkCachedLoadMessage() {
  1066. if (!this.blinkCachedLoad)
  1067. return;
  1068. this.blinkCount = 30;
  1069. if (!this.inBlink) {
  1070. this.inBlink = true;
  1071. this.stopBlink = false;
  1072. this.$nextTick(async() => {
  1073. let page = this.$refs.page;
  1074. while (this.blinkCount) {
  1075. this.showRefreshIcon = !this.showRefreshIcon;
  1076. if (page && page.blinkCachedLoadMessage)
  1077. page.blinkCachedLoadMessage(this.showRefreshIcon);
  1078. await utils.sleep(500);
  1079. if (this.stopBlink)
  1080. break;
  1081. this.blinkCount--;
  1082. page = this.$refs.page;
  1083. }
  1084. this.showRefreshIcon = true;
  1085. this.inBlink = false;
  1086. if (page && page.blinkCachedLoadMessage)
  1087. page.blinkCachedLoadMessage('finish');
  1088. });
  1089. }
  1090. }
  1091. doAction(opts) {
  1092. let result = true;
  1093. let {action = '', event = false} = opts;
  1094. switch (action) {
  1095. case 'loader':
  1096. this.loaderToggle();
  1097. break;
  1098. case 'loadFile':
  1099. this.loadFileToggle();
  1100. break;
  1101. case 'loadBuffer':
  1102. this.loadBufferToggle();
  1103. break;
  1104. case 'help':
  1105. this.helpToggle();
  1106. break;
  1107. case 'undoAction':
  1108. this.undoAction();
  1109. break;
  1110. case 'redoAction':
  1111. this.redoAction();
  1112. break;
  1113. case 'fullScreen':
  1114. this.fullScreenToggle();
  1115. break;
  1116. case 'scrolling':
  1117. this.scrollingToggle();
  1118. break;
  1119. case 'stopScrolling':
  1120. this.stopScrolling();
  1121. break;
  1122. case 'setPosition':
  1123. this.setPositionToggle();
  1124. break;
  1125. case 'search':
  1126. this.searchToggle();
  1127. break;
  1128. case 'copyText':
  1129. this.copyTextToggle();
  1130. break;
  1131. case 'convOptions':
  1132. this.convOptionsToggle();
  1133. break;
  1134. case 'refresh':
  1135. this.refreshBook();
  1136. break;
  1137. case 'contents':
  1138. this.contentsPageToggle();
  1139. break;
  1140. case 'libs':
  1141. this.libsToogle();
  1142. break;
  1143. case 'recentBooks':
  1144. this.recentBooksToggle();
  1145. break;
  1146. case 'clickControl':
  1147. this.clickControlToggle();
  1148. break;
  1149. case 'offlineMode':
  1150. this.offlineModeToggle();
  1151. break;
  1152. case 'settings':
  1153. this.settingsToggle();
  1154. break;
  1155. case 'switchToolbar':
  1156. this.toolBarToggle();
  1157. break;
  1158. case 'donate':
  1159. this.donateToggle();
  1160. break;
  1161. default:
  1162. result = false;
  1163. break;
  1164. }
  1165. if (!result && this.activePage == 'TextPage' && this.$refs.page) {
  1166. result = true;
  1167. const textPage = this.$refs.page;
  1168. switch (action) {
  1169. case 'bookBegin':
  1170. textPage.doHome();
  1171. break;
  1172. case 'bookEnd':
  1173. textPage.doEnd();
  1174. break;
  1175. case 'pageBack':
  1176. textPage.doPageUp();
  1177. break;
  1178. case 'pageForward':
  1179. textPage.doPageDown();
  1180. break;
  1181. case 'lineBack':
  1182. textPage.doUp();
  1183. break;
  1184. case 'lineForward':
  1185. textPage.doDown();
  1186. break;
  1187. case 'incFontSize':
  1188. textPage.doFontSizeInc();
  1189. break;
  1190. case 'decFontSize':
  1191. textPage.doFontSizeDec();
  1192. break;
  1193. case 'scrollingSpeedUp':
  1194. textPage.doScrollingSpeedUp();
  1195. break;
  1196. case 'scrollingSpeedDown':
  1197. textPage.doScrollingSpeedDown();
  1198. break;
  1199. default:
  1200. result = false;
  1201. break;
  1202. }
  1203. }
  1204. if (result && event) {
  1205. event.preventDefault();
  1206. event.stopPropagation();
  1207. }
  1208. return result;
  1209. }
  1210. keyHook(event) {
  1211. let result = false;
  1212. if (this.$root.getRootRoute() == '/reader') {
  1213. if (this.$root.stdDialog.active)
  1214. return result;
  1215. if (!result)
  1216. result = this.$refs.dialogs.keyHook(event);
  1217. if (!result && this.helpActive)
  1218. result = this.$refs.helpPage.keyHook(event);
  1219. if (!result && this.settingsActive)
  1220. result = this.$refs.settingsPage.keyHook(event);
  1221. if (!result && this.recentBooksActive)
  1222. result = this.$refs.recentBooksPage.keyHook(event);
  1223. if (!result && this.setPositionActive)
  1224. result = this.$refs.setPositionPage.keyHook(event);
  1225. if (!result && this.searchActive)
  1226. result = this.$refs.searchPage.keyHook(event);
  1227. if (!result && this.copyTextActive)
  1228. result = this.$refs.copyTextPage.keyHook(event);
  1229. if (!result && this.contentsActive)
  1230. result = this.$refs.contentsPage.keyHook(event);
  1231. if (!result && this.$refs.page && this.$refs.page.keyHook)
  1232. result = this.$refs.page.keyHook(event);
  1233. if (!result && event.type == 'keydown') {
  1234. const action = this.$root.readerActionByKeyEvent(event);
  1235. /*if (action == 'loader') {
  1236. result = this.doAction({action, event});
  1237. }
  1238. if (!result && this.activePage == 'TextPage') {
  1239. result = this.doAction({action, event});
  1240. }*/
  1241. result = this.doAction({action, event});
  1242. }
  1243. }
  1244. return result;
  1245. }
  1246. }
  1247. export default vueComponent(Reader);
  1248. //-----------------------------------------------------------------------------
  1249. </script>
  1250. <style scoped>
  1251. .header {
  1252. height: 50px;
  1253. padding-left: 5px;
  1254. padding-right: 5px;
  1255. background-color: #1B695F;
  1256. color: #000;
  1257. overflow-x: auto;
  1258. overflow-y: hidden;
  1259. scrollbar-color: #c49a60 #e4e4e4;
  1260. }
  1261. .header::-webkit-scrollbar {
  1262. height: 10px;
  1263. }
  1264. .header::-webkit-scrollbar-track {
  1265. background-color: #e4e4e4;
  1266. border-radius: 4px;
  1267. }
  1268. .header::-webkit-scrollbar-thumb {
  1269. background-color: #c49a60;
  1270. border-radius: 4px;
  1271. border: 2px solid #e4e4e4;
  1272. }
  1273. .header::-webkit-scrollbar-thumb:hover {
  1274. background-color: #b48a50;
  1275. }
  1276. .main {
  1277. background-color: #EBE2C9;
  1278. color: #000;
  1279. }
  1280. .tool-button {
  1281. margin: 0px 2px 0 2px;
  1282. padding: 0;
  1283. color: #3E843E;
  1284. background-color: #E6EDF4;
  1285. margin-top: 5px;
  1286. height: 38px;
  1287. width: 38px;
  1288. border: 0;
  1289. border-radius: 6px;
  1290. box-shadow: 3px 3px 5px black;
  1291. outline: 0;
  1292. }
  1293. .tool-button:hover {
  1294. background-color: white;
  1295. cursor: pointer;
  1296. }
  1297. .tool-button-active {
  1298. box-shadow: 0 0 0;
  1299. color: white;
  1300. background-color: #8AB45F;
  1301. position: relative;
  1302. top: 1px;
  1303. left: 1px;
  1304. }
  1305. .tool-button-active:hover {
  1306. color: white;
  1307. background-color: #81C581;
  1308. cursor: pointer;
  1309. }
  1310. .tool-button-disabled {
  1311. color: lightgray;
  1312. background-color: gray;
  1313. cursor: default;
  1314. }
  1315. .tool-button-disabled:hover {
  1316. color: lightgray;
  1317. background-color: gray;
  1318. cursor: default;
  1319. }
  1320. .space {
  1321. width: 10px;
  1322. display: inline-block;
  1323. }
  1324. .clear {
  1325. color: rgba(0,0,0,0);
  1326. }
  1327. </style>