|
@@ -28,7 +28,7 @@
|
|
</q-btn>
|
|
</q-btn>
|
|
</template>
|
|
</template>
|
|
<template v-slot:selected>
|
|
<template v-slot:selected>
|
|
- <div style="overflow: hidden; white-space: nowrap;">{{ removeProtocol(rootLink) }}</div>
|
|
|
|
|
|
+ <div style="overflow: hidden; white-space: nowrap;">{{ rootLinkWithoutProtocol }}</div>
|
|
</template>
|
|
</template>
|
|
</q-select>
|
|
</q-select>
|
|
|
|
|
|
@@ -113,6 +113,7 @@ import BookmarkSettings from './BookmarkSettings/BookmarkSettings.vue';
|
|
|
|
|
|
import rstore from '../../store/modules/reader';
|
|
import rstore from '../../store/modules/reader';
|
|
import * as utils from '../../share/utils';
|
|
import * as utils from '../../share/utils';
|
|
|
|
+import * as lu from './linkUtils';
|
|
|
|
|
|
const proxySubst = {
|
|
const proxySubst = {
|
|
'http://flibusta.is': 'http://b.liberama.top:23480',
|
|
'http://flibusta.is': 'http://b.liberama.top:23480',
|
|
@@ -286,8 +287,8 @@ class ExternalLibs extends Vue {
|
|
|
|
|
|
loadLibs() {
|
|
loadLibs() {
|
|
const libs = this.libs;
|
|
const libs = this.libs;
|
|
- this.startLink = (libs.comment ? libs.comment + ' ': '') + this.removeProtocol(libs.startLink);
|
|
|
|
- this.rootLink = this.getOrigin(libs.startLink);
|
|
|
|
|
|
+ this.startLink = (libs.comment ? libs.comment + ' ': '') + lu.removeProtocol(libs.startLink);
|
|
|
|
+ this.rootLink = lu.getOrigin(libs.startLink);
|
|
this.updateSelectedLink();
|
|
this.updateSelectedLink();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -304,10 +305,14 @@ class ExternalLibs extends Vue {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ get rootLinkWithoutProtocol() {
|
|
|
|
+ return lu.removeProtocol(this.rootLink);
|
|
|
|
+ }
|
|
|
|
+
|
|
updateSelectedLink() {
|
|
updateSelectedLink() {
|
|
if (!this.ready)
|
|
if (!this.ready)
|
|
return;
|
|
return;
|
|
- const index = this.getRootIndexByUrl(this.libs.groups, this.rootLink);
|
|
|
|
|
|
+ const index = lu.getRootIndexByUrl(this.libs.groups, this.rootLink);
|
|
if (index >= 0)
|
|
if (index >= 0)
|
|
this.selectedLink = this.libs.groups[index].s;
|
|
this.selectedLink = this.libs.groups[index].s;
|
|
}
|
|
}
|
|
@@ -315,7 +320,7 @@ class ExternalLibs extends Vue {
|
|
updateStartLink() {
|
|
updateStartLink() {
|
|
if (!this.ready)
|
|
if (!this.ready)
|
|
return;
|
|
return;
|
|
- const index = this.getRootIndexByUrl(this.libs.groups, this.rootLink);
|
|
|
|
|
|
+ const index = lu.getRootIndexByUrl(this.libs.groups, this.rootLink);
|
|
if (index >= 0) {
|
|
if (index >= 0) {
|
|
let libs = _.cloneDeep(this.libs);
|
|
let libs = _.cloneDeep(this.libs);
|
|
libs.groups[index].s = this.selectedLink;
|
|
libs.groups[index].s = this.selectedLink;
|
|
@@ -332,7 +337,7 @@ class ExternalLibs extends Vue {
|
|
return result;
|
|
return result;
|
|
|
|
|
|
this.libs.groups.forEach(group => {
|
|
this.libs.groups.forEach(group => {
|
|
- result.push({label: this.removeProtocol(group.r), value: group.r});
|
|
|
|
|
|
+ result.push({label: lu.removeProtocol(group.r), value: group.r});
|
|
});
|
|
});
|
|
|
|
|
|
return result;
|
|
return result;
|
|
@@ -342,7 +347,7 @@ class ExternalLibs extends Vue {
|
|
let result = [];
|
|
let result = [];
|
|
|
|
|
|
rstore.libsDefaults.groups.forEach(group => {
|
|
rstore.libsDefaults.groups.forEach(group => {
|
|
- result.push({label: this.removeProtocol(group.r), value: group.r});
|
|
|
|
|
|
+ result.push({label: lu.removeProtocol(group.r), value: group.r});
|
|
});
|
|
});
|
|
|
|
|
|
return result;
|
|
return result;
|
|
@@ -353,10 +358,10 @@ class ExternalLibs extends Vue {
|
|
if (!this.ready)
|
|
if (!this.ready)
|
|
return result;
|
|
return result;
|
|
|
|
|
|
- const index = this.getRootIndexByUrl(this.libs.groups, this.rootLink);
|
|
|
|
|
|
+ const index = lu.getRootIndexByUrl(this.libs.groups, this.rootLink);
|
|
if (index >= 0) {
|
|
if (index >= 0) {
|
|
this.libs.groups[index].list.forEach(link => {
|
|
this.libs.groups[index].list.forEach(link => {
|
|
- result.push({label: (link.c ? link.c + ' ': '') + this.removeOrigin(link.l), value: link.l});
|
|
|
|
|
|
+ result.push({label: (link.c ? link.c + ' ': '') + lu.removeOrigin(link.l), value: link.l});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -365,7 +370,7 @@ class ExternalLibs extends Vue {
|
|
|
|
|
|
openBookUrlInFrame() {
|
|
openBookUrlInFrame() {
|
|
if (this.bookUrl) {
|
|
if (this.bookUrl) {
|
|
- this.goToLink(this.addProtocol(this.bookUrl));
|
|
|
|
|
|
+ this.goToLink(lu.addProtocol(this.bookUrl));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -383,48 +388,8 @@ class ExternalLibs extends Vue {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- addProtocol(url) {
|
|
|
|
- if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0))
|
|
|
|
- return 'http://' + url;
|
|
|
|
- return url;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- removeProtocol(url) {
|
|
|
|
- return url.replace(/(^\w+:|^)\/\//, '');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- getOrigin(url) {
|
|
|
|
- const parsed = new URL(url);
|
|
|
|
- return parsed.origin;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- removeOrigin(url) {
|
|
|
|
- const parsed = new URL(url);
|
|
|
|
- const result = url.substring(parsed.origin.length);
|
|
|
|
- return (result ? result : '/');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- getRootIndexByUrl(groups, url) {
|
|
|
|
- if (!this.ready)
|
|
|
|
- return -1;
|
|
|
|
- const origin = this.getOrigin(url);
|
|
|
|
- for (let i = 0; i < groups.length; i++) {
|
|
|
|
- if (groups[i].r == origin)
|
|
|
|
- return i;
|
|
|
|
- }
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- getListItemByLink(list, link) {
|
|
|
|
- for (const item of list) {
|
|
|
|
- if (item.l == link)
|
|
|
|
- return item;
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
getCommentByLink(list, link) {
|
|
getCommentByLink(list, link) {
|
|
- const item = this.getListItemByLink(list, link);
|
|
|
|
|
|
+ const item = lu.getListItemByLink(list, link);
|
|
return (item ? item.c : '');
|
|
return (item ? item.c : '');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -457,7 +422,7 @@ class ExternalLibs extends Vue {
|
|
submitUrl() {
|
|
submitUrl() {
|
|
if (this.bookUrl) {
|
|
if (this.bookUrl) {
|
|
this.sendMessage({type: 'submitUrl', data: {
|
|
this.sendMessage({type: 'submitUrl', data: {
|
|
- url: this.makeProxySubst(this.addProtocol(this.bookUrl), true),
|
|
|
|
|
|
+ url: this.makeProxySubst(lu.addProtocol(this.bookUrl), true),
|
|
force: true
|
|
force: true
|
|
}});
|
|
}});
|
|
this.bookUrl = '';
|
|
this.bookUrl = '';
|
|
@@ -467,7 +432,7 @@ class ExternalLibs extends Vue {
|
|
}
|
|
}
|
|
|
|
|
|
addBookmark() {
|
|
addBookmark() {
|
|
- this.bookmarkLink = (this.bookUrl ? this.makeProxySubst(this.addProtocol(this.bookUrl), true) : '');
|
|
|
|
|
|
+ this.bookmarkLink = (this.bookUrl ? this.makeProxySubst(lu.addProtocol(this.bookUrl), true) : '');
|
|
this.bookmarkDesc = '';
|
|
this.bookmarkDesc = '';
|
|
this.addBookmarkVisible = true;
|
|
this.addBookmarkVisible = true;
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
@@ -477,7 +442,7 @@ class ExternalLibs extends Vue {
|
|
}
|
|
}
|
|
|
|
|
|
updateBookmarkLink() {
|
|
updateBookmarkLink() {
|
|
- const index = this.getRootIndexByUrl(rstore.libsDefaults.groups, this.defaultRootLink);
|
|
|
|
|
|
+ const index = lu.getRootIndexByUrl(rstore.libsDefaults.groups, this.defaultRootLink);
|
|
if (index >= 0) {
|
|
if (index >= 0) {
|
|
this.bookmarkLink = rstore.libsDefaults.groups[index].s;
|
|
this.bookmarkLink = rstore.libsDefaults.groups[index].s;
|
|
this.bookmarkDesc = this.getCommentByLink(rstore.libsDefaults.groups[index].list, this.bookmarkLink);
|
|
this.bookmarkDesc = this.getCommentByLink(rstore.libsDefaults.groups[index].list, this.bookmarkLink);
|
|
@@ -509,10 +474,10 @@ class ExternalLibs extends Vue {
|
|
if (!this.bookmarkLink)
|
|
if (!this.bookmarkLink)
|
|
return;
|
|
return;
|
|
|
|
|
|
- const link = this.addProtocol(this.bookmarkLink);
|
|
|
|
|
|
+ const link = lu.addProtocol(this.bookmarkLink);
|
|
let index = -1;
|
|
let index = -1;
|
|
try {
|
|
try {
|
|
- index = this.getRootIndexByUrl(this.libs.groups, link);
|
|
|
|
|
|
+ index = lu.getRootIndexByUrl(this.libs.groups, link);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
await this.$root.stdDialog.alert('Неверный формат ссылки', 'Ошибка');
|
|
await this.$root.stdDialog.alert('Неверный формат ссылки', 'Ошибка');
|
|
return;
|
|
return;
|
|
@@ -520,7 +485,7 @@ class ExternalLibs extends Vue {
|
|
|
|
|
|
//есть группа в закладках
|
|
//есть группа в закладках
|
|
if (index >= 0) {
|
|
if (index >= 0) {
|
|
- const item = this.getListItemByLink(this.libs.groups[index].list, link);
|
|
|
|
|
|
+ const item = lu.getListItemByLink(this.libs.groups[index].list, link);
|
|
|
|
|
|
if (!item || item.c != this.bookmarkDesc) {
|
|
if (!item || item.c != this.bookmarkDesc) {
|
|
//добавляем
|
|
//добавляем
|
|
@@ -543,9 +508,9 @@ class ExternalLibs extends Vue {
|
|
}
|
|
}
|
|
|
|
|
|
//добавляем сначала группу
|
|
//добавляем сначала группу
|
|
- libs.groups.push({r: this.getOrigin(link), s: link, list: []});
|
|
|
|
|
|
+ libs.groups.push({r: lu.getOrigin(link), s: link, list: []});
|
|
|
|
|
|
- index = this.getRootIndexByUrl(libs.groups, link);
|
|
|
|
|
|
+ index = lu.getRootIndexByUrl(libs.groups, link);
|
|
if (index >= 0)
|
|
if (index >= 0)
|
|
libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
|
|
libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
|
|
|
|
|