-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
executable file
·94 lines (92 loc) · 3.85 KB
/
index.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// Uncomment if you're having caching issues
//clearstatcache();
$root = dirname($_SERVER['SCRIPT_NAME']) . '/';
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="<?= $root ?>assets/favicon.png" type="image/png" rel="icon">
<title>Snippets</title>
<link rel="stylesheet" href="<?= $root ?>assets/monokai-sublime.min.css">
<script charset="UTF-8" src="<?= $root ?>assets/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="stylesheet" href="<?= $root ?>assets/style.css">
<script>
function toggle(e) {
if (e.parentElement.getElementsByTagName("UL")[0].style.display === "none" ||getComputedStyle(e.parentElement.getElementsByTagName("UL")[0], null).display === "none") {
e.parentElement.getElementsByTagName("UL")[0].style.display = "block";
e.parentElement.getElementsByTagName("SPAN")[0].className = "shown";
} else {
e.parentElement.getElementsByTagName("UL")[0].style.display = "none";
e.parentElement.getElementsByTagName("SPAN")[0].className = "hidden";
}
}
</script>
</head>
<body>
<div id="wrapper">
<div id="list">
<span class="head">Snippets {}</span>
<ul id="filelist">
<?php
function dirlist($path) {
$root = dirname($_SERVER['SCRIPT_NAME']) . '/';
$entries = array_diff(scandir($path), array('..', '.', '.htaccess'));
foreach ($entries as $entry) {
if (is_dir($path . $entry)) {
printf('<li class="dir"><img src="%sassets/dir.png" class="diricon"/><span onclick="toggle(this)" style="display:inline-block;width:80%%;">%s</span><ul>', $root, $entry);
dirlist($path . $entry . '/');
print('</ul></li>');
}
}
foreach ($entries as $entry) {
if (is_file($path . $entry)) {
printf('<li class="snippet" href="%s">%s<a href="%s" download><img id="download" src="%sassets/download.png" /></a></li>' . "\n", $root . $path . $entry, $entry, $root . $path . $entry, $root);
}
}
}
dirlist('scripts/');
?>
</ul>
<span class="brand"><a href="https://github.com/MaverickEsq/snipbin">snipbin by <img src="<?= $root ?>assets/favicon.ico"></a></span>
</div>
<div id="code"><pre><code><?php
if ($_GET['s'] != '') {
if (file_exists('./scripts/' . $_GET['s'])) {
$file = file_get_contents('./scripts/'.$_GET['s']);
print str_replace(' ', ' ', str_replace('<', '<', $file));
} else {
print "File not found";
}
} else { print 'print "hello world";'; }
?>
</code>
</pre>
</div>
</div>
<script type="text/javascript">
// set 'snippet' as the pre in code in div with class code
let snippet = document.querySelector('#code pre code');
// locate your element and add the Click Event Listener
document.getElementById('filelist').addEventListener("click", changeScript);
function changeScript(e) {
// e.target is our targetted element.
// try doing console.log(e.target.nodeName), it will result LI
if(e.target && e.target.nodeName == "LI") {
if (e.target.getAttribute("class") != 'dir') {
console.log(e.target.textContent + " was clicked");
fetch(e.target.getAttribute("href"), {headers: new Headers({'X-Requested-With': 'XMLHttpRequest'})})
.then(response => response.text()).then(text => {
snippet.innerHTML = text.replace(/</g, '<').replace(/ /g, ' ') + "\n\n\n";
snippet.removeAttribute("class");
hljs.highlightBlock(snippet);
window.history.pushState('script change', 'Snippets', e.target.getAttribute("href").replace('scripts/', ''));
});
}
}
}
</script>
</body>
</html>