123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227 |
- <template>
- <q-page class="column no-wrap">
- <div class="header" v-show="toolBarActive">
- <div ref="buttons" class="row justify-between no-wrap">
- <button ref="loader" class="tool-button" :class="buttonActiveClass('loader')" @click="buttonClick('loader')" v-ripple>
- <q-icon name="o_arrow_back" size="30px"/>
- <q-tooltip :delay="1000" anchor="bottom right" content-style="font-size: 80%">Загрузить книгу</q-tooltip>
- </button>
- <div>
- <button ref="undoAction" v-show="showToolButton['undoAction']" class="tool-button" :class="buttonActiveClass('undoAction')" @click="buttonClick('undoAction')" v-ripple>
- <q-icon name="o_arrow_back_ios" size="25px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Действие назад</q-tooltip>
- </button>
- <button ref="redoAction" v-show="showToolButton['redoAction']" class="tool-button" :class="buttonActiveClass('redoAction')" @click="buttonClick('redoAction')" v-ripple>
- <q-icon name="o_arrow_forward_ios" size="25px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Действие вперед</q-tooltip>
- </button>
- <div class="space"></div>
- <button ref="fullScreen" v-show="showToolButton['fullScreen']" class="tool-button" :class="buttonActiveClass('fullScreen')" @click="buttonClick('fullScreen')" v-ripple>
- <q-icon :name="(fullScreenActive ? 'o_fullscreen_exit': 'o_fullscreen')" size="38px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">На весь экран</q-tooltip>
- </button>
- <button ref="scrolling" v-show="showToolButton['scrolling']" class="tool-button" :class="buttonActiveClass('scrolling')" @click="buttonClick('scrolling')" v-ripple>
- <q-icon name="o_swap_vert" size="34px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Плавный скроллинг</q-tooltip>
- </button>
- <button ref="setPosition" v-show="showToolButton['setPosition']" class="tool-button" :class="buttonActiveClass('setPosition')" @click="buttonClick('setPosition')" v-ripple>
- <q-icon name="o_fast_forward" size="34px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">На страницу</q-tooltip>
- </button>
- <button ref="search" v-show="showToolButton['search']" class="tool-button" :class="buttonActiveClass('search')" @click="buttonClick('search')" v-ripple>
- <q-icon name="o_search" size="34px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Найти в тексте</q-tooltip>
- </button>
- <button ref="copyText" v-show="showToolButton['copyText']" class="tool-button" :class="buttonActiveClass('copyText')" @click="buttonClick('copyText')" v-ripple>
- <q-icon name="o_open_in_new" size="34px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Скопировать текст со страницы</q-tooltip>
- </button>
- <button ref="refresh" v-show="showToolButton['refresh']" class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')" v-ripple>
- <q-icon name="o_sync" size="34px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Принудительно обновить книгу в обход кэша</q-tooltip>
- </button>
- <div class="space"></div>
- <button ref="offlineMode" v-show="showToolButton['offlineMode']" class="tool-button" :class="buttonActiveClass('offlineMode')" @click="buttonClick('offlineMode')" v-ripple>
- <q-icon name="o_link_off" size="32px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Автономный режим (без интернета)</q-tooltip>
- </button>
- <button ref="recentBooks" v-show="showToolButton['recentBooks']" class="tool-button" :class="buttonActiveClass('recentBooks')" @click="buttonClick('recentBooks')" v-ripple>
- <q-icon name="o_library_books" size="32px"/>
- <q-tooltip :delay="1000" anchor="bottom middle" content-style="font-size: 80%">Открыть недавние</q-tooltip>
- </button>
- </div>
- <button ref="settings" class="tool-button" :class="buttonActiveClass('settings')" @click="buttonClick('settings')" v-ripple>
- <q-icon name="o_settings" size="30px"/>
- <q-tooltip :delay="1000" anchor="bottom left" content-style="font-size: 80%">Настроить</q-tooltip>
- </button>
- </div>
- </div>
- <div class="main col row relative-position">
- <keep-alive>
- <component ref="page" class="col" :is="activePage"
- @load-book="loadBook"
- @load-file="loadFile"
- @book-pos-changed="bookPosChanged"
- @tool-bar-toggle="toolBarToggle"
- @full-screen-toogle="fullScreenToggle"
- @stop-scrolling="stopScrolling"
- @scrolling-toggle="scrollingToggle"
- @help-toggle="helpToggle"
- @donate-toggle="donateToggle"
- ></component>
- </keep-alive>
- <SetPositionPage v-if="setPositionActive" ref="setPositionPage" @set-position-toggle="setPositionToggle" @book-pos-changed="bookPosChanged"></SetPositionPage>
- <SearchPage v-show="searchActive" ref="searchPage"
- @search-toggle="searchToggle"
- @book-pos-changed="bookPosChanged"
- @start-text-search="startTextSearch"
- @stop-text-search="stopTextSearch">
- </SearchPage>
- <CopyTextPage v-if="copyTextActive" ref="copyTextPage" @copy-text-toggle="copyTextToggle"></CopyTextPage>
- <RecentBooksPage v-show="recentBooksActive" ref="recentBooksPage" @load-book="loadBook" @recent-books-toggle="recentBooksToggle"></RecentBooksPage>
- <SettingsPage v-if="settingsActive" ref="settingsPage" @settings-toggle="settingsToggle"></SettingsPage>
- <HelpPage v-if="helpActive" ref="helpPage" @help-toggle="helpToggle"></HelpPage>
- <ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
- <ServerStorage v-show="hidden" ref="serverStorage"></ServerStorage>
- <el-dialog
- title="Что нового:"
- :visible.sync="whatsNewVisible"
- width="80%">
- <div style="line-height: 20px" v-html="whatsNewContent"></div>
- <span class="clickable" @click="openVersionHistory">Посмотреть историю версий</span>
- <span slot="footer" class="dialog-footer">
- <el-button @click="whatsNewDisable">Больше не показывать</el-button>
- </span>
- </el-dialog>
- <el-dialog
- title="Здравствуйте, уважаемые читатели!"
- :visible.sync="donationVisible"
- width="90%">
- <div style="word-break: normal">
- Стартовала ежегодная акция "Оплатим хостинг вместе".<br><br>
- Для оплаты годового хостинга читалки, необходимо собрать около 2000 рублей.
- В настоящий момент у автора эта сумма есть в наличии. Однако будет справедливо, если каждый
- сможет проголосовать рублем за то, чтобы читалка так и оставалась:
- <ul>
- <li>непрерывно улучшаемой</li>
- <li>без рекламы</li>
- <li>без регистрации</li>
- <li>Open Source</li>
- </ul>
- Автор также обращается с просьбой о помощи в распространении
- <a href="https://omnireader.ru" target="_blank">ссылки</a>
- <el-tooltip :open-delay="500" effect="light">
- <template slot="content">
- Скопировать
- </template>
- <i class="el-icon-copy-document" style="cursor: pointer; font-size: 100%" @click="copyLink('https://omnireader.ru')"></i>
- </el-tooltip>
- на читалку через тематические форумы, соцсети, мессенджеры и пр.
- Чем нас больше, тем легче оставаться на плаву и тем больше мотивации у разработчика, чтобы продолжать работать над проектом.
- <br><br>
- Если соберется бóльшая сумма, то разработка децентрализованной библиотеки для свободного обмена книгами будет по возможности ускорена.
- <br><br>
- P.S. При необходимости можно воспользоваться подходящим обменником на <a href="https://www.bestchange.ru" target="_blank">bestchange.ru</a>
- <br><br>
- <el-row type="flex" justify="center">
- <el-button type="success" round @click="openDonate">Помочь проекту</el-button>
- </el-row>
- </div>
- <span slot="footer" class="dialog-footer">
- <span class="clickable" style="font-size: 60%; color: grey" @click="donationDialogDisable">Больше не показывать</span>
- <br><br>
- <el-button @click="donationDialogRemind">Напомнить позже</el-button>
- </span>
- </el-dialog>
- </div>
- </q-page>
- </template>
- <script>
- //-----------------------------------------------------------------------------
- import Vue from 'vue';
- import Component from 'vue-class-component';
- import _ from 'lodash';
- import {Buffer} from 'safe-buffer';
- import LoaderPage from './LoaderPage/LoaderPage.vue';
- import TextPage from './TextPage/TextPage.vue';
- import ProgressPage from './ProgressPage/ProgressPage.vue';
- import SetPositionPage from './SetPositionPage/SetPositionPage.vue';
- import SearchPage from './SearchPage/SearchPage.vue';
- import CopyTextPage from './CopyTextPage/CopyTextPage.vue';
- import RecentBooksPage from './RecentBooksPage/RecentBooksPage.vue';
- import SettingsPage from './SettingsPage/SettingsPage.vue';
- import HelpPage from './HelpPage/HelpPage.vue';
- import ClickMapPage from './ClickMapPage/ClickMapPage.vue';
- import ServerStorage from './ServerStorage/ServerStorage.vue';
- import bookManager from './share/bookManager';
- import readerApi from '../../api/reader';
- import * as utils from '../../share/utils';
- import {versionHistory} from './versionHistory';
- export default @Component({
- components: {
- LoaderPage,
- TextPage,
- ProgressPage,
- SetPositionPage,
- SearchPage,
- CopyTextPage,
- RecentBooksPage,
- SettingsPage,
- HelpPage,
- ClickMapPage,
- ServerStorage,
- },
- watch: {
- bookPos: function(newValue) {
- if (newValue !== undefined && this.activePage == 'TextPage') {
- const textPage = this.$refs.page;
- if (textPage.bookPos != newValue) {
- textPage.bookPos = newValue;
- }
- if (!this.scrollingActive)
- this.debouncedSetRecentBook(newValue);
- else
- this.scrollingSetRecentBook(newValue);
- }
- },
- routeParamPos: function(newValue) {
- if (!this.paramPosIgnore && newValue !== undefined && newValue != this.bookPos) {
- this.bookPos = newValue;
- }
- },
- routeParamUrl: function(newValue) {
- if (newValue !== '' && newValue !== this.mostRecentBook().url) {
- this.loadBook({url: newValue, bookPos: this.routeParamPos});
- }
- },
- settings: function() {
- this.loadSettings();
- this.updateRoute();
- },
- loaderActive: function(newValue) {
- (async() => {
- const recent = this.mostRecentBook();
- if (!newValue && !this.loading && recent && !await bookManager.hasBookParsed(recent)) {
- this.loadBook(recent);
- }
- })();
- },
- },
- })
- class Reader extends Vue {
- loaderActive = false;
- progressActive = false;
- fullScreenActive = false;
- scrollingActive = false;
- setPositionActive = false;
- searchActive = false;
- copyTextActive = false;
- recentBooksActive = false;
- offlineModeActive = false;
- settingsActive = false;
- helpActive = false;
- clickMapActive = false;
- bookPos = null;
- allowUrlParamBookPos = false;
- showRefreshIcon = true;
- mostRecentBookReactive = null;
- showToolButton = {};
- actionList = [];
- actionCur = -1;
- hidden = false;
- whatsNewVisible = false;
- whatsNewContent = '';
- donationVisible = false;
- created() {
- this.loading = true;
- this.commit = this.$store.commit;
- this.dispatch = this.$store.dispatch;
- this.reader = this.$store.state.reader;
- this.config = this.$store.state.config;
- this.$root.addKeyHook(this.keyHook);
- this.lastActivePage = false;
- this.debouncedSetRecentBook = _.debounce(async(newValue) => {
- const recent = this.mostRecentBook();
- if (recent && (recent.bookPos != newValue || recent.bookPosSeen !== this.bookPosSeen)) {
- await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
- if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
- this.addAction(newValue);
- this.paramPosIgnore = true;
- this.updateRoute();
- await this.$nextTick();
- this.paramPosIgnore = false;
- }
- }, 500, {'maxWait':5000});
- this.scrollingSetRecentBook = _.debounce((newValue) => {
- this.debouncedSetRecentBook(newValue);
- }, 15000, {'maxWait':20000});
- document.addEventListener('fullscreenchange', () => {
- this.fullScreenActive = (document.fullscreenElement !== null);
- });
- this.loadSettings();
- }
- mounted() {
- this.updateHeaderMinWidth();
- (async() => {
- await bookManager.init(this.settings);
- bookManager.addEventListener(this.bookManagerEvent);
-
- if (this.$root.rootRoute == '/reader') {
- if (this.routeParamUrl) {
- await this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos, force: this.routeParamRefresh});
- } else {
- this.loaderActive = true;
- }
- }
- await this.$refs.serverStorage.init();
- this.checkSetStorageAccessKey();
- this.checkActivateDonateHelpPage();
- this.loading = false;
- this.updateRoute();
- await this.showWhatsNew();
- await this.showDonation();
- })();
- }
- loadSettings() {
- const settings = this.settings;
- this.allowUrlParamBookPos = settings.allowUrlParamBookPos;
- this.copyFullText = settings.copyFullText;
- this.showClickMapPage = settings.showClickMapPage;
- this.clickControl = settings.clickControl;
- this.blinkCachedLoad = settings.blinkCachedLoad;
- this.showWhatsNewDialog = settings.showWhatsNewDialog;
- this.showDonationDialog2020 = settings.showDonationDialog2020;
- this.showToolButton = settings.showToolButton;
- this.enableSitesFilter = settings.enableSitesFilter;
- this.updateHeaderMinWidth();
- }
- updateHeaderMinWidth() {
- const showButtonCount = Object.values(this.showToolButton).reduce((a, b) => a + (b ? 1 : 0), 0);
- if (this.$refs.buttons)
- this.$refs.buttons.style.minWidth = 65*showButtonCount + 'px';
- }
- checkSetStorageAccessKey() {
- const q = this.$route.query;
- if (q['setStorageAccessKey']) {
- this.$router.replace(`/reader`);
- this.settingsToggle();
- this.$nextTick(() => {
- this.$refs.settingsPage.enterServerStorageKey(
- Buffer.from(utils.fromBase58(q['setStorageAccessKey'])).toString()
- );
- });
- }
- }
- checkActivateDonateHelpPage() {
- const q = this.$route.query;
- if (q['donate']) {
- this.$router.replace(`/reader`);
- this.helpToggle();
- this.$nextTick(() => {
- this.$refs.helpPage.activateDonateHelpPage();
- });
- }
- }
- checkBookPosPercent() {
- const q = this.$route.query;
- if (q['__pp']) {
- let pp = q['__pp'];
- if (pp) {
- pp = parseFloat(pp) || 0;
- const recent = this.mostRecentBook();
- (async() => {
- await utils.sleep(100);
- this.bookPos = Math.floor(recent.textLength*pp/100);
- })();
- }
- }
- }
- async showWhatsNew() {
- await utils.sleep(2000);
- const whatsNew = versionHistory[0];
- if (this.showWhatsNewDialog &&
- whatsNew.showUntil >= utils.formatDate(new Date(), 'coDate') &&
- whatsNew.header != this.whatsNewContentHash) {
- this.whatsNewContent = 'Версия ' + whatsNew.header + whatsNew.content;
- this.whatsNewVisible = true;
- }
- }
- async showDonation() {
- await utils.sleep(3000);
- const today = utils.formatDate(new Date(), 'coDate');
- if (this.mode == 'omnireader' && today < '2020-03-01' && this.showDonationDialog2020 && this.donationRemindDate != today) {
- this.donationVisible = true;
- }
- }
- donationDialogDisable() {
- this.donationVisible = false;
- if (this.showDonationDialog2020) {
- const newSettings = Object.assign({}, this.settings, { showDonationDialog2020: false });
- this.commit('reader/setSettings', newSettings);
- }
- }
- donationDialogRemind() {
- this.donationVisible = false;
- this.commit('reader/setDonationRemindDate', utils.formatDate(new Date(), 'coDate'));
- }
- openDonate() {
- this.donationVisible = false;
- this.donateToggle();
- }
- async copyLink(link) {
- const result = await utils.copyTextToClipboard(link);
- if (result)
- this.$notify.success({message: `Ссылка ${link} успешно скопирована в буфер обмена`});
- else
- this.$notify.error({message: 'Копирование не удалось'});
- }
- openVersionHistory() {
- this.whatsNewVisible = false;
- this.versionHistoryToggle();
- }
- whatsNewDisable() {
- this.whatsNewVisible = false;
- const whatsNew = versionHistory[0];
- this.commit('reader/setWhatsNewContentHash', whatsNew.header);
- }
- get routeParamPos() {
- let result = undefined;
- const q = this.$route.query;
- if (q['__p']) {
- result = q['__p'];
- if (Array.isArray(result))
- result = result[0];
- }
-
- return (result ? parseInt(result, 10) || 0 : result);
- }
- updateRoute(isNewRoute) {
- if (this.loading)
- return;
- const recent = this.mostRecentBook();
- const pos = (recent && recent.bookPos && this.allowUrlParamBookPos ? `__p=${recent.bookPos}&` : '');
- const url = (recent ? `url=${recent.url}` : '');
- if (isNewRoute)
- this.$router.push(`/reader?${pos}${url}`).catch(() => {});
- else
- this.$router.replace(`/reader?${pos}${url}`).catch(() => {});
- }
- get mode() {
- return this.$store.state.config.mode;
- }
- get routeParamUrl() {
- let result = '';
- const path = this.$route.fullPath;
- const i = path.indexOf('url=');
- if (i >= 0) {
- result = path.substr(i + 4);
- }
-
- return decodeURIComponent(result);
- }
- get routeParamRefresh() {
- const q = this.$route.query;
- return !!q['__refresh'];
- }
- bookPosChanged(event) {
- if (event.bookPosSeen !== undefined)
- this.bookPosSeen = event.bookPosSeen;
- this.bookPos = event.bookPos;
- }
- async bookManagerEvent(eventName, value) {
- if (eventName == 'set-recent' || eventName == 'recent-deleted') {
- const oldBook = (this.textPage ? this.textPage.lastBook : null);
- const oldPos = (this.textPage ? this.textPage.bookPos : null);
- const newBook = bookManager.mostRecentBook();
- if (!(oldBook && newBook && oldBook.key == newBook.key)) {
- this.mostRecentBook();
- }
- if (oldBook && newBook) {
- if (oldBook.key != newBook.key || oldBook.path != newBook.path) {
- this.loadingBook = true;
- try {
- await this.loadBook(newBook);
- } finally {
- this.loadingBook = false;
- }
- } else if (oldPos != newBook.bookPos) {
- while (this.loadingBook) await utils.sleep(100);
- this.bookPosChanged({bookPos: newBook.bookPos});
- }
- }
- }
- if (eventName == 'recent-changed') {
- if (this.recentBooksActive) {
- await this.$refs.recentBooksPage.updateTableData();
- }
- //сохранение в serverStorage
- if (value) {
- await utils.sleep(500);
- await this.$refs.serverStorage.saveRecent(value);
- }
- }
- }
- get toolBarActive() {
- return this.reader.toolBarActive;
- }
- mostRecentBook() {
- const result = bookManager.mostRecentBook();
- this.mostRecentBookReactive = result;
- return result;
- }
- get settings() {
- return this.$store.state.reader.settings;
- }
- get whatsNewContentHash() {
- return this.$store.state.reader.whatsNewContentHash;
- }
- get donationRemindDate() {
- return this.$store.state.reader.donationRemindDate;
- }
- addAction(pos) {
- let a = this.actionList;
- if (!a.length || a[a.length - 1] != pos) {
- a.push(pos);
- if (a.length > 20)
- a.shift();
- this.actionCur = a.length - 1;
- }
- }
- toolBarToggle() {
- this.commit('reader/setToolBarActive', !this.toolBarActive);
- this.$root.$emit('resize');
- }
- fullScreenToggle() {
- this.fullScreenActive = !this.fullScreenActive;
- if (this.fullScreenActive) {
- this.$q.fullscreen.request();
- } else {
- this.$q.fullscreen.exit();
- }
- }
- closeAllTextPages() {
- this.setPositionActive = false;
- this.copyTextActive = false;
- this.recentBooksActive = false;
- this.settingsActive = false;
- this.stopScrolling();
- this.stopSearch();
- this.helpActive = false;
- }
- loaderToggle() {
- this.loaderActive = !this.loaderActive;
- if (this.loaderActive) {
- this.closeAllTextPages();
- }
- }
- setPositionToggle() {
- this.setPositionActive = !this.setPositionActive;
- if (this.setPositionActive && this.activePage == 'TextPage' && this.mostRecentBook()) {
- this.closeAllTextPages();
- this.setPositionActive = true;
- this.$nextTick(() => {
- const recent = this.mostRecentBook();
- this.$refs.setPositionPage.init(recent.bookPos, recent.textLength - 1);
- });
- } else {
- this.setPositionActive = false;
- }
- }
- stopScrolling() {
- if (this.scrollingActive)
- this.scrollingToggle();
- }
- scrollingToggle() {
- this.scrollingActive = !this.scrollingActive;
- if (this.activePage == 'TextPage') {
- const page = this.$refs.page;
- if (this.scrollingActive) {
- page.startTextScrolling();
- } else {
- page.stopTextScrolling();
- }
- }
- if (!this.scrollingActive) {
- this.scrollingSetRecentBook.flush();
- }
- }
- stopSearch() {
- if (this.searchActive)
- this.searchToggle();
- }
- startTextSearch(opts) {
- if (this.activePage == 'TextPage')
- this.$refs.page.startSearch(opts.needle);
- }
- stopTextSearch() {
- if (this.activePage == 'TextPage')
- this.$refs.page.stopSearch();
- }
- searchToggle() {
- this.searchActive = !this.searchActive;
- const page = this.$refs.page;
- if (this.searchActive && this.activePage == 'TextPage' && page.parsed) {
- this.closeAllTextPages();
- this.searchActive = true;
- this.$nextTick(() => {
- this.$refs.searchPage.init(page.parsed);
- });
- } else {
- this.stopTextSearch();
- this.searchActive = false;
- }
- }
- copyTextToggle() {
- this.copyTextActive = !this.copyTextActive;
- const page = this.$refs.page;
- if (this.copyTextActive && this.activePage == 'TextPage' && page.parsed) {
- this.closeAllTextPages();
- this.copyTextActive = true;
- this.$nextTick(() => {
- this.$refs.copyTextPage.init(this.mostRecentBook().bookPos, page.parsed, this.copyFullText);
- });
- } else {
- this.copyTextActive = false;
- }
- }
- recentBooksToggle() {
- this.recentBooksActive = !this.recentBooksActive;
- if (this.recentBooksActive) {
- this.closeAllTextPages();
- this.$refs.recentBooksPage.init();
- this.recentBooksActive = true;
- } else {
- this.recentBooksActive = false;
- }
- }
- offlineModeToggle() {
- this.offlineModeActive = !this.offlineModeActive;
- this.$refs.serverStorage.offlineModeActive = this.offlineModeActive;
- }
- settingsToggle() {
- this.settingsActive = !this.settingsActive;
- if (this.settingsActive) {
- this.closeAllTextPages();
- this.settingsActive = true;
- this.$nextTick(() => {
- this.$refs.settingsPage.init();
- });
- } else {
- this.settingsActive = false;
- }
- }
- helpToggle() {
- this.helpActive = !this.helpActive;
- if (this.helpActive) {
- this.closeAllTextPages();
- this.helpActive = true;
- }
- }
- donateToggle() {
- this.helpToggle();
- if (this.helpActive) {
- this.$nextTick(() => {
- this.$refs.helpPage.activateDonateHelpPage();
- });
- }
- }
- versionHistoryToggle() {
- this.helpToggle();
- if (this.helpActive) {
- this.$nextTick(() => {
- this.$refs.helpPage.activateVersionHistoryHelpPage();
- });
- }
- }
- refreshBook() {
- if (this.mostRecentBook()) {
- this.loadBook({url: this.mostRecentBook().url, force: true});
- }
- }
- buttonClick(button) {
- const activeClass = this.buttonActiveClass(button);
- this.$refs[button].blur();
- if (activeClass['tool-button-disabled'])
- return;
-
- switch (button) {
- case 'loader':
- this.loaderToggle();
- break;
- case 'undoAction':
- if (this.actionCur > 0) {
- this.actionCur--;
- this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
- }
- break;
- case 'redoAction':
- if (this.actionCur < this.actionList.length - 1) {
- this.actionCur++;
- this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
- }
- break;
- case 'fullScreen':
- this.fullScreenToggle();
- break;
- case 'setPosition':
- this.setPositionToggle();
- break;
- case 'scrolling':
- this.scrollingToggle();
- break;
- case 'search':
- this.searchToggle();
- break;
- case 'copyText':
- this.copyTextToggle();
- break;
- case 'refresh':
- this.refreshBook();
- break;
- case 'recentBooks':
- this.recentBooksToggle();
- break;
- case 'offlineMode':
- this.offlineModeToggle();
- break;
- case 'settings':
- this.settingsToggle();
- break;
- }
- }
- buttonActiveClass(button) {
- const classActive = { 'tool-button-active': true, 'tool-button-active:hover': true };
- const classDisabled = { 'tool-button-disabled': true, 'tool-button-disabled:hover': true };
- let classResult = {};
- switch (button) {
- case 'loader':
- case 'fullScreen':
- case 'setPosition':
- case 'scrolling':
- case 'search':
- case 'copyText':
- case 'refresh':
- case 'offlineMode':
- case 'recentBooks':
- case 'settings':
- if (this.progressActive) {
- classResult = classDisabled;
- } else if (this[`${button}Active`]) {
- classResult = classActive;
- }
- break;
- case 'undoAction':
- if (this.actionCur <= 0)
- classResult = classDisabled;
- break;
- case 'redoAction':
- if (this.actionCur == this.actionList.length - 1)
- classResult = classDisabled;
- break;
- }
- if (this.activePage == 'LoaderPage' || !this.mostRecentBookReactive) {
- switch (button) {
- case 'undoAction':
- case 'redoAction':
- case 'setPosition':
- case 'scrolling':
- case 'search':
- case 'copyText':
- classResult = classDisabled;
- break;
- case 'recentBooks':
- case 'refresh':
- if (!this.mostRecentBookReactive)
- classResult = classDisabled;
- break;
- }
- }
- return classResult;
- }
- async activateClickMapPage() {
- if (this.clickControl && this.showClickMapPage && !this.clickMapActive) {
- this.clickMapActive = true;
- await this.$refs.clickMapPage.slowDisappear();
- this.clickMapActive = false;
- }
- }
- get activePage() {
- let result = '';
- if (this.progressActive)
- result = 'ProgressPage';
- else if (this.loaderActive)
- result = 'LoaderPage';
- else if (this.mostRecentBookReactive)
- result = 'TextPage';
- if (!result && !this.loading) {
- this.loaderActive = true;
- result = 'LoaderPage';
- }
- if (result != 'TextPage') {
- this.$root.$emit('set-app-title');
- }
- // на LoaderPage всегда показываем toolBar
- if (result == 'LoaderPage' && !this.toolBarActive) {
- this.toolBarToggle();
- }
- if (this.lastActivePage != result && result == 'TextPage') {
- //акивируем страницу с текстом
- this.$nextTick(async() => {
- const last = this.mostRecentBookReactive;
- const isParsed = await bookManager.hasBookParsed(last);
- if (!isParsed) {
- this.$root.$emit('set-app-title');
- return;
- }
- this.updateRoute();
- const textPage = this.$refs.page;
- if (textPage.showBook) {
- this.textPage = textPage;
- textPage.lastBook = last;
- textPage.bookPos = (last.bookPos !== undefined ? last.bookPos : 0);
- textPage.showBook();
- }
- });
- }
- this.lastActivePage = result;
- return result;
- }
- async loadBook(opts) {
- if (!opts || !opts.url) {
- this.mostRecentBook();
- return;
- }
- let url = encodeURI(decodeURI(opts.url));
- if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0) &&
- (url.indexOf('file://') != 0))
- url = 'http://' + url;
- // уже просматривается сейчас
- const lastBook = (this.textPage ? this.textPage.lastBook : null);
- if (!opts.force && lastBook && lastBook.url == url &&
- (!opts.path || opts.path == lastBook.path) &&
- await bookManager.hasBookParsed(lastBook)) {
- this.loaderActive = false;
- return;
- }
- this.progressActive = true;
- await this.$nextTick();
- const progress = this.$refs.page;
- this.actionList = [];
- this.actionCur = -1;
- try {
- progress.show();
- progress.setState({state: 'parse'});
- // есть ли среди недавних
- const key = bookManager.keyFromUrl(url);
- let wasOpened = await bookManager.getRecentBook({key});
- wasOpened = (wasOpened ? wasOpened : {});
- const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
- const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
- let book = null;
- if (!opts.force) {
- // пытаемся загрузить и распарсить книгу в менеджере из локального кэша
- const bookParsed = await bookManager.getBook({url, path: opts.path}, (prog) => {
- progress.setState({progress: prog});
- });
- // если есть в локальном кэше
- if (bookParsed) {
- await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookParsed));
- this.mostRecentBook();
- this.addAction(bookPos);
- this.loaderActive = false;
- progress.hide(); this.progressActive = false;
- this.blinkCachedLoadMessage();
- this.checkBookPosPercent();
- await this.activateClickMapPage();
- return;
- }
- // иначе идем на сервер
- // пытаемся загрузить готовый файл с сервера
- if (wasOpened.path) {
- progress.setState({totalSteps: 5});
- try {
- const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
- progress.setState(state);
- });
- book = Object.assign({}, wasOpened, {data: resp.data});
- } catch (e) {
- //молчим
- }
- }
- }
- progress.setState({totalSteps: 5});
- // не удалось, скачиваем книгу полностью с конвертацией
- let loadCached = true;
- if (!book) {
- book = await readerApi.loadBook({url, enableSitesFilter: this.enableSitesFilter}, (state) => {
- progress.setState(state);
- });
- loadCached = false;
- }
- // добавляем в bookManager
- progress.setState({state: 'parse', step: 5});
- const addedBook = await bookManager.addBook(book, (prog) => {
- progress.setState({progress: prog});
- });
- // добавляем в историю
- await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, addedBook));
- this.mostRecentBook();
- this.addAction(bookPos);
- this.updateRoute(true);
- this.loaderActive = false;
- progress.hide(); this.progressActive = false;
- if (loadCached) {
- this.blinkCachedLoadMessage();
- } else
- this.stopBlink = true;
- this.checkBookPosPercent();
- await this.activateClickMapPage();
- } catch (e) {
- progress.hide(); this.progressActive = false;
- this.loaderActive = true;
- this.$alert(e.message, 'Ошибка', {type: 'error'});
- }
- }
- async loadFile(opts) {
- this.progressActive = true;
- await this.$nextTick();
- const progress = this.$refs.page;
- try {
- progress.show();
- progress.setState({state: 'upload'});
- const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
- progress.setState(state);
- });
- progress.hide(); this.progressActive = false;
- await this.loadBook({url});
- } catch (e) {
- progress.hide(); this.progressActive = false;
- this.loaderActive = true;
- this.$alert(e.message, 'Ошибка', {type: 'error'});
- }
- }
- blinkCachedLoadMessage() {
- if (!this.blinkCachedLoad)
- return;
- this.blinkCount = 30;
- if (!this.inBlink) {
- this.inBlink = true;
- this.stopBlink = false;
- this.$nextTick(async() => {
- let page = this.$refs.page;
- while (this.blinkCount) {
- this.showRefreshIcon = !this.showRefreshIcon;
- if (page && page.blinkCachedLoadMessage)
- page.blinkCachedLoadMessage(this.showRefreshIcon);
- await utils.sleep(500);
- if (this.stopBlink)
- break;
- this.blinkCount--;
- page = this.$refs.page;
- }
- this.showRefreshIcon = true;
- this.inBlink = false;
- if (page && page.blinkCachedLoadMessage)
- page.blinkCachedLoadMessage('finish');
- });
- }
- }
- keyHook(event) {
- if (this.$root.rootRoute == '/reader') {
- let handled = false;
- if (!handled && this.helpActive)
- handled = this.$refs.helpPage.keyHook(event);
- if (!handled && this.settingsActive)
- handled = this.$refs.settingsPage.keyHook(event);
- if (!handled && this.recentBooksActive)
- handled = this.$refs.recentBooksPage.keyHook(event);
- if (!handled && this.setPositionActive)
- handled = this.$refs.setPositionPage.keyHook(event);
- if (!handled && this.searchActive)
- handled = this.$refs.searchPage.keyHook(event);
- if (!handled && this.copyTextActive)
- handled = this.$refs.copyTextPage.keyHook(event);
- if (!handled && this.$refs.page && this.$refs.page.keyHook)
- handled = this.$refs.page.keyHook(event);
- if (!handled && event.type == 'keydown') {
- if (event.code == 'Escape')
- this.loaderToggle();
- if (this.activePage == 'TextPage') {
- switch (event.code) {
- case 'KeyH':
- case 'F1':
- this.helpToggle();
- event.preventDefault();
- event.stopPropagation();
- break;
- case 'KeyZ':
- this.scrollingToggle();
- break;
- case 'KeyP':
- this.setPositionToggle();
- break;
- case 'KeyF':
- if (event.ctrlKey) {
- this.searchToggle();
- event.preventDefault();
- event.stopPropagation();
- }
- break;
- case 'KeyC':
- if (event.ctrlKey) {
- this.copyTextToggle();
- event.preventDefault();
- event.stopPropagation();
- }
- break;
- case 'KeyR':
- this.refreshBook();
- break;
- case 'KeyX':
- this.recentBooksToggle();
- event.preventDefault();
- event.stopPropagation();
- break;
- case 'KeyO':
- this.offlineModeToggle();
- break;
- case 'KeyS':
- this.settingsToggle();
- break;
- }
- }
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- </script>
- <style scoped>
- .header {
- padding-left: 5px;
- padding-right: 5px;
- background-color: #1B695F;
- color: #000;
- overflow-x: auto;
- overflow-y: hidden;
- height: 50px;
- }
- .main {
- background-color: #EBE2C9;
- color: #000;
- }
- .tool-button {
- margin: 0px 2px 0 2px;
- padding: 0;
- color: #3E843E;
- background-color: #E6EDF4;
- margin-top: 5px;
- height: 38px;
- width: 38px;
- border: 0;
- border-radius: 2px;
- box-shadow: 3px 3px 5px black;
- outline: 0;
- }
- .tool-button:hover {
- background-color: white;
- }
- .tool-button-active {
- box-shadow: 0 0 0;
- color: white;
- background-color: #8AB45F;
- position: relative;
- top: 1px;
- left: 1px;
- }
- .tool-button-active:hover {
- color: white;
- background-color: #81C581;
- }
- .tool-button-disabled {
- color: lightgray;
- background-color: gray;
- }
- .tool-button-disabled:hover {
- color: lightgray;
- background-color: gray;
- }
- .space {
- width: 10px;
- display: inline-block;
- }
- .clear {
- color: rgba(0,0,0,0);
- }
- .clickable {
- color: blue;
- text-decoration: underline;
- cursor: pointer;
- }
- </style>
|