From c02920607f79c3b36455294eed785398910fe52d Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 18 Oct 2021 21:43:16 +0200 Subject: [PATCH] linkable search results --- copyparty/web/browser.js | 45 +++++++++++++++++++++++----------------- copyparty/web/util.js | 9 ++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index f68d21f5..163ff7ce 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1439,12 +1439,7 @@ function play(tid, is_ev, seek, call_depth) { if (!seek) { var o = ebi(oid); o.setAttribute('id', 'thx_js'); - if (window.history && history.replaceState) { - hist_replace(document.location.pathname + '#' + oid); - } - else { - document.location.hash = oid; - } + sethash(oid); o.setAttribute('id', oid); } @@ -1516,9 +1511,12 @@ function autoplay_blocked(seek) { } -function play_linked() { +function eval_hash() { var v = location.hash; - if (v && v.indexOf('#af-') === 0) { + if (!v) + return; + + if (v.indexOf('#af-') === 0) { var id = v.slice(2).split('&'); if (id[0].length != 10) return; @@ -1532,6 +1530,13 @@ function play_linked() { return play(id[0], false, parseInt(m[1] || 0) * 60 + parseInt(m[2] || 0)); } + + if (v.indexOf('#q=') === 0) { + goto('search'); + var i = ebi('q_raw'); + i.value = uricom_dec(v.slice(3))[0]; + return i.oninput(); + } }; @@ -2725,28 +2730,28 @@ document.onkeydown = function (e) { (function () { var sconf = [ ["size", - ["szl", "sz_min", "minimum MiB", ""], - ["szu", "sz_max", "maximum MiB", ""] + ["szl", "sz_min", "minimum MiB", "16"], + ["szu", "sz_max", "maximum MiB", "16"] ], ["date", - ["dtl", "dt_min", "min. iso8601", ""], - ["dtu", "dt_max", "max. iso8601", ""] + ["dtl", "dt_min", "min. iso8601", "16"], + ["dtu", "dt_max", "max. iso8601", "16"] ], ["path", - ["path", "path", "path contains   (space-separated)", "46"] + ["path", "path", "path contains   (space-separated)", "34"] ], ["name", - ["name", "name", "name contains   (negate with -nope)", "46"] + ["name", "name", "name contains   (negate with -nope)", "34"] ] ]; var oldcfg = []; if (QS('#srch_form.tags')) { sconf.push(["tags", - ["tags", "tags", "tags contains   (^=start, end=$)", "46"] + ["tags", "tags", "tags contains   (^=start, end=$)", "34"] ]); sconf.push(["adv.", - ["adv", "adv", "key>=1A  key<=2B  .bpm>165", "46"] + ["adv", "adv", "key>=1A  key<=2B  .bpm>165", "34"] ]); } @@ -2763,8 +2768,8 @@ document.onkeydown = function (e) { html.push( '\n' + '\n' + - '
'); + '
'); if (csp == 2) break; } @@ -2976,6 +2981,7 @@ document.onkeydown = function (e) { reload_browser(); filecols.set_style(['File Name']); + sethash('q=' + uricom_enc(this.q_raw)); ebi('unsearch').onclick = unsearch; } @@ -2985,6 +2991,7 @@ document.onkeydown = function (e) { ebi('files').innerHTML = orig_html; ebi('files').removeAttribute('q_raw'); orig_html = null; + sethash(''); reload_browser(); } })(); @@ -4447,4 +4454,4 @@ function reload_browser(not_mp) { } reload_browser(true); mukey.render(); -play_linked(); +setTimeout(eval_hash, 1); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 6fb3512f..e82709c8 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -723,6 +723,15 @@ function hist_replace(url) { history.replaceState(url, url, url); } +function sethash(hv) { + if (window.history && history.replaceState) { + hist_replace(document.location.pathname + '#' + hv); + } + else { + document.location.hash = hv; + } +} + var timer = (function () { var r = {};