Reader.vue 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  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" @load-book="loadBook" @libs-close="libsClose"></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.recentBooksActive = false;
  521. this.settingsActive = false;
  522. this.stopScrolling();
  523. this.stopSearch();
  524. this.helpActive = false;
  525. }
  526. loaderToggle() {
  527. this.loaderActive = !this.loaderActive;
  528. if (this.loaderActive) {
  529. this.closeAllWindows();
  530. }
  531. }
  532. setPositionToggle() {
  533. this.setPositionActive = !this.setPositionActive;
  534. const page = this.$refs.page;
  535. if (this.setPositionActive && this.activePage == 'TextPage' && page.parsed) {
  536. this.closeAllWindows();
  537. this.setPositionActive = true;
  538. this.$nextTick(() => {
  539. const recent = this.mostRecentBook();
  540. this.$refs.setPositionPage.init(recent.bookPos, recent.textLength - 1);
  541. });
  542. } else {
  543. this.setPositionActive = false;
  544. }
  545. }
  546. stopScrolling() {
  547. if (this.scrollingActive)
  548. this.scrollingToggle();
  549. }
  550. scrollingToggle() {
  551. this.scrollingActive = !this.scrollingActive;
  552. if (this.activePage == 'TextPage') {
  553. const page = this.$refs.page;
  554. if (this.scrollingActive) {
  555. page.startTextScrolling();
  556. } else {
  557. page.stopTextScrolling();
  558. }
  559. }
  560. if (!this.scrollingActive) {
  561. this.scrollingSetRecentBook.flush();
  562. }
  563. }
  564. stopSearch() {
  565. if (this.searchActive)
  566. this.searchToggle();
  567. }
  568. startTextSearch(opts) {
  569. if (this.activePage == 'TextPage')
  570. this.$refs.page.startSearch(opts.needle);
  571. }
  572. stopTextSearch() {
  573. if (this.activePage == 'TextPage')
  574. this.$refs.page.stopSearch();
  575. }
  576. searchToggle() {
  577. this.searchActive = !this.searchActive;
  578. const page = this.$refs.page;
  579. if (this.searchActive && this.activePage == 'TextPage' && page.parsed) {
  580. this.closeAllWindows();
  581. this.searchActive = true;
  582. this.$nextTick(() => {
  583. this.$refs.searchPage.init(page.parsed);
  584. });
  585. } else {
  586. this.stopTextSearch();
  587. this.searchActive = false;
  588. }
  589. }
  590. copyTextToggle() {
  591. this.copyTextActive = !this.copyTextActive;
  592. const page = this.$refs.page;
  593. if (this.copyTextActive && this.activePage == 'TextPage' && page.parsed) {
  594. this.closeAllWindows();
  595. this.copyTextActive = true;
  596. this.$nextTick(() => {
  597. this.$refs.copyTextPage.init(this.mostRecentBook().bookPos, page.parsed, this.copyFullText);
  598. });
  599. } else {
  600. this.copyTextActive = false;
  601. }
  602. }
  603. recentBooksClose() {
  604. this.recentBooksActive = false;
  605. }
  606. recentBooksToggle() {
  607. this.recentBooksActive = !this.recentBooksActive;
  608. if (this.recentBooksActive) {
  609. this.closeAllWindows();
  610. this.$refs.recentBooksPage.init();
  611. this.recentBooksActive = true;
  612. } else {
  613. this.recentBooksActive = false;
  614. }
  615. }
  616. libsClose() {
  617. if (this.libsActive)
  618. this.libsToogle();
  619. }
  620. libsToogle() {
  621. this.libsActive = !this.libsActive;
  622. if (this.libsActive) {
  623. this.$refs.libsPage.init();
  624. } else {
  625. this.$refs.libsPage.done();
  626. }
  627. }
  628. offlineModeToggle() {
  629. this.offlineModeActive = !this.offlineModeActive;
  630. this.$refs.serverStorage.offlineModeActive = this.offlineModeActive;
  631. }
  632. settingsToggle() {
  633. this.settingsActive = !this.settingsActive;
  634. if (this.settingsActive) {
  635. this.closeAllWindows();
  636. this.settingsActive = true;
  637. this.$nextTick(() => {
  638. this.$refs.settingsPage.init();
  639. });
  640. } else {
  641. this.settingsActive = false;
  642. }
  643. }
  644. helpToggle() {
  645. this.helpActive = !this.helpActive;
  646. if (this.helpActive) {
  647. this.closeAllWindows();
  648. this.helpActive = true;
  649. }
  650. }
  651. donateToggle() {
  652. this.helpToggle();
  653. if (this.helpActive) {
  654. this.$nextTick(() => {
  655. this.$refs.helpPage.activateDonateHelpPage();
  656. });
  657. }
  658. }
  659. versionHistoryToggle() {
  660. this.helpToggle();
  661. if (this.helpActive) {
  662. this.$nextTick(() => {
  663. this.$refs.helpPage.activateVersionHistoryHelpPage();
  664. });
  665. }
  666. }
  667. refreshBook() {
  668. if (this.mostRecentBook()) {
  669. this.loadBook({url: this.mostRecentBook().url, force: true});
  670. }
  671. }
  672. undoAction() {
  673. if (this.actionCur > 0) {
  674. this.actionCur--;
  675. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  676. }
  677. }
  678. redoAction() {
  679. if (this.actionCur < this.actionList.length - 1) {
  680. this.actionCur++;
  681. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  682. }
  683. }
  684. buttonClick(action) {
  685. const activeClass = this.buttonActiveClass(action);
  686. this.$refs[action].blur();
  687. if (activeClass['tool-button-disabled'])
  688. return;
  689. this.doAction({action});
  690. }
  691. buttonActiveClass(action) {
  692. const classActive = { 'tool-button-active': true, 'tool-button-active:hover': true };
  693. const classDisabled = { 'tool-button-disabled': true, 'tool-button-disabled:hover': true };
  694. let classResult = {};
  695. switch (action) {
  696. case 'loader':
  697. case 'fullScreen':
  698. case 'setPosition':
  699. case 'scrolling':
  700. case 'search':
  701. case 'copyText':
  702. case 'refresh':
  703. case 'libs':
  704. case 'recentBooks':
  705. case 'offlineMode':
  706. case 'settings':
  707. if (this.progressActive) {
  708. classResult = classDisabled;
  709. } else if (this[`${action}Active`]) {
  710. classResult = classActive;
  711. }
  712. break;
  713. case 'undoAction':
  714. if (this.actionCur <= 0)
  715. classResult = classDisabled;
  716. break;
  717. case 'redoAction':
  718. if (this.actionCur == this.actionList.length - 1)
  719. classResult = classDisabled;
  720. break;
  721. }
  722. if (this.activePage == 'LoaderPage' || !this.mostRecentBookReactive) {
  723. switch (action) {
  724. case 'undoAction':
  725. case 'redoAction':
  726. case 'setPosition':
  727. case 'scrolling':
  728. case 'search':
  729. case 'copyText':
  730. classResult = classDisabled;
  731. break;
  732. case 'recentBooks':
  733. case 'refresh':
  734. if (!this.mostRecentBookReactive)
  735. classResult = classDisabled;
  736. break;
  737. }
  738. }
  739. return classResult;
  740. }
  741. async activateClickMapPage() {
  742. if (this.clickControl && this.showClickMapPage && !this.clickMapActive) {
  743. this.clickMapActive = true;
  744. await this.$refs.clickMapPage.slowDisappear();
  745. this.clickMapActive = false;
  746. }
  747. }
  748. get activePage() {
  749. let result = '';
  750. if (this.progressActive)
  751. result = 'ProgressPage';
  752. else if (this.loaderActive)
  753. result = 'LoaderPage';
  754. else if (this.mostRecentBookReactive)
  755. result = 'TextPage';
  756. if (!result && !this.loading) {
  757. this.loaderActive = true;
  758. result = 'LoaderPage';
  759. }
  760. if (result != 'TextPage') {
  761. this.$root.$emit('set-app-title');
  762. }
  763. // на LoaderPage всегда показываем toolBar
  764. if (result == 'LoaderPage' && !this.toolBarActive) {
  765. this.toolBarToggle();
  766. }
  767. if (this.lastActivePage != result && result == 'TextPage') {
  768. //акивируем страницу с текстом
  769. this.$nextTick(async() => {
  770. const last = this.mostRecentBookReactive;
  771. const isParsed = await bookManager.hasBookParsed(last);
  772. if (!isParsed) {
  773. this.$root.$emit('set-app-title');
  774. return;
  775. }
  776. this.updateRoute();
  777. const textPage = this.$refs.page;
  778. if (textPage.showBook) {
  779. this.textPage = textPage;
  780. textPage.lastBook = last;
  781. textPage.bookPos = (last.bookPos !== undefined ? last.bookPos : 0);
  782. textPage.showBook();
  783. }
  784. });
  785. }
  786. this.lastActivePage = result;
  787. return result;
  788. }
  789. async loadBook(opts) {
  790. if (!opts || !opts.url) {
  791. this.mostRecentBook();
  792. return;
  793. }
  794. this.closeAllWindows();
  795. let url = encodeURI(decodeURI(opts.url));
  796. if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0) &&
  797. (url.indexOf('file://') != 0))
  798. url = 'http://' + url;
  799. // уже просматривается сейчас
  800. const lastBook = (this.textPage ? this.textPage.lastBook : null);
  801. if (!opts.force && lastBook && lastBook.url == url &&
  802. (!opts.path || opts.path == lastBook.path) &&
  803. await bookManager.hasBookParsed(lastBook)) {
  804. this.loaderActive = false;
  805. return;
  806. }
  807. this.progressActive = true;
  808. await this.$nextTick();
  809. const progress = this.$refs.page;
  810. this.actionList = [];
  811. this.actionCur = -1;
  812. try {
  813. progress.show();
  814. progress.setState({state: 'parse'});
  815. // есть ли среди недавних
  816. const key = bookManager.keyFromUrl(url);
  817. let wasOpened = await bookManager.getRecentBook({key});
  818. wasOpened = (wasOpened ? wasOpened : {});
  819. const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
  820. const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
  821. let book = null;
  822. if (!opts.force) {
  823. // пытаемся загрузить и распарсить книгу в менеджере из локального кэша
  824. const bookParsed = await bookManager.getBook({url, path: opts.path}, (prog) => {
  825. progress.setState({progress: prog});
  826. });
  827. // если есть в локальном кэше
  828. if (bookParsed) {
  829. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookParsed));
  830. this.mostRecentBook();
  831. this.addAction(bookPos);
  832. this.loaderActive = false;
  833. progress.hide(); this.progressActive = false;
  834. this.blinkCachedLoadMessage();
  835. this.checkBookPosPercent();
  836. await this.activateClickMapPage();
  837. return;
  838. }
  839. // иначе идем на сервер
  840. // пытаемся загрузить готовый файл с сервера
  841. if (wasOpened.path) {
  842. progress.setState({totalSteps: 5});
  843. try {
  844. const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
  845. progress.setState(state);
  846. });
  847. book = Object.assign({}, wasOpened, {data: resp.data});
  848. } catch (e) {
  849. //молчим
  850. }
  851. }
  852. }
  853. progress.setState({totalSteps: 5});
  854. // не удалось, скачиваем книгу полностью с конвертацией
  855. let loadCached = true;
  856. if (!book) {
  857. book = await readerApi.loadBook({url, enableSitesFilter: this.enableSitesFilter}, (state) => {
  858. progress.setState(state);
  859. });
  860. loadCached = false;
  861. }
  862. // добавляем в bookManager
  863. progress.setState({state: 'parse', step: 5});
  864. const addedBook = await bookManager.addBook(book, (prog) => {
  865. progress.setState({progress: prog});
  866. });
  867. // добавляем в историю
  868. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, addedBook));
  869. this.mostRecentBook();
  870. this.addAction(bookPos);
  871. this.updateRoute(true);
  872. this.loaderActive = false;
  873. progress.hide(); this.progressActive = false;
  874. if (loadCached) {
  875. this.blinkCachedLoadMessage();
  876. } else
  877. this.stopBlink = true;
  878. this.checkBookPosPercent();
  879. await this.activateClickMapPage();
  880. } catch (e) {
  881. progress.hide(); this.progressActive = false;
  882. this.loaderActive = true;
  883. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  884. }
  885. }
  886. async loadFile(opts) {
  887. this.progressActive = true;
  888. await this.$nextTick();
  889. const progress = this.$refs.page;
  890. try {
  891. progress.show();
  892. progress.setState({state: 'upload'});
  893. const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
  894. progress.setState(state);
  895. });
  896. progress.hide(); this.progressActive = false;
  897. await this.loadBook({url});
  898. } catch (e) {
  899. progress.hide(); this.progressActive = false;
  900. this.loaderActive = true;
  901. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  902. }
  903. }
  904. blinkCachedLoadMessage() {
  905. if (!this.blinkCachedLoad)
  906. return;
  907. this.blinkCount = 30;
  908. if (!this.inBlink) {
  909. this.inBlink = true;
  910. this.stopBlink = false;
  911. this.$nextTick(async() => {
  912. let page = this.$refs.page;
  913. while (this.blinkCount) {
  914. this.showRefreshIcon = !this.showRefreshIcon;
  915. if (page && page.blinkCachedLoadMessage)
  916. page.blinkCachedLoadMessage(this.showRefreshIcon);
  917. await utils.sleep(500);
  918. if (this.stopBlink)
  919. break;
  920. this.blinkCount--;
  921. page = this.$refs.page;
  922. }
  923. this.showRefreshIcon = true;
  924. this.inBlink = false;
  925. if (page && page.blinkCachedLoadMessage)
  926. page.blinkCachedLoadMessage('finish');
  927. });
  928. }
  929. }
  930. doAction(opts) {
  931. let result = true;
  932. let {action = '', event = false} = opts;
  933. switch (action) {
  934. case 'loader':
  935. this.loaderToggle();
  936. break;
  937. case 'help':
  938. this.helpToggle();
  939. break;
  940. case 'undoAction':
  941. this.undoAction();
  942. break;
  943. case 'redoAction':
  944. this.redoAction();
  945. break;
  946. case 'fullScreen':
  947. this.fullScreenToggle();
  948. break;
  949. case 'scrolling':
  950. this.scrollingToggle();
  951. break;
  952. case 'stopScrolling':
  953. this.stopScrolling();
  954. break;
  955. case 'setPosition':
  956. this.setPositionToggle();
  957. break;
  958. case 'search':
  959. this.searchToggle();
  960. break;
  961. case 'copyText':
  962. this.copyTextToggle();
  963. break;
  964. case 'refresh':
  965. this.refreshBook();
  966. break;
  967. case 'libs':
  968. this.libsToogle();
  969. break;
  970. case 'recentBooks':
  971. this.recentBooksToggle();
  972. break;
  973. case 'offlineMode':
  974. this.offlineModeToggle();
  975. break;
  976. case 'settings':
  977. this.settingsToggle();
  978. break;
  979. case 'switchToolbar':
  980. this.toolBarToggle();
  981. break;
  982. case 'donate':
  983. this.donateToggle();
  984. break;
  985. default:
  986. result = false;
  987. break;
  988. }
  989. if (!result && this.activePage == 'TextPage' && this.$refs.page) {
  990. result = true;
  991. const textPage = this.$refs.page;
  992. switch (action) {
  993. case 'bookBegin':
  994. textPage.doHome();
  995. break;
  996. case 'bookEnd':
  997. textPage.doEnd();
  998. break;
  999. case 'pageBack':
  1000. textPage.doPageUp();
  1001. break;
  1002. case 'pageForward':
  1003. textPage.doPageDown();
  1004. break;
  1005. case 'lineBack':
  1006. textPage.doUp();
  1007. break;
  1008. case 'lineForward':
  1009. textPage.doDown();
  1010. break;
  1011. case 'incFontSize':
  1012. textPage.doFontSizeInc();
  1013. break;
  1014. case 'decFontSize':
  1015. textPage.doFontSizeDec();
  1016. break;
  1017. case 'scrollingSpeedUp':
  1018. textPage.doScrollingSpeedUp();
  1019. break;
  1020. case 'scrollingSpeedDown':
  1021. textPage.doScrollingSpeedDown();
  1022. break;
  1023. default:
  1024. result = false;
  1025. break;
  1026. }
  1027. }
  1028. if (result && event) {
  1029. event.preventDefault();
  1030. event.stopPropagation();
  1031. }
  1032. return result;
  1033. }
  1034. keyHook(event) {
  1035. let result = false;
  1036. if (this.$root.rootRoute() == '/reader') {
  1037. if (this.$root.stdDialog.active || this.$refs.dialog1.active || this.$refs.dialog2.active)
  1038. return result;
  1039. let handled = false;
  1040. if (!handled && this.helpActive)
  1041. handled = this.$refs.helpPage.keyHook(event);
  1042. if (!handled && this.settingsActive)
  1043. handled = this.$refs.settingsPage.keyHook(event);
  1044. if (!handled && this.recentBooksActive)
  1045. handled = this.$refs.recentBooksPage.keyHook(event);
  1046. if (!handled && this.setPositionActive)
  1047. handled = this.$refs.setPositionPage.keyHook(event);
  1048. if (!handled && this.searchActive)
  1049. handled = this.$refs.searchPage.keyHook(event);
  1050. if (!handled && this.copyTextActive)
  1051. handled = this.$refs.copyTextPage.keyHook(event);
  1052. if (!handled && this.$refs.page && this.$refs.page.keyHook)
  1053. handled = this.$refs.page.keyHook(event);
  1054. if (!handled && event.type == 'keydown') {
  1055. const action = this.$root.readerActionByKeyEvent(event);
  1056. if (action == 'loader') {
  1057. result = this.doAction({action, event});
  1058. }
  1059. if (!result && this.activePage == 'TextPage') {
  1060. result = this.doAction({action, event});
  1061. }
  1062. }
  1063. }
  1064. return result;
  1065. }
  1066. }
  1067. //-----------------------------------------------------------------------------
  1068. </script>
  1069. <style scoped>
  1070. .header {
  1071. padding-left: 5px;
  1072. padding-right: 5px;
  1073. background-color: #1B695F;
  1074. color: #000;
  1075. overflow: hidden;
  1076. height: 50px;
  1077. }
  1078. .main {
  1079. background-color: #EBE2C9;
  1080. color: #000;
  1081. }
  1082. .tool-button {
  1083. margin: 0px 2px 0 2px;
  1084. padding: 0;
  1085. color: #3E843E;
  1086. background-color: #E6EDF4;
  1087. margin-top: 5px;
  1088. height: 38px;
  1089. width: 38px;
  1090. border: 0;
  1091. border-radius: 6px;
  1092. box-shadow: 3px 3px 5px black;
  1093. outline: 0;
  1094. }
  1095. .tool-button:hover {
  1096. background-color: white;
  1097. cursor: pointer;
  1098. }
  1099. .tool-button-active {
  1100. box-shadow: 0 0 0;
  1101. color: white;
  1102. background-color: #8AB45F;
  1103. position: relative;
  1104. top: 1px;
  1105. left: 1px;
  1106. }
  1107. .tool-button-active:hover {
  1108. color: white;
  1109. background-color: #81C581;
  1110. cursor: pointer;
  1111. }
  1112. .tool-button-disabled {
  1113. color: lightgray;
  1114. background-color: gray;
  1115. cursor: default;
  1116. }
  1117. .tool-button-disabled:hover {
  1118. color: lightgray;
  1119. background-color: gray;
  1120. cursor: default;
  1121. }
  1122. .space {
  1123. width: 10px;
  1124. display: inline-block;
  1125. }
  1126. .clear {
  1127. color: rgba(0,0,0,0);
  1128. }
  1129. .clickable {
  1130. color: blue;
  1131. text-decoration: underline;
  1132. cursor: pointer;
  1133. }
  1134. .copy-icon {
  1135. cursor: pointer;
  1136. font-size: 120%;
  1137. color: blue;
  1138. }
  1139. </style>