Added info about authors and books from Wikipedia

This commit is contained in:
Alexander I. Chebykin 2019-06-30 02:09:22 +03:00
parent c0b6e35430
commit 3cfedc7e08
5 changed files with 109 additions and 23 deletions

View File

@ -65,6 +65,12 @@
</v-list-tile-action> </v-list-tile-action>
<v-list-tile-title>{{ $t("autoBookmarks") }}</v-list-tile-title> <v-list-tile-title>{{ $t("autoBookmarks") }}</v-list-tile-title>
</v-list-tile> </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> <v-divider></v-divider>
@ -206,6 +212,7 @@
{ flag: "ru", language: "ru", title: "Русский" } { flag: "ru", language: "ru", title: "Русский" }
], ],
scrolled: false, scrolled: false,
useWikipedia: false,
volume: 5//, volume: 5//,
//locale: [] //locale: []
} }
@ -223,14 +230,15 @@
this.autoBookmark = localStorage.autoBookmark this.autoBookmark = localStorage.autoBookmark
? JSON.parse(localStorage.autoBookmark) ? JSON.parse(localStorage.autoBookmark)
: false; : false;
this.useWikipedia = localStorage.useWikipedia
? JSON.parse(localStorage.useWikipedia)
: false;
this.volume = localStorage.volume this.volume = localStorage.volume
? JSON.parse(localStorage.volume) ? JSON.parse(localStorage.volume)
: 5; : 5;
this.isLoading = true; this.isLoading = true;
//let userLocale = navigator.language || navigator.userLanguage;
this.axios.get("config.json") this.axios.get("config.json")
.then(response => { .then(response => {
this.appNet = response.data.AppNet; this.appNet = response.data.AppNet;
@ -306,6 +314,7 @@
watch: { watch: {
autoBookmark (val) { localStorage.autoBookmark = val; }, autoBookmark (val) { localStorage.autoBookmark = val; },
darkTheme (val) { localStorage.darkTheme = val; }, darkTheme (val) { localStorage.darkTheme = val; },
useWikipedia (val) { localStorage.useWikipedia = val; },
volume (val) { volume (val) {
localStorage.volume = val; localStorage.volume = val;
this.$refs.Book.volume = val; this.$refs.Book.volume = val;
@ -313,6 +322,48 @@
}, },
methods: { 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) { getHash (val) {
let CryptoJS = require("crypto-js"); let CryptoJS = require("crypto-js");
let hash = CryptoJS.MD5(val); let hash = CryptoJS.MD5(val);
@ -348,6 +399,9 @@
this.$refs.Book.loadChapter(); this.$refs.Book.loadChapter();
} }
if (this.useWikipedia) {
this.fillWikiInfo(val.title, false);
}
this.activeTab = 2; this.activeTab = 2;
this.isLoading = false; this.isLoading = false;
}) })
@ -356,8 +410,6 @@
this.showMessage(this.$t("error"), error); this.showMessage(this.$t("error"), error);
console.error(error); console.error(error);
}); });
this.activeTab = 2;
}, },
openBooks (val) { openBooks (val) {
@ -368,6 +420,11 @@
this.$refs.Books.authorName = val.author; this.$refs.Books.authorName = val.author;
this.$refs.Books.authorImg = val.image; this.$refs.Books.authorImg = val.image;
this.$refs.Books.items = response.data; this.$refs.Books.items = response.data;
if (this.useWikipedia) {
this.fillWikiInfo(val.author);
}
this.activeTab = 1; this.activeTab = 1;
this.isLoading = false; this.isLoading = false;
}) })

View File

@ -34,6 +34,19 @@
</v-img> </v-img>
</v-flex> </v-flex>
<v-flex xs12 text-xs-center>{{ bookTitle }}</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>
<v-flex xs12 sm6> <v-flex xs12 sm6>
<v-list> <v-list>
@ -73,7 +86,8 @@
items: [], items: [],
progress: 0, progress: 0,
status: 0, //this.statuses.stopped, status: 0, //this.statuses.stopped,
volume: 5 volume: 5,
wikiText: ""
} }
}, },

View File

@ -1,7 +1,7 @@
<template> <template>
<v-card flat> <v-card flat>
<v-container bg grid-list-md> <v-container bg grid-list-md>
<v-layout row wrap align-center> <v-layout row wrap align-top>
<v-flex> <v-flex>
<v-img <v-img
v-if="authorImg !== ''" v-if="authorImg !== ''"
@ -18,6 +18,18 @@
{{ authorName }} {{ authorName }}
</div> </div>
</v-flex> </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-layout>
</v-container> </v-container>
@ -71,7 +83,8 @@
return { return {
authorName: "", authorName: "",
authorImg: "", authorImg: "",
items: [] items: [],
wikiText: ""
} }
}, },

View File

@ -16,7 +16,8 @@ const messages = {
error: "Error", error: "Error",
information: "Information", information: "Information",
removeBookmark: "Remove bookmark", removeBookmark: "Remove bookmark",
setBookmark: "Set bookmark" setBookmark: "Set bookmark",
useWikipedia: "Use Wikipedia"
}, },
"ru": { "ru": {
about: "О приложении", about: "О приложении",
@ -30,7 +31,8 @@ const messages = {
error: "Ошибка", error: "Ошибка",
information: "Информация", information: "Информация",
removeBookmark: "Удалить закладку", removeBookmark: "Удалить закладку",
setBookmark: "Установить закладку" setBookmark: "Установить закладку",
useWikipedia: "Использовать Wikipedia"
} }
} }