ExternalLibs.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. <template>
  2. <Window ref="window" margin="2px" @close="close">
  3. <template #header>
  4. {{ header }}
  5. </template>
  6. <template #buttons>
  7. <span class="header-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="header-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="header-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="header-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. 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. 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. outlined dense
  73. bg-color="white"
  74. placeholder="Скопируйте сюда ссылку на книгу и нажмите 'Открыть'"
  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" 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" allow="clipboard-read; clipboard-write"></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. inpxReady = false;
  281. inpxTitle = '';
  282. inpxUrl = '';
  283. created() {
  284. this.oldStartLink = '';
  285. this.justOpened = true;
  286. this.$root.addEventHook('key', this.keyHook);
  287. this.$root.addEventHook('resize', async() => {
  288. await utils.sleep(200);
  289. this.frameResize();
  290. });
  291. document.addEventListener('fullscreenchange', () => {
  292. this.fullScreenActive = (document.fullscreenElement !== null);
  293. });
  294. this.debouncedGoToLink = _.debounce((link) => {
  295. this.goToLink(link);
  296. }, 100, {'maxWait':200});
  297. //this.commit = this.$store.commit;
  298. //this.commit('reader/setLibs', rstore.libsDefaults);
  299. }
  300. mounted() {
  301. (async() => {
  302. //подождем this.mode
  303. let i = 0;
  304. while(!this.mode && i < 100) {
  305. await utils.sleep(100);
  306. i++;
  307. }
  308. if (this.mode != 'liberama.top') {
  309. this.$router.replace('/404');
  310. return;
  311. }
  312. this.$refs.window.init();
  313. this.opener = null;
  314. const host = window.location.host;
  315. const openerHost = (host.indexOf('b.') == 0 ? host.substring(2) : host);
  316. const openerOrigin1 = `http://${openerHost}`;
  317. const openerOrigin2 = `https://${openerHost}`;
  318. window.addEventListener('message', (event) => {
  319. //from inpx-web
  320. if (_.isObject(event.data) && event.data.from === 'inpx-web') {
  321. //console.log(event);
  322. this.inpxOrigin = event.origin;
  323. this.recvInpxMessage(event.data);
  324. return;
  325. }
  326. //from parent
  327. if (event.origin !== openerOrigin1 && event.origin !== openerOrigin2)
  328. return;
  329. if (!_.isObject(event.data) || event.data.from != 'LibsPage')
  330. return;
  331. if (event.origin == openerOrigin1)
  332. this.opener = window.opener;
  333. else
  334. this.opener = event.source;
  335. this.openerOrigin = event.origin;
  336. this.recvMessage(event.data);
  337. });
  338. //Ожидаем родителя
  339. i = 0;
  340. while(!this.opener) {
  341. await utils.sleep(1000);
  342. i++;
  343. if (i >= 5) {
  344. await this.$root.stdDialog.alert('Нет связи с читалкой. Окно будет закрыто', 'Ошибка');
  345. window.close();
  346. }
  347. }
  348. //Проверка закрытия родительского окна
  349. while(this.opener) {
  350. await this.checkOpener();
  351. await utils.sleep(1000);
  352. }
  353. })();
  354. }
  355. recvMessage(d) {
  356. if (d.type == 'mes') {
  357. switch(d.data) {
  358. case 'hello': this.sendMessage({type: 'mes', data: 'ready'}); break;
  359. }
  360. } else if (d.type == 'libs') {
  361. this.ready = true;
  362. this.libs = _.cloneDeep(d.data);
  363. } else if (d.type == 'notify') {
  364. this.$root.notify.success(d.data, '', {position: 'bottom-right'});
  365. }
  366. }
  367. sendMessage(d) {
  368. (async() => {
  369. await this.checkOpener();
  370. if (this.opener && this.openerOrigin)
  371. this.opener.postMessage(Object.assign({}, {from: 'ExternalLibs'}, d), this.openerOrigin);
  372. })();
  373. }
  374. recvInpxMessage(d) {
  375. if (d.type == 'mes') {
  376. switch(d.data) {
  377. case 'hello-from-inpx-web':
  378. this.sendInpxMessage({type: 'mes', data: 'ready'});
  379. break;
  380. case 'ready':
  381. this.inpxReady = true;
  382. break;
  383. }
  384. } else if (d.type == 'submitUrl') {
  385. this.submitUrl(d.data);
  386. } else if (d.type == 'titleChange') {
  387. this.inpxTitle = d.data;
  388. } else if (d.type == 'urlChange') {
  389. this.inpxUrl = d.data;
  390. }
  391. }
  392. sendInpxMessage(d) {
  393. if (this.$refs.frame && this.inpxOrigin)
  394. this.$refs.frame.contentWindow.postMessage(Object.assign({}, {from: 'ExternalLibs'}, d), this.inpxOrigin);
  395. }
  396. async checkOpener() {
  397. if (this.opener.closed) {
  398. await this.$root.stdDialog.alert('Потеряна связь с читалкой. Окно будет закрыто', 'Ошибка');
  399. window.close();
  400. }
  401. }
  402. commitLibs(libs) {
  403. this.sendMessage({type: 'libs', data: libs});
  404. }
  405. commitProp(prop, value) {
  406. let libs = _.cloneDeep(this.libs);
  407. libs[prop] = value;
  408. this.commitLibs(libs);
  409. }
  410. loadLibs() {
  411. const libs = this.libs;
  412. if (!libs.helpShowed) {
  413. this.showHelp();
  414. (async() => {
  415. await utils.sleep(1000);
  416. this.commitProp('helpShowed', true);
  417. })();
  418. }
  419. this.selectedLink = libs.startLink;
  420. this.closeAfterSubmit = libs.closeAfterSubmit || false;
  421. this.openInFrameOnEnter = libs.openInFrameOnEnter || false;
  422. this.openInFrameOnAdd = libs.openInFrameOnAdd || false;
  423. this.frameScale = 1;
  424. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.selectedLink);
  425. if (index >= 0)
  426. this.frameScale = this.libs.groups[index].frameScale || 1;
  427. this.updateStartLink();
  428. }
  429. doAction(event) {
  430. switch (event.action) {
  431. case 'setLibs': this.commitLibs(event.data); break;
  432. case 'setRootLink': this.rootLink = event.data; this.rootLinkInput(); break;
  433. case 'setSelectedLink': this.selectedLink = event.data; this.selectedLinkInput(); break;
  434. case 'editBookmark': this.addBookmark('edit', event.data.link, event.data.desc); break;
  435. case 'addBookmark': this.addBookmark('add'); break;
  436. }
  437. }
  438. get mode() {
  439. return this.$store.state.config.mode;
  440. }
  441. get header() {
  442. let result = (this.ready ? 'Сетевая библиотека' : 'Загрузка...');
  443. if (this.ready && this.selectedLink) {
  444. let title = `${(this.libs.comment ? this.libs.comment + ' ': '') + lu.removeProtocol(this.libs.startLink)}`;
  445. if (this.inpxReady && this.inpxTitle)
  446. title = this.inpxTitle;
  447. result += ` | ${title}`;
  448. }
  449. this.$root.setAppTitle(result);
  450. return result;
  451. }
  452. get rootLinkWithoutProtocol() {
  453. return lu.removeProtocol(this.rootLink);
  454. }
  455. updateSelectedLinkByRoot() {
  456. if (!this.ready)
  457. return;
  458. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.rootLink);
  459. if (index >= 0)
  460. this.selectedLink = this.libs.groups[index].s;
  461. else
  462. this.selectedLink = '';
  463. }
  464. updateStartLink(force) {
  465. if (!this.ready)
  466. return;
  467. let index = -1;
  468. try {
  469. this.rootLink = lu.getOrigin(this.selectedLink);
  470. index = lu.getRootIndexByUrl(this.libs.groups, this.rootLink);
  471. } catch(e) {
  472. //
  473. }
  474. if (index >= 0) {
  475. let libs = _.cloneDeep(this.libs);
  476. const com = this.getCommentByLink(libs.groups[index].list, this.selectedLink);
  477. if (libs.groups[index].s != this.selectedLink ||
  478. libs.startLink != this.selectedLink ||
  479. libs.comment != com) {
  480. libs.groups[index].s = this.selectedLink;
  481. libs.startLink = this.selectedLink;
  482. libs.comment = com;
  483. this.commitLibs(libs);
  484. }
  485. if (force || this.oldStartLink != libs.startLink) {
  486. this.oldStartLink = libs.startLink;
  487. this.debouncedGoToLink(this.selectedLink);
  488. }
  489. } else {
  490. this.rootLink = '';
  491. this.selectedLink = '';
  492. this.debouncedGoToLink(this.selectedLink);
  493. }
  494. }
  495. get rootLinkOptions() {
  496. let result = [];
  497. if (!this.ready)
  498. return result;
  499. this.libs.groups.forEach(group => {
  500. result.push({label: lu.removeProtocol(group.r), value: group.r});
  501. });
  502. return result;
  503. }
  504. get defaultRootLinkOptions() {
  505. let result = [];
  506. rstore.libsDefaults.groups.forEach(group => {
  507. result.push({label: lu.removeProtocol(group.r), value: group.r});
  508. });
  509. return result;
  510. }
  511. get selectedLinkOptions() {
  512. let result = [];
  513. if (!this.ready)
  514. return result;
  515. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.rootLink);
  516. if (index >= 0) {
  517. this.libs.groups[index].list.forEach(link => {
  518. result.push({label: (link.c ? link.c + ' ': '') + lu.removeOrigin(link.l), value: link.l});
  519. });
  520. }
  521. return result;
  522. }
  523. openBookUrlInFrame() {
  524. if (this.bookUrl) {
  525. this.goToLink(lu.addProtocol(this.bookUrl));
  526. }
  527. }
  528. goToLink(link) {
  529. this.inpxReady = false;
  530. this.inpxOrigin = false;
  531. if (!this.ready || !link)
  532. return;
  533. if (!link) {
  534. this.frameVisible = false;
  535. return;
  536. }
  537. this.frameSrc = this.makeProxySubst(link);
  538. this.frameVisible = false;
  539. this.$nextTick(() => {
  540. this.frameVisible = true;
  541. this.$nextTick(() => {
  542. if (this.$refs.frame) {
  543. this.$refs.frame.contentWindow.location.reload(true);
  544. this.$refs.frame.contentWindow.focus();
  545. this.frameResize();
  546. }
  547. });
  548. });
  549. }
  550. frameResize() {
  551. this.$refs.frameWrap.style = 'width: 1px; height: 1px;';
  552. this.$nextTick(() => {
  553. if (this.$refs.frame) {
  554. const w = this.$refs.frameBox.offsetWidth;
  555. const h = this.$refs.frameBox.offsetHeight;
  556. const normalSize = `width: ${w}px; height: ${h}px;`;
  557. this.$refs.frameWrap.style = normalSize;
  558. if (this.frameScale != 1) {
  559. const s = this.frameScale;
  560. this.$refs.frame.style = `width: ${w/s}px; height: ${h/s}px; transform: scale(${s}); transform-origin: 0 0;`;
  561. } else {
  562. this.$refs.frame.style = normalSize;
  563. }
  564. }
  565. });
  566. }
  567. changeScale(delta) {
  568. if ((this.frameScale > 0.1 && delta <= 0) || (this.frameScale < 5 && delta >= 0)) {
  569. this.frameScale = _.round(this.frameScale + delta, 1);
  570. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.selectedLink);
  571. if (index >= 0) {
  572. let libs = _.cloneDeep(this.libs);
  573. libs.groups[index].frameScale = this.frameScale;
  574. this.commitLibs(libs);
  575. }
  576. this.frameResize();
  577. this.$root.notify.success(`Масштаб изменен: ${(this.frameScale*100).toFixed(0)}%`, '', {position: 'bottom-right'});
  578. }
  579. }
  580. getCommentByLink(list, link) {
  581. const item = lu.getListItemByLink(list, link);
  582. return (item ? item.c : '');
  583. }
  584. makeProxySubst(url, reverse = false) {
  585. for (const [key, value] of Object.entries(proxySubst)) {
  586. if (reverse && value == url.substring(0, value.length)) {
  587. return key + url.substring(value.length);
  588. } else if (!reverse && key == url.substring(0, key.length)) {
  589. return value + url.substring(key.length);
  590. }
  591. }
  592. return url;
  593. }
  594. selectAllOnFocus(event) {
  595. if (event.target.select)
  596. event.target.select();
  597. }
  598. rootLinkInput() {
  599. this.updateSelectedLinkByRoot();
  600. this.updateStartLink(true);
  601. }
  602. selectedLinkInput() {
  603. this.updateStartLink(true);
  604. }
  605. submitUrl(url) {
  606. if (!url) {
  607. url = this.bookUrl;
  608. this.bookUrl = '';
  609. }
  610. if (url) {
  611. this.sendMessage({type: 'submitUrl', data: {
  612. url,
  613. force: true
  614. }});
  615. if (this.closeAfterSubmit)
  616. this.close();
  617. }
  618. }
  619. addBookmark(mode = 'add', link = '', desc = '') {
  620. if (mode == 'edit') {
  621. this.editBookmarkLink = this.bookmarkLink = link;
  622. this.editBookmarkDesc = this.bookmarkDesc = desc;
  623. } else {
  624. this.bookmarkLink = this.bookUrl;
  625. this.bookmarkDesc = '';
  626. if (!this.bookmarkLink && this.inpxReady && this.inpxUrl) {
  627. this.bookmarkLink = this.inpxUrl;
  628. if (this.inpxTitle)
  629. this.bookmarkDesc = this.inpxTitle;
  630. }
  631. }
  632. this.addBookmarkMode = mode;
  633. this.addBookmarkVisible = true;
  634. this.$nextTick(async() => {
  635. await this.$refs.dialogAddBookmark.waitShown();
  636. this.$refs.bookmarkLink.focus();
  637. });
  638. }
  639. updateBookmarkLink() {
  640. const index = lu.getSafeRootIndexByUrl(rstore.libsDefaults.groups, this.defaultRootLink);
  641. if (index >= 0) {
  642. this.bookmarkLink = rstore.libsDefaults.groups[index].s;
  643. this.bookmarkDesc = this.getCommentByLink(rstore.libsDefaults.groups[index].list, this.bookmarkLink);
  644. } else {
  645. this.bookmarkLink = '';
  646. this.bookmarkDesc = '';
  647. }
  648. }
  649. bookmarkLinkKeyDown(event) {
  650. if (event.key == 'Enter') {
  651. this.$refs.bookmarkDesc.focus();
  652. event.preventDefault();
  653. }
  654. }
  655. bookmarkDescKeyDown(event) {
  656. if (event.key == 'Enter') {
  657. event.stopPropagation();
  658. event.preventDefault();
  659. this.okAddBookmark();
  660. }
  661. }
  662. async okAddBookmark() {
  663. if (!this.bookmarkLink)
  664. return;
  665. const link = (this.addBookmarkMode == 'edit' ? lu.addProtocol(this.editBookmarkLink) : lu.addProtocol(this.bookmarkLink));
  666. let index = -1;
  667. try {
  668. index = lu.getRootIndexByUrl(this.libs.groups, link);
  669. } catch (e) {
  670. await this.$root.stdDialog.alert('Неверный формат ссылки', 'Ошибка');
  671. return;
  672. }
  673. let libs = _.cloneDeep(this.libs);
  674. //добавление
  675. //есть группа в закладках
  676. if (index >= 0) {
  677. const item = lu.getListItemByLink(libs.groups[index].list, link);
  678. //редактирование
  679. if (item && this.addBookmarkMode == 'edit') {
  680. if (item) {
  681. //редактируем
  682. item.l = link;
  683. item.c = this.bookmarkDesc;
  684. this.commitLibs(libs);
  685. } else {
  686. await this.$root.stdDialog.alert('Не удалось отредактировать закладку', 'Ошибка');
  687. }
  688. } else if (!item) {
  689. //добавляем
  690. if (libs.groups[index].list.length >= 100) {
  691. await this.$root.stdDialog.alert('Достигнут предел количества закладок для этого сайта', 'Ошибка');
  692. return;
  693. }
  694. libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
  695. if (this.openInFrameOnAdd) {
  696. libs.startLink = link;
  697. libs.comment = this.bookmarkDesc;
  698. }
  699. this.commitLibs(libs);
  700. } else if (item.c != this.bookmarkDesc) {
  701. if (await this.$root.stdDialog.confirm(`Такая закладка уже существует с другим описанием.<br>` +
  702. `Заменить '${this.$root.sanitize(item.c)}' на '${this.$root.sanitize(this.bookmarkDesc)}'?`, ' ')) {
  703. item.c = this.bookmarkDesc;
  704. this.commitLibs(libs);
  705. } else
  706. return;
  707. } else {
  708. await this.$root.stdDialog.alert('Такая закладка уже существует', ' ');
  709. return;
  710. }
  711. } else {//нет группы в закладках
  712. if (libs.groups.length >= 100) {
  713. await this.$root.stdDialog.alert('Достигнут предел количества различных сайтов в закладках', 'Ошибка');
  714. return;
  715. }
  716. //добавляем сначала группу
  717. libs.groups.push({r: lu.getOrigin(link), s: link, list: []});
  718. index = lu.getSafeRootIndexByUrl(libs.groups, link);
  719. if (index >= 0)
  720. libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
  721. if (this.openInFrameOnAdd) {
  722. libs.startLink = link;
  723. libs.comment = this.bookmarkDesc;
  724. }
  725. this.commitLibs(libs);
  726. }
  727. this.addBookmarkVisible = false;
  728. }
  729. fullScreenToggle() {
  730. this.fullScreenActive = !this.fullScreenActive;
  731. if (this.fullScreenActive) {
  732. this.$q.fullscreen.request();
  733. } else {
  734. this.$q.fullscreen.exit();
  735. }
  736. }
  737. transparentLayoutClick() {
  738. this.transparentLayoutVisible = false;
  739. }
  740. onSelectPopupShow() {
  741. this.transparentLayoutVisible = true;
  742. }
  743. onSelectPopupHide() {
  744. this.transparentLayoutVisible = false;
  745. }
  746. close() {
  747. this.sendMessage({type: 'close'});
  748. }
  749. bookUrlKeyDown(event) {
  750. if (event.key == 'Enter') {
  751. if (!this.openInFrameOnEnter) {
  752. this.submitUrl();
  753. } else {
  754. if (this.bookUrl)
  755. this.goToLink(this.bookUrl);
  756. }
  757. event.preventDefault();
  758. }
  759. }
  760. bookmarkSettings() {
  761. this.bookmarkSettingsActive = true;
  762. this.$nextTick(() => {
  763. this.$refs.bookmarkSettings.init();
  764. });
  765. }
  766. closeBookmarkSettings() {
  767. this.bookmarkSettingsActive = false;
  768. }
  769. showHelp() {
  770. this.$root.stdDialog.alert(`
  771. <p>Окно 'Сетевая библиотека' позволяет открывать ссылки в читалке без переключения между окнами,
  772. что особенно актуально для мобильных устройств. Имеется возможность управлять закладками
  773. на понравившиеся ресурсы, книги или страницы авторов. Открытие ссылок и навигация происходят во фрейме, но,
  774. к сожалению, в нем открываются не все страницы.</p>
  775. <p>Доступ к сайтам <span style="color: blue">http://flibusta.is</span> и <span style="color: blue">http://fantasy-worlds.org</span> работает через прокси.
  776. <br><span style="color: red"><b>ПРЕДУПРЕЖДЕНИЕ!</b></span>
  777. Доступ предназначен только для просмотра и скачивания книг. Авторизоваться на этих сайтах
  778. из фрейма категорически не рекомендуется, т.к. ваше подключение не защищено и данные могут попасть
  779. к третьим лицам.
  780. </p>
  781. <p>Из-за проблем с безопасностью, навигация 'вперед-назад' во фрейме осуществляется с помощью контекстного меню правой кнопкой мыши.
  782. На мобильных устройствах для этого служит системная клавиша 'Назад (стрелка влево)' и опция 'Вперед (стрелка вправо)' в меню браузера.
  783. </p>
  784. <p>Приятного пользования ;-)
  785. </p>
  786. `, 'Справка', {iconName: 'la la-info-circle'});
  787. }
  788. keyHook(event) {
  789. if (this.$root.getRootRoute() == '/external-libs') {
  790. if (this.$root.stdDialog.active)
  791. return false;
  792. if (this.bookmarkSettingsActive && this.$refs.bookmarkSettings.keyHook(event))
  793. return true;
  794. if (this.addBookmarkVisible || this.optionsVisible)
  795. return false;
  796. if (event.type == 'keydown' && event.key == 'F4') {
  797. this.addBookmark();
  798. return true;
  799. }
  800. if (event.type == 'keydown' && event.key == 'Escape' &&
  801. (document.activeElement != this.$refs.rootLink.$refs.target || !this.$refs.rootLink.menu) &&
  802. (document.activeElement != this.$refs.selectedLink.$refs.target || !this.$refs.selectedLink.menu)
  803. ) {
  804. this.close();
  805. return true;
  806. }
  807. }
  808. return false;
  809. }
  810. }
  811. export default vueComponent(ExternalLibs);
  812. //-----------------------------------------------------------------------------
  813. </script>
  814. <style scoped>
  815. .separator {
  816. height: 1px;
  817. background-color: #A0A0A0;
  818. }
  819. .header-button {
  820. width: 30px;
  821. height: 30px;
  822. cursor: pointer;
  823. }
  824. .header-button:hover {
  825. color: white;
  826. background-color: #39902F;
  827. }
  828. .transparent-layout {
  829. top: 0;
  830. left: 0;
  831. position: absolute;
  832. }
  833. </style>