From 337bd2bdf525f4c6d783faacaec4f4189daf1d57 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 24 Jun 2019 09:24:51 +0300 Subject: add basic wiktionary support --- js/read.js | 24 ++++++++++++++++++++++++ js/reader.js | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'js') 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(); } }); -- cgit v1.2.3