about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <noreply@fakecake.org>2019-06-24 09:24:51 +0300
committerAndrew Dolgov <noreply@fakecake.org>2019-06-24 09:24:51 +0300
commit337bd2bdf525f4c6d783faacaec4f4189daf1d57 (patch)
treeb59111ff9dda2a45b30dda42f31805f753bd6448
parent6bbce144df1e35a4844afbbf10735ddecbe81819 (diff)
downloadthe-epube-337bd2bdf525f4c6d783faacaec4f4189daf1d57.tar.gz
the-epube-337bd2bdf525f4c6d783faacaec4f4189daf1d57.tar.xz
add basic wiktionary support
-rw-r--r--backend.php9
-rw-r--r--js/read.js24
-rw-r--r--js/reader.js2
-rw-r--r--read.html1
4 files changed, 35 insertions, 1 deletions
diff --git a/backend.php b/backend.php
index 4f4b402..4ed612b 100644
--- a/backend.php
+++ b/backend.php
@@ -231,6 +231,15 @@
 
 		break;
 
+	case "wikisearch":
+		$query = urlencode(strip_tags($_REQUEST['query']));
+		$url = "https://en.wiktionary.org/w/api.php?titles=${query}&action=query&prop=extracts&format=json&exlimit=1";
+
+		if ($resp = file_get_contents($url)) {
+			print $resp;
+		}
+
+		break;
 	case "define":
 
 		if (defined('DICT_ENABLED') && DICT_ENABLED) {
diff --git a/js/read.js b/js/read.js
index dd3c3f4..de75072 100644
--- a/js/read.js
+++ b/js/read.js
@@ -344,6 +344,30 @@ function init_reader() {
 		window.open("https://duckduckgo.com/?q=" + $(".dict_query").val());
 	});
 
+	$(".wiki_search_btn").on("click", function() {
+		$(".dict_result").html("Loading, please wait...");
+
+		$.post("backend.php", {op: "wikisearch", query: $(".dict_query").val()})
+			.then((resp) => {
+				try {
+					let tmp = "";
+
+					$.each(resp.query.pages, (i,p) => {
+						tmp += p.extract;
+					});
+
+					$(".dict_result").html(tmp && tmp != "undefined" ? tmp : "No definition found for " + $(".dict_query").val() + ".");
+				} catch (e) {
+					console.error(e);
+					$(".dict_result").text("Error while processing data: " + e);
+				}
+			})
+			.fail((e) => {
+				console.error(e);
+				$(".dict_result").text("Error while retrieving data.");
+			})
+	});
+
 	function toc_loc_msg(href) {
 		try {
 			const cfiBase = book.spine.get(href).cfiBase;
diff --git a/js/reader.js b/js/reader.js
index cfb16a8..537835a 100644
--- a/js/reader.js
+++ b/js/reader.js
@@ -18,7 +18,7 @@ $(document).ready(function() {
 
 		const sel = getSelection().toString().trim();
 
-		if (!sel.match(/^\w+$/)) {
+		if (sel.match(/^$/)) {
 			parent.toggle_fullscreen();
 		}
 	});
diff --git a/read.html b/read.html
index bf50f4e..46b3fdd 100644
--- a/read.html
+++ b/read.html
@@ -131,6 +131,7 @@
 			<div class="dict_result"> </div>
       </div>
       <div class="modal-footer">
+        <button type="button" class="wiki_search_btn btn-default btn">Wiktionary</button>
         <button type="button" class="dict_search_btn btn-default btn">Web search</button>
         <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
       </div>