Reader.vue 46 KB

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