From 7a842db949ae42b04d567aeb69fe553752844e80 Mon Sep 17 00:00:00 2001 From: glowinthedark <48893368+glowinthedark@users.noreply.github.com> Date: Fri, 17 Nov 2023 09:37:29 +0100 Subject: [PATCH 1/6] persist and reload page state on page via URL hash Store current dictionary and lookup word in the top page URL hash to allow persisting state on page refresh. Allows reopening a specific article with the lookup word via a top frame URL like - http://127.0.0.1:8013/#/slob/c52148ef-0ac7-47cf-bd0f-c503552ebdd7/awake?blob=155-10&q=awake --- src/script.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/script.js b/src/script.js index 39474f3..de3fbd2 100644 --- a/src/script.js +++ b/src/script.js @@ -16,6 +16,10 @@ $(function () { if (contentLocation.href === "about:blank") { $contentHeader.hide(); } else { + var url = new URL(contentLocation.href); + url.searchParams.set('q', $word.val()); + window.top.location.hash = url.pathname + url.search; + history.pushState("", "", window.top.location.href); var i, slobId, lookupKey, @@ -43,6 +47,17 @@ $(function () { $("#header-title").text(contentLocation.href); } $contentHeader.show(); + $content.contents().find('body').dblclick(function(e) { + var selectedWord = $content.contents()[0].getSelection().toString().trim(); + if (selectedWord) { + $word.val(selectedWord); + doLookup(true); + $content.attr('src', ""); + setTimeout(function(){ + $content.attr('src', $('#lookup-result li:first-child a').attr('href')); + }, 500); + } + }); } } catch (x) { console.warn(x); @@ -115,6 +130,14 @@ $(function () { }); }; + if (window.top.location.hash) { + var itemUrl = window.top.location.hash.slice(1); + var params = new URLSearchParams(itemUrl); + $word.val(params.get('q')); + doLookup(); + $("#content").attr("src", itemUrl); + } + var onInputChange = function () { if (scheduledLookupID) { clearTimeout(scheduledLookupID); From 2757864cc9e064cbc9d3bcf457b162e5c3988e38 Mon Sep 17 00:00:00 2001 From: glowinthedark <48893368+glowinthedark@users.noreply.github.com> Date: Sat, 18 Nov 2023 14:21:32 +0100 Subject: [PATCH 2/6] change doubleclick behaviour to search in the current dictionary only change doubleclick behaviour to search in the current dictionary only --- src/script.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/script.js b/src/script.js index de3fbd2..6c8c16a 100644 --- a/src/script.js +++ b/src/script.js @@ -50,12 +50,11 @@ $(function () { $content.contents().find('body').dblclick(function(e) { var selectedWord = $content.contents()[0].getSelection().toString().trim(); if (selectedWord) { + var $link = $("").attr("href", selectedWord); + $(e.target).append($link); + $link[0].click(); $word.val(selectedWord); doLookup(true); - $content.attr('src', ""); - setTimeout(function(){ - $content.attr('src', $('#lookup-result li:first-child a').attr('href')); - }, 500); } }); } From 9528ed96c3f9a90e85fc2d0cf29aba068d2cfc18 Mon Sep 17 00:00:00 2001 From: glowinthedark <48893368+glowinthedark@users.noreply.github.com> Date: Mon, 20 Nov 2023 18:35:10 +0100 Subject: [PATCH 3/6] open 1st result if content empty - open 1st result after lookup when content empty - cleanup --- src/script.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/script.js b/src/script.js index 6c8c16a..50d4938 100644 --- a/src/script.js +++ b/src/script.js @@ -17,7 +17,9 @@ $(function () { $contentHeader.hide(); } else { var url = new URL(contentLocation.href); - url.searchParams.set('q', $word.val()); + if ($word.val()) { + url.searchParams.set('q', $word.val()); + } window.top.location.hash = url.pathname + url.search; history.pushState("", "", window.top.location.href); var i, @@ -119,21 +121,26 @@ $(function () { var $a = $("") .append($label) .append($dictLabel) - .attr("href", item.url) + .attr("href", item.url.slice(0,-1) + "&q=" + item.label) .attr("target", "content"); $li.append($a); $ul.append($li); return true; }); $lookupResult.append($ul); + if (!$content.attr('src')) { + $content.attr('src', $ul.find('li:first-child a').attr('href')); + } }); }; if (window.top.location.hash) { var itemUrl = window.top.location.hash.slice(1); - var params = new URLSearchParams(itemUrl); - $word.val(params.get('q')); - doLookup(); + var q = new URLSearchParams(new URL(itemUrl, 'http://_').search).get('q'); + if (q) { + $word.val(q); + doLookup(); + } $("#content").attr("src", itemUrl); } From 0cb74e97aede90c423b7f6ec7bf7d8dd6df05726 Mon Sep 17 00:00:00 2001 From: glowinthedark <48893368+glowinthedark@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:05:43 +0100 Subject: [PATCH 4/6] -Dslobber.host=0.0.0.0 --- README.org | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.org b/README.org index 6d686c0..31d678d 100644 --- a/README.org +++ b/README.org @@ -17,6 +17,12 @@ directory). This should open Aard2 web UI page (http://localhost:8013) in the default system browser. + To make the web server available for the entire home/work network add `-Dslobber.host=0.0.0.0`, e.g: + + #+BEGIN_SRC sh + java -Dslobber.browse=true -Dslobber.host=0.0.0.0 -jar aard2-web-0.8.jar ~/Downloads/*.slob + #+END_SRC + To start the web server on a different port, set system property /slobber.port/. For example, to start on port 8014: From 615e8e78aac8f5ec1bbbaf10c546aa9346f451b6 Mon Sep 17 00:00:00 2001 From: glowinthedark <48893368+glowinthedark@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:06:44 +0100 Subject: [PATCH 5/6] -Dslobber.host=0.0.0.0 --- README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.org b/README.org index 31d678d..4bb84d7 100644 --- a/README.org +++ b/README.org @@ -17,7 +17,7 @@ directory). This should open Aard2 web UI page (http://localhost:8013) in the default system browser. - To make the web server available for the entire home/work network add `-Dslobber.host=0.0.0.0`, e.g: + To make the web server available for the entire home/work network add /-Dslobber.host=0.0.0.0/, e.g: #+BEGIN_SRC sh java -Dslobber.browse=true -Dslobber.host=0.0.0.0 -jar aard2-web-0.8.jar ~/Downloads/*.slob From d7a291451004439a87f5252754419c352d00c33a Mon Sep 17 00:00:00 2001 From: glowinthedark <48893368+glowinthedark@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:08:01 +0100 Subject: [PATCH 6/6] -Dslobber.host=0.0.0.0 --- README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.org b/README.org index 4bb84d7..389d319 100644 --- a/README.org +++ b/README.org @@ -17,7 +17,7 @@ directory). This should open Aard2 web UI page (http://localhost:8013) in the default system browser. - To make the web server available for the entire home/work network add /-Dslobber.host=0.0.0.0/, e.g: + To make the web server available for the LAN network add /-Dslobber.host=0.0.0.0/, e.g: #+BEGIN_SRC sh java -Dslobber.browse=true -Dslobber.host=0.0.0.0 -jar aard2-web-0.8.jar ~/Downloads/*.slob