From d4ce7bab20f42c64472ff3c0b0cc0d195993fb9c Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Tue, 25 Sep 2018 10:26:51 +0300 Subject: [PATCH] new stuff --- example_links.txt | 16 ++++++++++++++++ index.html | 35 +++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/example_links.txt b/example_links.txt index 1182736..37512db 100644 --- a/example_links.txt +++ b/example_links.txt @@ -40,3 +40,19 @@ are parsed. [Source file](example_links.txt) [Additional config](config.js) [Project homepage](https://bitbucket.org/MoonQ/mdlinks) + +# Advanced +## Parsing the request + +[Open pages in new window](?blank) +[Predefined filter](?filter=predefined) + +## Keyboard + +- N: toggle new window opening +- C: clear filter +- S: enter filter editor + + + + diff --git a/index.html b/index.html index 76194aa..9ab3554 100644 --- a/index.html +++ b/index.html @@ -80,6 +80,7 @@ function init() { print_results(hitList); fold_initial(); scroll_load(); + parse_request(); } function narrow_window() { return window.innerWidth < config.narrow; @@ -141,6 +142,7 @@ function filter(ev) { var c=hitList.length; var lastHit=hitList[c-1]; print_results(hitList); + if (ev == null) { return } var key=ev.keyCode; if (key==13){ if (c==0) { document.getElementById('filter').focus(); } @@ -273,9 +275,26 @@ function parse_links(s) { linkList=links.slice(0); init(); } + +function parse_request() { + var request = window.location.search.substring(1); + var vars = request.split('&'); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split('='); + if (decodeURIComponent(pair[0]) == "blank") { + toggle_blank(); + } + if (decodeURIComponent(pair[0]) == "filter") { + var value = decodeURIComponent(pair[1]); + document.getElementById("filter").value = value; + filter(null); + } + } +} + function keyboard_entry(ev) { - var kC=ev.keyCode; - var k=String.fromCharCode(ev.keyCode); + var kC = ev.keyCode; + var k = String.fromCharCode(ev.keyCode); if ( document.activeElement === document.getElementById("filter")) { return } @@ -294,13 +313,13 @@ function toggle_blank() { var span=document.getElementById('open_blank_span'); var arrow=document.getElementById('open_blank_arrow'); if (span.attributes['data']) { - if ( span.attributes['data']=="true" ) { - span.attributes['data']="false"; + if ( span.attributes['data'] == "true" ) { + span.attributes['data'] = "false"; } else { - span.attributes['data']="true"; + span.attributes['data'] = "true"; } } else { - span.attributes['data']="true" + span.attributes['data'] = "true"; } var blank=span.attributes['data']=="true"; var anchors = document.getElementsByTagName('a'); @@ -421,9 +440,9 @@ function fold_set_state(state) { } function set_cookie(name,value) { - // Save cookies for 2 hours + // Save cookies for 30 minutes document.cookie = name + "=" + value.toString() + "&" + window.location.pathname + - ";path=" + window.location.pathname + ";max-age="+ (60*60*2).toString() + ";"; + ";path=" + window.location.pathname + ";max-age="+ (60 * 30).toString() + ";"; } function clear() {