ExternalLibs.vue 29 KB

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