diff --git a/src/App.vue b/src/App.vue index 8d12548..38e9d48 100644 --- a/src/App.vue +++ b/src/App.vue @@ -65,6 +65,12 @@ {{ $t("autoBookmarks") }} + + + + + {{ $t("useWikipedia") }} + @@ -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; } diff --git a/src/components/Authors.vue b/src/components/Authors.vue index d6cdfd5..140f750 100644 --- a/src/components/Authors.vue +++ b/src/components/Authors.vue @@ -50,7 +50,7 @@ export default { data () { return { - items: [] + items: [] } }, diff --git a/src/components/Book.vue b/src/components/Book.vue index 0b6344c..79d3deb 100644 --- a/src/components/Book.vue +++ b/src/components/Book.vue @@ -34,6 +34,19 @@ {{ bookTitle }} + + + + + + {{ wikiText }} + + + + + @@ -73,7 +86,8 @@ items: [], progress: 0, status: 0, //this.statuses.stopped, - volume: 5 + volume: 5, + wikiText: "" } }, diff --git a/src/components/Books.vue b/src/components/Books.vue index 80e9833..a818c31 100644 --- a/src/components/Books.vue +++ b/src/components/Books.vue @@ -1,7 +1,7 @@