Reader.vue 53 KB

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