Reader.vue 46 KB

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