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