Added info about authors and books from Wikipedia
This commit is contained in:
parent
c0b6e35430
commit
3cfedc7e08
91
src/App.vue
91
src/App.vue
@ -65,6 +65,12 @@
|
||||
</v-list-tile-action>
|
||||
<v-list-tile-title>{{ $t("autoBookmarks") }}</v-list-tile-title>
|
||||
</v-list-tile>
|
||||
<v-list-tile>
|
||||
<v-list-tile-action>
|
||||
<v-switch v-model="useWikipedia" color="blue"></v-switch>
|
||||
</v-list-tile-action>
|
||||
<v-list-tile-title>{{ $t("useWikipedia") }}</v-list-tile-title>
|
||||
</v-list-tile>
|
||||
|
||||
<v-divider></v-divider>
|
||||
|
||||
@ -194,7 +200,7 @@
|
||||
return {
|
||||
appNet: "CAINet",
|
||||
appName: "Аудиотека",
|
||||
|
||||
|
||||
activeTab: null,
|
||||
autoBookmark: false,
|
||||
darkTheme: false,
|
||||
@ -206,6 +212,7 @@
|
||||
{ flag: "ru", language: "ru", title: "Русский" }
|
||||
],
|
||||
scrolled: false,
|
||||
useWikipedia: false,
|
||||
volume: 5//,
|
||||
//locale: []
|
||||
}
|
||||
@ -214,23 +221,24 @@
|
||||
created () {
|
||||
window.addEventListener("scroll", this.onScroll);
|
||||
},
|
||||
|
||||
|
||||
mounted () {
|
||||
this.isMounted = true;
|
||||
this.darkTheme = localStorage.darkTheme
|
||||
? JSON.parse(localStorage.darkTheme)
|
||||
this.darkTheme = localStorage.darkTheme
|
||||
? JSON.parse(localStorage.darkTheme)
|
||||
: false;
|
||||
this.autoBookmark = localStorage.autoBookmark
|
||||
? JSON.parse(localStorage.autoBookmark)
|
||||
this.autoBookmark = localStorage.autoBookmark
|
||||
? JSON.parse(localStorage.autoBookmark)
|
||||
: false;
|
||||
this.volume = localStorage.volume
|
||||
? JSON.parse(localStorage.volume)
|
||||
this.useWikipedia = localStorage.useWikipedia
|
||||
? JSON.parse(localStorage.useWikipedia)
|
||||
: false;
|
||||
this.volume = localStorage.volume
|
||||
? JSON.parse(localStorage.volume)
|
||||
: 5;
|
||||
|
||||
this.isLoading = true;
|
||||
|
||||
//let userLocale = navigator.language || navigator.userLanguage;
|
||||
|
||||
this.axios.get("config.json")
|
||||
.then(response => {
|
||||
this.appNet = response.data.AppNet;
|
||||
@ -306,6 +314,7 @@
|
||||
watch: {
|
||||
autoBookmark (val) { localStorage.autoBookmark = val; },
|
||||
darkTheme (val) { localStorage.darkTheme = val; },
|
||||
useWikipedia (val) { localStorage.useWikipedia = val; },
|
||||
volume (val) {
|
||||
localStorage.volume = val;
|
||||
this.$refs.Book.volume = val;
|
||||
@ -313,18 +322,60 @@
|
||||
},
|
||||
|
||||
methods: {
|
||||
fillWikiInfo (searchText, fillAuthorInfo = true) {
|
||||
this.axios.get("https://" + this.locale.language + ".wikipedia.org/w/api.php", {
|
||||
params: {
|
||||
format: "json",
|
||||
action: "query",
|
||||
prop: "extracts",
|
||||
exintro: 1,
|
||||
explaintext: 1,
|
||||
redirects: 1,
|
||||
titles: searchText,
|
||||
origin: "*"
|
||||
}
|
||||
}).then(response => {
|
||||
if (Object.getOwnPropertyNames(response.data.query.pages)[0] > 0) {
|
||||
let result = response.data.query.pages[
|
||||
Object.getOwnPropertyNames(response.data.query.pages)[0]
|
||||
].extract;
|
||||
|
||||
if (fillAuthorInfo) {
|
||||
this.$refs.Books.wikiText = result;
|
||||
} else {
|
||||
this.$refs.Book.wikiText = result;
|
||||
}
|
||||
} else {
|
||||
if (fillAuthorInfo) {
|
||||
this.$refs.Books.wikiText = "";
|
||||
} else {
|
||||
this.$refs.Book.wikiText = "";
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
this.isLoading = false;
|
||||
if (fillAuthorInfo) {
|
||||
this.$refs.Books.wikiText = "";
|
||||
} else {
|
||||
this.$refs.Book.wikiText = "";
|
||||
}
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
|
||||
getHash (val) {
|
||||
let CryptoJS = require("crypto-js");
|
||||
let hash = CryptoJS.MD5(val);
|
||||
return hash.toString(CryptoJS.enc.Hex);
|
||||
},
|
||||
|
||||
nextChapter () {
|
||||
this.$refs.Book.nextChapter();
|
||||
nextChapter () {
|
||||
this.$refs.Book.nextChapter();
|
||||
},
|
||||
|
||||
onScroll () {
|
||||
this.scrolled = window.scrollY > 0;
|
||||
onScroll () {
|
||||
this.scrolled = window.scrollY > 0;
|
||||
},
|
||||
|
||||
openBook (val) {
|
||||
@ -348,6 +399,9 @@
|
||||
this.$refs.Book.loadChapter();
|
||||
}
|
||||
|
||||
if (this.useWikipedia) {
|
||||
this.fillWikiInfo(val.title, false);
|
||||
}
|
||||
this.activeTab = 2;
|
||||
this.isLoading = false;
|
||||
})
|
||||
@ -356,8 +410,6 @@
|
||||
this.showMessage(this.$t("error"), error);
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
this.activeTab = 2;
|
||||
},
|
||||
|
||||
openBooks (val) {
|
||||
@ -368,6 +420,11 @@
|
||||
this.$refs.Books.authorName = val.author;
|
||||
this.$refs.Books.authorImg = val.image;
|
||||
this.$refs.Books.items = response.data;
|
||||
|
||||
if (this.useWikipedia) {
|
||||
this.fillWikiInfo(val.author);
|
||||
}
|
||||
|
||||
this.activeTab = 1;
|
||||
this.isLoading = false;
|
||||
})
|
||||
@ -404,7 +461,7 @@
|
||||
behavior: "smooth"
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
setBookmark (silent = true) {
|
||||
if (this.$refs.Book.items.length == 0) { return; }
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
items: []
|
||||
items: []
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -34,6 +34,19 @@
|
||||
</v-img>
|
||||
</v-flex>
|
||||
<v-flex xs12 text-xs-center>{{ bookTitle }}</v-flex>
|
||||
<v-flex xs12 v-if="wikiText !== ''">
|
||||
<v-expansion-panel>
|
||||
<v-expansion-panel-content>
|
||||
<template v-slot:header>
|
||||
<div>Wikipedia</div>
|
||||
</template>
|
||||
<v-card>
|
||||
<v-card-text>{{ wikiText }}</v-card-text>
|
||||
</v-card>
|
||||
</v-expansion-panel-content>
|
||||
</v-expansion-panel>
|
||||
|
||||
</v-flex>
|
||||
</v-flex>
|
||||
<v-flex xs12 sm6>
|
||||
<v-list>
|
||||
@ -73,7 +86,8 @@
|
||||
items: [],
|
||||
progress: 0,
|
||||
status: 0, //this.statuses.stopped,
|
||||
volume: 5
|
||||
volume: 5,
|
||||
wikiText: ""
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<v-card flat>
|
||||
<v-container bg grid-list-md>
|
||||
<v-layout row wrap align-center>
|
||||
<v-layout row wrap align-top>
|
||||
<v-flex>
|
||||
<v-img
|
||||
v-if="authorImg !== ''"
|
||||
@ -18,6 +18,18 @@
|
||||
{{ authorName }}
|
||||
</div>
|
||||
</v-flex>
|
||||
<v-flex xs12 sm6 v-if="wikiText !== ''">
|
||||
<v-expansion-panel>
|
||||
<v-expansion-panel-content>
|
||||
<template v-slot:header>
|
||||
<div>Wikipedia</div>
|
||||
</template>
|
||||
<v-card>
|
||||
<v-card-text>{{ wikiText }}</v-card-text>
|
||||
</v-card>
|
||||
</v-expansion-panel-content>
|
||||
</v-expansion-panel>
|
||||
</v-flex>
|
||||
</v-layout>
|
||||
</v-container>
|
||||
|
||||
@ -71,7 +83,8 @@
|
||||
return {
|
||||
authorName: "",
|
||||
authorImg: "",
|
||||
items: []
|
||||
items: [],
|
||||
wikiText: ""
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -16,7 +16,8 @@ const messages = {
|
||||
error: "Error",
|
||||
information: "Information",
|
||||
removeBookmark: "Remove bookmark",
|
||||
setBookmark: "Set bookmark"
|
||||
setBookmark: "Set bookmark",
|
||||
useWikipedia: "Use Wikipedia"
|
||||
},
|
||||
"ru": {
|
||||
about: "О приложении",
|
||||
@ -30,7 +31,8 @@ const messages = {
|
||||
error: "Ошибка",
|
||||
information: "Информация",
|
||||
removeBookmark: "Удалить закладку",
|
||||
setBookmark: "Установить закладку"
|
||||
setBookmark: "Установить закладку",
|
||||
useWikipedia: "Использовать Wikipedia"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user