-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_file_browser.sh
63 lines (47 loc) · 1.52 KB
/
html_file_browser.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Browse local HTML files in a folder using "Previous" and "Next" buttons, like (for example) Windows Photo Viewer does for image files
# Based on http://stackoverflow.com/a/8786346
#
# Edit "my_files" path below, run and save output in .html file, and open it to start browsing
#
# _Very_ basic URL encoding implemented, as some browsers will not open the file instead
echo '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Browse all HTML files in directory</title>
<script>
var cnt = -1;
var webpageArray = ['
for htmlFile in my_files/*.html
do
htmlFileUrlEnc=$(echo $htmlFile | sed 's/#/%23/g')
echo \"$htmlFileUrlEnc\",
done
echo ' ];
function loadNextPage(dir) {
cnt+=dir;
if (cnt<0)
cnt=webpageArray.length-1; // wrap
else if (cnt>= webpageArray.length)
cnt=0; // wrap
var iframe = document.getElementById("myframe");
iframe.src = webpageArray[cnt];
fileCurrent.innerHTML = webpageArray[cnt];
filePos.innerHTML = (cnt+1) + "/" + webpageArray.length;
return false; // mandatory!
}
</script>
</head>
<body>
<a href="#" onclick="return loadNextPage(-1)"> << Previous </a> |
<a href="#" onclick="return loadNextPage(1)"> Next >> </a>
<div style="display:inline; font-family:monospace" id="fileCurrent">about:blank</div>
<div style="display:inline" id="filePos"></div>
<br>
<iframe width="90%" height="90%" id="myframe" src="about:blank"></iframe>
</body>
</html>
'