ExternalLibs.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. <template>
  2. <Window ref="window" margin="2px" @close="close">
  3. <template #header>
  4. {{ header }}
  5. </template>
  6. <template #buttons>
  7. <span class="full-screen-button row justify-center items-center" @mousedown.stop @click="fullScreenToggle">
  8. <q-icon :name="(fullScreenActive ? 'la la-compress-arrows-alt': 'la la-expand-arrows-alt')" size="16px" />
  9. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">На весь экран</q-tooltip>
  10. </span>
  11. <span class="full-screen-button row justify-center items-center" @mousedown.stop @click="changeScale(0.1)">
  12. <q-icon name="la la-plus" size="16px" />
  13. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Увеличить масштаб</q-tooltip>
  14. </span>
  15. <span class="full-screen-button row justify-center items-center" @mousedown.stop @click="changeScale(-0.1)">
  16. <q-icon name="la la-minus" size="16px" />
  17. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Уменьшить масштаб</q-tooltip>
  18. </span>
  19. <span class="full-screen-button row justify-center items-center" @mousedown.stop @click="showHelp">
  20. <q-icon name="la la-question-circle" size="16px" />
  21. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Справка</q-tooltip>
  22. </span>
  23. </template>
  24. <div v-show="ready" class="col column" style="min-width: 600px">
  25. <div class="row items-center q-px-sm" style="height: 50px">
  26. <q-select
  27. ref="rootLink"
  28. v-model="rootLink"
  29. class="q-mr-sm"
  30. :options="rootLinkOptions"
  31. style="width: 230px"
  32. dropdown-icon="la la-angle-down la-sm"
  33. rounded outlined dense emit-value map-options display-value-sanitize options-sanitize
  34. @popup-show="onSelectPopupShow" @popup-hide="onSelectPopupHide"
  35. >
  36. <template #prepend>
  37. <q-btn class="q-mr-xs" round dense color="blue" icon="la la-plus" size="12px" @click.stop="addBookmark">
  38. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  39. Добавить закладку
  40. </q-tooltip>
  41. </q-btn>
  42. <q-btn round dense color="blue" icon="la la-bars" size="12px" @click.stop="bookmarkSettings">
  43. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  44. Настроить закладки
  45. </q-tooltip>
  46. </q-btn>
  47. </template>
  48. <template #selected>
  49. <div style="overflow: hidden; white-space: nowrap;">
  50. {{ rootLinkWithoutProtocol }}
  51. </div>
  52. </template>
  53. </q-select>
  54. <q-select
  55. ref="selectedLink"
  56. v-model="selectedLink"
  57. class="q-mr-sm"
  58. :options="selectedLinkOptions"
  59. style="width: 50px"
  60. dropdown-icon="la la-angle-down la-sm"
  61. rounded outlined dense emit-value map-options hide-selected display-value-sanitize options-sanitize
  62. @popup-show="onSelectPopupShow" @popup-hide="onSelectPopupHide"
  63. >
  64. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  65. Закладки
  66. </q-tooltip>
  67. </q-select>
  68. <q-input
  69. ref="input"
  70. v-model="bookUrl"
  71. class="col q-mr-sm"
  72. rounded outlined dense
  73. bg-color="white"
  74. placeholder="Скопируйте сюда URL книги"
  75. @focus="selectAllOnFocus" @keydown="bookUrlKeyDown"
  76. >
  77. <template #prepend>
  78. <q-btn class="q-mr-xs" round dense color="blue" icon="la la-home" size="12px" @click="goToLink(selectedLink)">
  79. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  80. Вернуться на стартовую страницу
  81. </q-tooltip>
  82. </q-btn>
  83. <q-btn :disabled="!bookUrl" round dense color="blue" icon="la la-angle-double-down" size="12px" @click="openBookUrlInFrame">
  84. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  85. Загрузить URL во фрейм
  86. </q-tooltip>
  87. </q-btn>
  88. </template>
  89. <template #append>
  90. <q-btn round dense color="blue" icon="la la-cog" size="12px" @click.stop="optionsVisible = true">
  91. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  92. Опции
  93. </q-tooltip>
  94. </q-btn>
  95. </template>
  96. </q-input>
  97. <q-btn :disabled="!bookUrl" rounded color="green-7" no-caps size="14px" @click="submitUrl">
  98. Открыть
  99. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  100. Открыть в читалке
  101. </q-tooltip>
  102. </q-btn>
  103. </div>
  104. <div class="separator"></div>
  105. <div ref="frameBox" class="col fit" style="position: relative;">
  106. <div ref="frameWrap" class="overflow-hidden">
  107. <iframe v-if="frameVisible" ref="frame" :src="frameSrc" frameborder="0"></iframe>
  108. </div>
  109. <div v-show="transparentLayoutVisible" ref="transparentLayout" class="fit transparent-layout" @click="transparentLayoutClick"></div>
  110. </div>
  111. <Dialog ref="dialogAddBookmark" v-model="addBookmarkVisible">
  112. <template #header>
  113. <div class="row items-center">
  114. <q-icon class="q-mr-sm" name="la la-bookmark" size="28px"></q-icon>
  115. <div v-if="addBookmarkMode == 'edit'">
  116. Редактировать закладку
  117. </div>
  118. <div v-else>
  119. Добавить закладку
  120. </div>
  121. </div>
  122. </template>
  123. <div class="q-mx-md row">
  124. <q-input
  125. ref="bookmarkLink"
  126. v-model="bookmarkLink"
  127. class="col q-mr-sm"
  128. outlined dense
  129. bg-color="white"
  130. placeholder="Ссылка для закладки" maxlength="2000" @focus="selectAllOnFocus" @keydown="bookmarkLinkKeyDown"
  131. >
  132. </q-input>
  133. <q-select
  134. ref="defaultRootLink"
  135. v-model="defaultRootLink"
  136. class="q-mr-sm"
  137. :options="defaultRootLinkOptions"
  138. style="width: 50px"
  139. dropdown-icon="la la-angle-down la-sm"
  140. outlined dense emit-value map-options hide-selected display-value-sanitize options-sanitize
  141. >
  142. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  143. Предустановленные ссылки
  144. </q-tooltip>
  145. </q-select>
  146. </div>
  147. <div class="q-mx-md q-mt-md">
  148. <q-input
  149. ref="bookmarkDesc"
  150. v-model="bookmarkDesc"
  151. class="col q-mr-sm"
  152. outlined dense
  153. bg-color="white"
  154. placeholder="Описание" style="width: 400px" maxlength="100" @focus="selectAllOnFocus" @keydown="bookmarkDescKeyDown"
  155. >
  156. </q-input>
  157. </div>
  158. <template #footer>
  159. <q-btn v-close-popup class="q-px-md q-ml-sm" dense no-caps>
  160. Отмена
  161. </q-btn>
  162. <q-btn :disabled="!bookmarkLink" class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okAddBookmark">
  163. OK
  164. </q-btn>
  165. </template>
  166. </Dialog>
  167. <Dialog ref="options" v-model="optionsVisible">
  168. <template #header>
  169. <div class="row items-center">
  170. <q-icon class="q-mr-sm" name="la la-cog" size="28px"></q-icon>
  171. Опции
  172. </div>
  173. </template>
  174. <div class="q-mx-md column">
  175. <q-checkbox v-model="closeAfterSubmit" size="36px" label="Закрыть окно при отправке ссылки в читалку" />
  176. <q-checkbox v-model="openInFrameOnEnter" size="36px" label="Открывать ссылку во фрейме при нажатии 'Enter'" />
  177. <q-checkbox v-model="openInFrameOnAdd" size="36px" label="Активировать новую закладку после добавления" />
  178. </div>
  179. <template #footer>
  180. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="optionsVisible = false">
  181. OK
  182. </q-btn>
  183. </template>
  184. </Dialog>
  185. </div>
  186. <BookmarkSettings
  187. v-if="bookmarkSettingsActive"
  188. ref="bookmarkSettings"
  189. :libs="libs"
  190. :add-bookmark-visible="addBookmarkVisible"
  191. @do-action="doAction" @close="closeBookmarkSettings"
  192. >
  193. </BookmarkSettings>
  194. </Window>
  195. </template>
  196. <script>
  197. //-----------------------------------------------------------------------------
  198. import vueComponent from '../vueComponent.js';
  199. import _ from 'lodash';
  200. import Window from '../share/Window.vue';
  201. import Dialog from '../share/Dialog.vue';
  202. import BookmarkSettings from './BookmarkSettings/BookmarkSettings.vue';
  203. import rstore from '../../store/modules/reader';
  204. import * as utils from '../../share/utils';
  205. import * as lu from './linkUtils';
  206. const proxySubst = {
  207. 'http://flibusta.is': 'http://b.liberama.top:23480',
  208. 'http://fantasy-worlds.org': 'http://b.liberama.top:23580',
  209. };
  210. const componentOptions = {
  211. components: {
  212. Window,
  213. Dialog,
  214. BookmarkSettings
  215. },
  216. watch: {
  217. libs() {
  218. this.loadLibs();
  219. },
  220. defaultRootLink() {
  221. this.updateBookmarkLink();
  222. },
  223. bookUrl(newValue) {
  224. const value = lu.addProtocol(newValue);
  225. const subst = this.makeProxySubst(value, true);
  226. if (value != subst) {
  227. this.$nextTick(() => {
  228. this.bookUrl = subst;
  229. });
  230. }
  231. },
  232. bookmarkLink(newValue) {
  233. const value = lu.addProtocol(newValue);
  234. const subst = this.makeProxySubst(value, true);
  235. if (value != subst) {
  236. this.$nextTick(() => {
  237. this.bookmarkLink = subst;
  238. });
  239. }
  240. },
  241. closeAfterSubmit(newValue) {
  242. this.commitProp('closeAfterSubmit', newValue);
  243. },
  244. openInFrameOnEnter(newValue) {
  245. this.commitProp('openInFrameOnEnter', newValue);
  246. },
  247. openInFrameOnAdd(newValue) {
  248. this.commitProp('openInFrameOnAdd', newValue);
  249. },
  250. rootLink() {
  251. this.rootLinkInput();
  252. },
  253. selectedLink() {
  254. this.selectedLinkInput();
  255. },
  256. }
  257. };
  258. class ExternalLibs {
  259. _options = componentOptions;
  260. ready = false;
  261. frameVisible = false;
  262. rootLink = '';
  263. selectedLink = '';
  264. frameSrc = '';
  265. bookUrl = '';
  266. libs = {};
  267. fullScreenActive = false;
  268. transparentLayoutVisible = false;
  269. addBookmarkVisible = false;
  270. optionsVisible = false;
  271. addBookmarkMode = '';
  272. bookmarkLink = '';
  273. bookmarkDesc = '';
  274. defaultRootLink = '';
  275. bookmarkSettingsActive = false;
  276. closeAfterSubmit = false;
  277. openInFrameOnEnter = false;
  278. openInFrameOnAdd = false;
  279. frameScale = 1;
  280. created() {
  281. this.oldStartLink = '';
  282. this.justOpened = true;
  283. this.$root.addEventHook('key', this.keyHook);
  284. this.$root.addEventHook('resize', async() => {
  285. await utils.sleep(200);
  286. this.frameResize();
  287. });
  288. document.addEventListener('fullscreenchange', () => {
  289. this.fullScreenActive = (document.fullscreenElement !== null);
  290. });
  291. this.debouncedGoToLink = _.debounce((link) => {
  292. this.goToLink(link);
  293. }, 100, {'maxWait':200});
  294. //this.commit = this.$store.commit;
  295. //this.commit('reader/setLibs', rstore.libsDefaults);
  296. }
  297. mounted() {
  298. (async() => {
  299. //подождем this.mode
  300. let i = 0;
  301. while(!this.mode && i < 100) {
  302. await utils.sleep(100);
  303. i++;
  304. }
  305. if (this.mode != 'liberama.top') {
  306. this.$router.replace('/404');
  307. return;
  308. }
  309. this.$refs.window.init();
  310. this.opener = null;
  311. const host = window.location.host;
  312. const openerHost = (host.indexOf('b.') == 0 ? host.substring(2) : host);
  313. const openerOrigin1 = `http://${openerHost}`;
  314. const openerOrigin2 = `https://${openerHost}`;
  315. window.addEventListener('message', (event) => {
  316. if (event.origin !== openerOrigin1 && event.origin !== openerOrigin2)
  317. return;
  318. if (!_.isObject(event.data) || event.data.from != 'LibsPage')
  319. return;
  320. if (event.origin == openerOrigin1)
  321. this.opener = window.opener;
  322. else
  323. this.opener = event.source;
  324. this.openerOrigin = event.origin;
  325. //console.log(event);
  326. this.recvMessage(event.data);
  327. });
  328. //Ожидаем родителя
  329. i = 0;
  330. while(!this.opener) {
  331. await utils.sleep(1000);
  332. i++;
  333. if (i >= 5) {
  334. await this.$root.stdDialog.alert('Нет связи с читалкой. Окно будет закрыто', 'Ошибка');
  335. window.close();
  336. }
  337. }
  338. //Проверка закрытия родительского окна
  339. while(this.opener) {
  340. await this.checkOpener();
  341. await utils.sleep(1000);
  342. }
  343. })();
  344. }
  345. recvMessage(d) {
  346. if (d.type == 'mes') {
  347. switch(d.data) {
  348. case 'hello': this.sendMessage({type: 'mes', data: 'ready'}); break;
  349. }
  350. } else if (d.type == 'libs') {
  351. this.ready = true;
  352. this.libs = _.cloneDeep(d.data);
  353. } else if (d.type == 'notify') {
  354. this.$root.notify.success(d.data, '', {position: 'bottom-right'});
  355. }
  356. }
  357. sendMessage(d) {
  358. (async() => {
  359. await this.checkOpener();
  360. if (this.opener && this.openerOrigin)
  361. this.opener.postMessage(Object.assign({}, {from: 'ExternalLibs'}, d), this.openerOrigin);
  362. })();
  363. }
  364. async checkOpener() {
  365. if (this.opener.closed) {
  366. await this.$root.stdDialog.alert('Потеряна связь с читалкой. Окно будет закрыто', 'Ошибка');
  367. window.close();
  368. }
  369. }
  370. commitLibs(libs) {
  371. this.sendMessage({type: 'libs', data: libs});
  372. }
  373. commitProp(prop, value) {
  374. let libs = _.cloneDeep(this.libs);
  375. libs[prop] = value;
  376. this.commitLibs(libs);
  377. }
  378. loadLibs() {
  379. const libs = this.libs;
  380. if (!libs.helpShowed) {
  381. this.showHelp();
  382. (async() => {
  383. await utils.sleep(1000);
  384. this.commitProp('helpShowed', true);
  385. })();
  386. }
  387. this.selectedLink = libs.startLink;
  388. this.closeAfterSubmit = libs.closeAfterSubmit || false;
  389. this.openInFrameOnEnter = libs.openInFrameOnEnter || false;
  390. this.openInFrameOnAdd = libs.openInFrameOnAdd || false;
  391. this.frameScale = 1;
  392. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.selectedLink);
  393. if (index >= 0)
  394. this.frameScale = this.libs.groups[index].frameScale || 1;
  395. this.updateStartLink();
  396. }
  397. doAction(event) {
  398. switch (event.action) {
  399. case 'setLibs': this.commitLibs(event.data); break;
  400. case 'setRootLink': this.rootLink = event.data; this.rootLinkInput(); break;
  401. case 'setSelectedLink': this.selectedLink = event.data; this.selectedLinkInput(); break;
  402. case 'editBookmark': this.addBookmark('edit', event.data.link, event.data.desc); break;
  403. case 'addBookmark': this.addBookmark('add'); break;
  404. }
  405. }
  406. get mode() {
  407. return this.$store.state.config.mode;
  408. }
  409. get header() {
  410. let result = (this.ready ? 'Сетевая библиотека' : 'Загрузка...');
  411. if (this.ready && this.selectedLink) {
  412. result += ` | ${(this.libs.comment ? this.libs.comment + ' ': '') + lu.removeProtocol(this.libs.startLink)}`;
  413. }
  414. this.$root.setAppTitle(result);
  415. return result;
  416. }
  417. get rootLinkWithoutProtocol() {
  418. return lu.removeProtocol(this.rootLink);
  419. }
  420. updateSelectedLinkByRoot() {
  421. if (!this.ready)
  422. return;
  423. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.rootLink);
  424. if (index >= 0)
  425. this.selectedLink = this.libs.groups[index].s;
  426. else
  427. this.selectedLink = '';
  428. }
  429. updateStartLink(force) {
  430. if (!this.ready)
  431. return;
  432. let index = -1;
  433. try {
  434. this.rootLink = lu.getOrigin(this.selectedLink);
  435. index = lu.getRootIndexByUrl(this.libs.groups, this.rootLink);
  436. } catch(e) {
  437. //
  438. }
  439. if (index >= 0) {
  440. let libs = _.cloneDeep(this.libs);
  441. const com = this.getCommentByLink(libs.groups[index].list, this.selectedLink);
  442. if (libs.groups[index].s != this.selectedLink ||
  443. libs.startLink != this.selectedLink ||
  444. libs.comment != com) {
  445. libs.groups[index].s = this.selectedLink;
  446. libs.startLink = this.selectedLink;
  447. libs.comment = com;
  448. this.commitLibs(libs);
  449. }
  450. if (force || this.oldStartLink != libs.startLink) {
  451. this.oldStartLink = libs.startLink;
  452. this.debouncedGoToLink(this.selectedLink);
  453. }
  454. } else {
  455. this.rootLink = '';
  456. this.selectedLink = '';
  457. this.debouncedGoToLink(this.selectedLink);
  458. }
  459. }
  460. get rootLinkOptions() {
  461. let result = [];
  462. if (!this.ready)
  463. return result;
  464. this.libs.groups.forEach(group => {
  465. result.push({label: lu.removeProtocol(group.r), value: group.r});
  466. });
  467. return result;
  468. }
  469. get defaultRootLinkOptions() {
  470. let result = [];
  471. rstore.libsDefaults.groups.forEach(group => {
  472. result.push({label: lu.removeProtocol(group.r), value: group.r});
  473. });
  474. return result;
  475. }
  476. get selectedLinkOptions() {
  477. let result = [];
  478. if (!this.ready)
  479. return result;
  480. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.rootLink);
  481. if (index >= 0) {
  482. this.libs.groups[index].list.forEach(link => {
  483. result.push({label: (link.c ? link.c + ' ': '') + lu.removeOrigin(link.l), value: link.l});
  484. });
  485. }
  486. return result;
  487. }
  488. openBookUrlInFrame() {
  489. if (this.bookUrl) {
  490. this.goToLink(lu.addProtocol(this.bookUrl));
  491. }
  492. }
  493. goToLink(link) {
  494. if (!this.ready || !link)
  495. return;
  496. if (!link) {
  497. this.frameVisible = false;
  498. return;
  499. }
  500. this.frameSrc = this.makeProxySubst(link);
  501. this.frameVisible = false;
  502. this.$nextTick(() => {
  503. this.frameVisible = true;
  504. this.$nextTick(() => {
  505. if (this.$refs.frame) {
  506. this.$refs.frame.contentWindow.focus();
  507. this.frameResize();
  508. }
  509. });
  510. });
  511. }
  512. frameResize() {
  513. this.$refs.frameWrap.style = 'width: 1px; height: 1px;';
  514. this.$nextTick(() => {
  515. if (this.$refs.frame) {
  516. const w = this.$refs.frameBox.offsetWidth;
  517. const h = this.$refs.frameBox.offsetHeight;
  518. const normalSize = `width: ${w}px; height: ${h}px;`;
  519. this.$refs.frameWrap.style = normalSize;
  520. if (this.frameScale != 1) {
  521. const s = this.frameScale;
  522. this.$refs.frame.style = `width: ${w/s}px; height: ${h/s}px; transform: scale(${s}); transform-origin: 0 0;`;
  523. } else {
  524. this.$refs.frame.style = normalSize;
  525. }
  526. }
  527. });
  528. }
  529. changeScale(delta) {
  530. if ((this.frameScale > 0.1 && delta <= 0) || (this.frameScale < 5 && delta >= 0)) {
  531. this.frameScale = _.round(this.frameScale + delta, 1);
  532. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.selectedLink);
  533. if (index >= 0) {
  534. let libs = _.cloneDeep(this.libs);
  535. libs.groups[index].frameScale = this.frameScale;
  536. this.commitLibs(libs);
  537. }
  538. this.frameResize();
  539. this.$root.notify.success(`Масштаб изменен: ${(this.frameScale*100).toFixed(0)}%`, '', {position: 'bottom-right'});
  540. }
  541. }
  542. getCommentByLink(list, link) {
  543. const item = lu.getListItemByLink(list, link);
  544. return (item ? item.c : '');
  545. }
  546. makeProxySubst(url, reverse = false) {
  547. for (const [key, value] of Object.entries(proxySubst)) {
  548. if (reverse && value == url.substring(0, value.length)) {
  549. return key + url.substring(value.length);
  550. } else if (!reverse && key == url.substring(0, key.length)) {
  551. return value + url.substring(key.length);
  552. }
  553. }
  554. return url;
  555. }
  556. selectAllOnFocus(event) {
  557. if (event.target.select)
  558. event.target.select();
  559. }
  560. rootLinkInput() {
  561. this.updateSelectedLinkByRoot();
  562. this.updateStartLink(true);
  563. }
  564. selectedLinkInput() {
  565. this.updateStartLink(true);
  566. }
  567. submitUrl() {
  568. if (this.bookUrl) {
  569. this.sendMessage({type: 'submitUrl', data: {
  570. url: this.bookUrl,
  571. force: true
  572. }});
  573. this.bookUrl = '';
  574. if (this.closeAfterSubmit)
  575. this.close();
  576. }
  577. }
  578. addBookmark(mode = 'add', link = '', desc = '') {
  579. if (mode == 'edit') {
  580. this.editBookmarkLink = this.bookmarkLink = link;
  581. this.editBookmarkDesc = this.bookmarkDesc = desc;
  582. } else {
  583. this.bookmarkLink = this.bookUrl;
  584. this.bookmarkDesc = '';
  585. }
  586. this.addBookmarkMode = mode;
  587. this.addBookmarkVisible = true;
  588. this.$nextTick(async() => {
  589. await this.$refs.dialogAddBookmark.waitShown();
  590. this.$refs.bookmarkLink.focus();
  591. });
  592. }
  593. updateBookmarkLink() {
  594. const index = lu.getSafeRootIndexByUrl(rstore.libsDefaults.groups, this.defaultRootLink);
  595. if (index >= 0) {
  596. this.bookmarkLink = rstore.libsDefaults.groups[index].s;
  597. this.bookmarkDesc = this.getCommentByLink(rstore.libsDefaults.groups[index].list, this.bookmarkLink);
  598. } else {
  599. this.bookmarkLink = '';
  600. this.bookmarkDesc = '';
  601. }
  602. }
  603. bookmarkLinkKeyDown(event) {
  604. if (event.key == 'Enter') {
  605. this.$refs.bookmarkDesc.focus();
  606. event.preventDefault();
  607. }
  608. }
  609. bookmarkDescKeyDown(event) {
  610. if (event.key == 'Enter') {
  611. event.stopPropagation();
  612. event.preventDefault();
  613. this.okAddBookmark();
  614. }
  615. }
  616. async okAddBookmark() {
  617. if (!this.bookmarkLink)
  618. return;
  619. const link = (this.addBookmarkMode == 'edit' ? lu.addProtocol(this.editBookmarkLink) : lu.addProtocol(this.bookmarkLink));
  620. let index = -1;
  621. try {
  622. index = lu.getRootIndexByUrl(this.libs.groups, link);
  623. } catch (e) {
  624. await this.$root.stdDialog.alert('Неверный формат ссылки', 'Ошибка');
  625. return;
  626. }
  627. let libs = _.cloneDeep(this.libs);
  628. //добавление
  629. //есть группа в закладках
  630. if (index >= 0) {
  631. const item = lu.getListItemByLink(libs.groups[index].list, link);
  632. //редактирование
  633. if (item && this.addBookmarkMode == 'edit') {
  634. if (item) {
  635. //редактируем
  636. item.l = link;
  637. item.c = this.bookmarkDesc;
  638. this.commitLibs(libs);
  639. } else {
  640. await this.$root.stdDialog.alert('Не удалось отредактировать закладку', 'Ошибка');
  641. }
  642. } else if (!item) {
  643. //добавляем
  644. if (libs.groups[index].list.length >= 100) {
  645. await this.$root.stdDialog.alert('Достигнут предел количества закладок для этого сайта', 'Ошибка');
  646. return;
  647. }
  648. libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
  649. if (this.openInFrameOnAdd) {
  650. libs.startLink = link;
  651. libs.comment = this.bookmarkDesc;
  652. }
  653. this.commitLibs(libs);
  654. } else if (item.c != this.bookmarkDesc) {
  655. if (await this.$root.stdDialog.confirm(`Такая закладка уже существует с другим описанием.<br>` +
  656. `Заменить '${this.$root.sanitize(item.c)}' на '${this.$root.sanitize(this.bookmarkDesc)}'?`, ' ')) {
  657. item.c = this.bookmarkDesc;
  658. this.commitLibs(libs);
  659. } else
  660. return;
  661. } else {
  662. await this.$root.stdDialog.alert('Такая закладка уже существует', ' ');
  663. return;
  664. }
  665. } else {//нет группы в закладках
  666. if (libs.groups.length >= 100) {
  667. await this.$root.stdDialog.alert('Достигнут предел количества различных сайтов в закладках', 'Ошибка');
  668. return;
  669. }
  670. //добавляем сначала группу
  671. libs.groups.push({r: lu.getOrigin(link), s: link, list: []});
  672. index = lu.getSafeRootIndexByUrl(libs.groups, link);
  673. if (index >= 0)
  674. libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
  675. if (this.openInFrameOnAdd) {
  676. libs.startLink = link;
  677. libs.comment = this.bookmarkDesc;
  678. }
  679. this.commitLibs(libs);
  680. }
  681. this.addBookmarkVisible = false;
  682. }
  683. fullScreenToggle() {
  684. this.fullScreenActive = !this.fullScreenActive;
  685. if (this.fullScreenActive) {
  686. this.$q.fullscreen.request();
  687. } else {
  688. this.$q.fullscreen.exit();
  689. }
  690. }
  691. transparentLayoutClick() {
  692. this.transparentLayoutVisible = false;
  693. }
  694. onSelectPopupShow() {
  695. this.transparentLayoutVisible = true;
  696. }
  697. onSelectPopupHide() {
  698. this.transparentLayoutVisible = false;
  699. }
  700. close() {
  701. this.sendMessage({type: 'close'});
  702. }
  703. bookUrlKeyDown(event) {
  704. if (event.key == 'Enter') {
  705. if (!this.openInFrameOnEnter) {
  706. this.submitUrl();
  707. } else {
  708. if (this.bookUrl)
  709. this.goToLink(this.bookUrl);
  710. }
  711. event.preventDefault();
  712. }
  713. }
  714. bookmarkSettings() {
  715. this.bookmarkSettingsActive = true;
  716. this.$nextTick(() => {
  717. this.$refs.bookmarkSettings.init();
  718. });
  719. }
  720. closeBookmarkSettings() {
  721. this.bookmarkSettingsActive = false;
  722. }
  723. showHelp() {
  724. this.$root.stdDialog.alert(`
  725. <p>Окно 'Сетевая библиотека' позволяет открывать ссылки в читалке без переключения между окнами,
  726. что особенно актуально для мобильных устройств. Имеется возможность управлять закладками
  727. на понравившиеся ресурсы, книги или страницы авторов. Открытие ссылок и навигация происходят во фрейме, но,
  728. к сожалению, в нем открываются не все страницы.</p>
  729. <p>Доступ к сайтам <span style="color: blue">http://flibusta.is</span> и <span style="color: blue">http://fantasy-worlds.org</span> работает через прокси.
  730. <br><span style="color: red"><b>ПРЕДУПРЕЖДЕНИЕ!</b></span>
  731. Доступ предназначен только для просмотра и скачивания книг. Авторизоваться на этих сайтах
  732. из фрейма категорически не рекомендуется, т.к. ваше подключение не защищено и данные могут попасть
  733. к третьим лицам.
  734. </p>
  735. <p>Из-за проблем с безопасностью, навигация 'вперед-назад' во фрейме осуществляется с помощью контекстного меню правой кнопкой мыши.
  736. На мобильных устройствах для этого служит системная клавиша 'Назад (стрелка влево)' и опция 'Вперед (стрелка вправо)' в меню браузера.
  737. </p>
  738. <p>Приятного пользования ;-)
  739. </p>
  740. `, 'Справка', {iconName: 'la la-info-circle'});
  741. }
  742. keyHook(event) {
  743. if (this.$root.getRootRoute() == '/external-libs') {
  744. if (this.$root.stdDialog.active)
  745. return false;
  746. if (this.bookmarkSettingsActive && this.$refs.bookmarkSettings.keyHook(event))
  747. return true;
  748. if (this.addBookmarkVisible || this.optionsVisible)
  749. return false;
  750. if (event.type == 'keydown' && event.key == 'F4') {
  751. this.addBookmark();
  752. return true;
  753. }
  754. if (event.type == 'keydown' && event.key == 'Escape' &&
  755. (document.activeElement != this.$refs.rootLink.$refs.target || !this.$refs.rootLink.menu) &&
  756. (document.activeElement != this.$refs.selectedLink.$refs.target || !this.$refs.selectedLink.menu)
  757. ) {
  758. this.close();
  759. return true;
  760. }
  761. }
  762. return false;
  763. }
  764. }
  765. export default vueComponent(ExternalLibs);
  766. //-----------------------------------------------------------------------------
  767. </script>
  768. <style scoped>
  769. .separator {
  770. height: 1px;
  771. background-color: #A0A0A0;
  772. }
  773. .full-screen-button {
  774. width: 30px;
  775. height: 30px;
  776. cursor: pointer;
  777. }
  778. .full-screen-button:hover {
  779. background-color: #69C05F;
  780. }
  781. .transparent-layout {
  782. top: 0;
  783. left: 0;
  784. position: absolute;
  785. }
  786. </style>