-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrawgithub.html
More file actions
160 lines (135 loc) · 6.63 KB
/
Copy pathrawgithub.html
File metadata and controls
160 lines (135 loc) · 6.63 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index of /</title>
<style>
body { font-family: monospace; background: #fff; color: #000; padding: 20px; }
h1 { font-size: 1.5em; margin-bottom: 5px; }
hr { border: 0; border-top: 1px solid #000; margin: 10px 0; }
table { width: 100%; max-width: 1000px; border-collapse: collapse; text-align: left; }
th, td { padding: 2px 10px; white-space: nowrap; }
th { border-bottom: 1px solid #000; }
a { color: #0000ee; text-decoration: none; }
a:hover { text-decoration: underline; }
.size, .preview-th, .preview-td { text-align: right; }
.preview-box { max-width: 80px; max-height: 60px; object-fit: cover; border: 1px solid #ccc; display: block; margin-left: auto;}
.loading { font-style: italic; color: #555; }
</style>
</head>
<body>
<h1 id="index-title">Index of /</h1>
<hr>
<div id="loading-text" class="loading">Loading directory contents...</div>
<table id="dir-table" style="display: none;">
<thead>
<tr>
<th width="5%">Icon</th>
<th width="45%">Name</th>
<th width="15%" class="size">Size</th>
<th width="35%" class="preview-th">Preview / Actions</th>
</tr>
</thead>
<tbody id="dir-list">
</tbody>
</table>
<hr>
<address>Apache/2.4.41 Server at GitHub API (Tailored for Frijal)</address>
<script>
// --- KONFIGURASI AWAL ---
const USERNAME = 'frijal';
const REPO = 'LayarKosong';
const BRANCH = 'main';
// Folder awal (root dari galeri kamu di repo). Contoh: 'assets/photos'
// Jika ingin mulai dari root repo, biarkan kosong ''
const BASE_FOLDER = 'img';
// State untuk menyimpan path aktif saat ini
let currentPath = BASE_FOLDER;
// Fungsi format ukuran file ala Apache (K, M)
function formatSize(bytes) {
if (bytes === undefined || bytes === null) return '-';
if (bytes === 0) return '0K';
const k = 1024;
const sizes = ['B', 'K', 'M', 'G'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
if (i === 0) return bytes + 'B';
return (bytes / Math.pow(k, i)).toFixed(1) + sizes[i];
}
async function loadDirectory(path) {
const loadingText = document.getElementById('loading-text');
const dirTable = document.getElementById('dir-table');
const dirList = document.getElementById('dir-list');
const indexTitle = document.getElementById('index-title');
loadingText.style.display = 'block';
dirTable.style.display = 'none';
dirList.innerHTML = '';
// Update Judul Halaman
indexTitle.innerText = `Index of /${path}`;
const url = `https://api.github.com/repos/${USERNAME}/${REPO}/contents/${path}?ref=${BRANCH}`;
try {
const response = await fetch(url);
if (!response.ok) throw new Error('Directory tidak ditemukan');
const items = await response.json();
loadingText.style.display = 'none';
dirTable.style.display = 'table';
// 1. Tambahkan tombol "Parent Directory" (Back) jika tidak di BASE_FOLDER
if (path !== BASE_FOLDER && path !== '') {
const pathParts = path.split('/');
pathParts.pop();
const parentPath = pathParts.join('/');
const row = document.createElement('tr');
row.innerHTML = `
<td>📁</td>
<td><a href="#" onclick="changeDir('${parentPath}'); return false;">Parent Directory</a></td>
<td class="size">-</td>
<td class="preview-td"></td>
`;
dirList.appendChild(row);
}
// Pisahkan folder dan file agar folder selalu muncul di atas (khas Apache)
const folders = items.filter(i => i.type === 'dir');
const files = items.filter(i => i.type === 'file');
// 2. Render Folders
folders.forEach(item => {
const row = document.createElement('tr');
row.innerHTML = `
<td>📁</td>
<td><a href="#" onclick="changeDir('${item.path}'); return false;">${item.name}/</a></td>
<td class="size">-</td>
<td class="preview-td">Go inside</td>
`;
dirList.appendChild(row);
});
// 3. Render Files (Filter hanya file gambar untuk preview)
const imgExts = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'avif'];
files.forEach(item => {
const ext = item.name.split('.').pop().toLowerCase();
const isImage = imgExts.includes(ext);
const row = document.createElement('tr');
// Gunakan CDN Statically untuk thumbnail biar ga berat
const thumbUrl = `https://img.statically.io/img/raw.githubusercontent.com/${USERNAME}/${REPO}/${BRANCH}/${item.path}?w=80&h=60&f=webp`;
row.innerHTML = `
<td>📄</td>
<td><a href="${item.download_url}" target="_blank" download="${item.name}">${item.name}</a></td>
<td class="size">${formatSize(item.size)}</td>
<td class="preview-td">
${isImage ? `<a href="${item.download_url}" target="_blank"><img src="${thumbUrl}" class="preview-box" title="Klik untuk lihat ukuran penuh"></a>` : `<a href="${item.download_url}" download>Download</a>`}
</td>
`;
dirList.appendChild(row);
});
} catch (error) {
loadingText.innerText = `Error: ${error.message}. Pastikan path dan repo benar, Jal!`;
}
}
// Fungsi hander untuk berpindah folder secara dinamis tanpa reload halaman
function changeDir(newPath) {
currentPath = newPath;
loadDirectory(currentPath);
}
// Jalankan pertama kali
loadDirectory(currentPath);
</script>
</body>
</html>