ExternalLibs.vue 35 KB

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