Last active
June 14, 2020 05:21
-
-
Save aminnj/86162d5d8abcd8071cd625b864ad0802 to your computer and use it in GitHub Desktop.
live searchable apache index page directory listings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Make sure the local (or global) .htaccess file has the following line | |
ReadmeName after.html | |
--> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.min.js"></script> | |
<style> | |
mark { | |
padding: 0px; | |
color: #f00; | |
background: none; | |
} | |
#filter { | |
margin: 10px; | |
} | |
</style> | |
<script> | |
$(function() { | |
var middlerows = $("tr:not(:first):not(:last)"); | |
console.log(middlerows); | |
var markre = function(pattern) { | |
context=middlerows; | |
context.show(); | |
context.unmark(); | |
var modifier = ""; | |
if (pattern.toLowerCase() == pattern) modifier = "i"; // like :set smartcase in vim (case-sensitive if there's an uppercase char) | |
var regex = new RegExp(pattern,modifier); | |
context.markRegExp(regex,{ | |
done: function(counter) { | |
context.not(":has(mark)").hide(); | |
console.log(counter); | |
if (counter < 1) { | |
context.show(); | |
} | |
}, | |
}); | |
}; | |
$("html").prepend("<input id=\"filter\" placeholder=\"Search/wildcard filter\" />"); | |
$( "input[id='filter']" ).on('keyup', function() { | |
var pattern = $(this).val(); | |
markre(pattern); | |
window.location.hash = escape($("#filter").val()); | |
}); | |
// vimlike incsearch: press / to focus on search box | |
$(document).keydown(function(e) { | |
console.log($(event.target)); | |
console.log(e.keyCode); | |
if(e.keyCode == 191) { | |
// / focus search box | |
e.preventDefault(); | |
$("#filter").focus().select(); | |
} | |
}); | |
if (window.location.hash) { | |
var search = unescape(window.location.hash.split("#")[1]); | |
$("#filter").val(search); | |
markre($("#filter").val()); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment