(function() { console.log('HacKing'); const style = document.createElement('style'); const styleContent = ` * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; } #hack4king-loader { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: radial-gradient(circle at top, #0a0a0a 0%, #000000 100%); z-index: 100000; display: none; flex-direction: column; overflow: hidden; } #hack4king-loader.active { display: flex; } .hk-nav { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); width: min(1100px, 95%); backdrop-filter: blur(16px); background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 999px; padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; z-index: 20; } .hk-nav-logo { font-size: 22px; font-weight: 700; background: linear-gradient(90deg, #fff, #aaa, #fff); -webkit-background-clip: text; background-clip: text; color: transparent; } .hk-nav-controls { display: flex; gap: 18px; align-items: center; } .hk-nav-btn { background: transparent; border: none; color: #bbb; font-size: 14px; cursor: pointer; transition: color 0.3s; font-family: inherit; } .hk-nav-btn:hover { color: #fff; } .hk-main-container { flex: 1; display: flex; padding-top: 100px; justify-content: center; overflow: hidden; } .hk-glass-card { width: min(1300px, 95%); background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(0,0,0,0.4)); border: 1px solid rgba(255,255,255,0.1); border-radius: 32px; backdrop-filter: blur(20px); position: relative; overflow: hidden; display: flex; flex-direction: column; height: calc(100vh - 120px); } .hk-glass-card::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at top, rgba(255,255,255,0.1), transparent 70%); pointer-events: none; } .hk-content-layout { display: flex; flex: 1; overflow: hidden; position: relative; z-index: 1; } .hk-sidebar { width: 280px; background: rgba(0,0,0,0.3); border-right: 1px solid rgba(255,255,255,0.08); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; } .hk-sidebar-header { padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.08); } .hk-search-input { width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; padding: 10px 14px; color: #fff; font-size: 14px; outline: none; transition: 0.3s; } .hk-search-input:focus { border-color: rgba(255,255,255,0.3); background: rgba(255,255,255,0.08); } .hk-category-filter { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; } .hk-category-btn { background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 20px; padding: 4px 12px; font-size: 11px; cursor: pointer; color: #aaa; transition: 0.3s; } .hk-category-btn:hover { background: rgba(255,255,255,0.1); color: #fff; } .hk-category-btn.active { background: rgba(255,255,255,0.2); color: #fff; border-color: rgba(255,255,255,0.2); } .hk-stats { font-size: 11px; color: #666; margin-top: 12px; } .hk-script-list { flex: 1; overflow-y: auto; padding: 10px 0; } .hk-script-item { padding: 12px 20px; cursor: pointer; display: flex; align-items: center; gap: 12px; transition: 0.2s; border-left: 3px solid transparent; } .hk-script-item:hover { background: rgba(255,255,255,0.05); } .hk-script-item.active { background: rgba(255,255,255,0.08); border-left-color: #fff; } .hk-script-icon { font-size: 18px; } .hk-script-info { flex: 1; min-width: 0; } .hk-script-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .hk-script-meta-sm { font-size: 10px; color: #666; margin-top: 2px; } .hk-script-badge { background: rgba(255,255,255,0.08); padding: 2px 8px; border-radius: 12px; font-size: 10px; color: #aaa; } .hk-pagination { display: flex; justify-content: center; gap: 8px; padding: 15px; border-top: 1px solid rgba(255,255,255,0.08); } .hk-page-btn { background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 12px; color: #aaa; transition: 0.2s; } .hk-page-btn:hover { background: rgba(255,255,255,0.1); color: #fff; } .hk-page-btn.active { background: rgba(255,255,255,0.2); color: #fff; } .hk-main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; } .hk-script-viewer { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 24px; } .hk-file-drop { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 40px; border: 2px dashed rgba(255,255,255,0.2); border-radius: 32px; background: rgba(255,255,255,0.02); cursor: pointer; transition: 0.3s; } .hk-file-drop:hover { border-color: rgba(255,255,255,0.4); background: rgba(255,255,255,0.05); } .hk-file-drop.dragover { border-color: #fff; background: rgba(255,255,255,0.1); transform: scale(1.02); } .hk-file-icon { font-size: 64px; margin-bottom: 20px; opacity: 0.7; } .hk-file-text { font-size: 18px; margin-bottom: 10px; color: #fff; } .hk-file-hint { font-size: 12px; color: #666; } .hk-script-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.08); } .hk-script-title { font-size: 20px; font-weight: 600; } .hk-script-meta { font-size: 12px; color: #666; margin-top: 5px; } .hk-script-actions { display: flex; gap: 10px; } .hk-btn { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; padding: 8px 16px; font-size: 13px; cursor: pointer; color: #fff; transition: 0.2s; font-family: inherit; } .hk-btn:hover { background: rgba(255,255,255,0.12); transform: translateY(-1px); } .hk-btn.danger { border-color: rgba(255,68,68,0.3); color: #ff6666; } .hk-btn.danger:hover { background: rgba(255,68,68,0.15); } .hk-btn.success { border-color: rgba(68,255,68,0.3); color: #66ff66; } .hk-btn.success:hover { background: rgba(68,255,68,0.1); } .hk-code-container { flex: 1; display: flex; flex-direction: column; background: rgba(0,0,0,0.4); border-radius: 20px; overflow: hidden; margin-bottom: 15px; } .hk-code-toolbar { padding: 12px 16px; background: rgba(0,0,0,0.3); border-bottom: 1px solid rgba(255,255,255,0.08); display: flex; gap: 10px; align-items: center; } .hk-code-viewer { flex: 1; padding: 20px; overflow: auto; font-family: 'Fira Code', 'Consolas', monospace; font-size: 12px; line-height: 1.5; color: #ccc; white-space: pre-wrap; } .hk-log-area { background: rgba(0,0,0,0.4); border-radius: 20px; overflow: hidden; height: 180px; display: flex; flex-direction: column; } .hk-log-header { padding: 10px 16px; background: rgba(0,0,0,0.3); border-bottom: 1px solid rgba(255,255,255,0.08); font-size: 12px; font-weight: 600; letter-spacing: 0.5px; } .hk-log-content { flex: 1; padding: 12px; overflow-y: auto; font-family: monospace; font-size: 11px; } .hk-log-line { margin: 4px 0; padding: 2px 8px; border-left: 2px solid transparent; } .hk-log-line.info { border-left-color: #3b82f6; color: #94a3b8; } .hk-log-line.success { border-left-color: #22c55e; color: #86efac; } .hk-log-line.error { border-left-color: #ef4444; color: #fca5a5; } .hk-log-line.warning { border-left-color: #eab308; color: #fde047; } .hk-empty-state { text-align: center; padding: 60px 20px; color: #666; } .hk-empty-state .icon { font-size: 48px; margin-bottom: 15px; opacity: 0.5; } #hk-activator { position: fixed; bottom: 30px; right: 30px; width: 56px; height: 56px; border-radius: 28px; background: linear-gradient(135deg, #fff, #aaa); border: none; font-size: 24px; cursor: pointer; z-index: 99999; box-shadow: 0 4px 20px rgba(0,0,0,0.3); transition: 0.3s; color: #000; } #hk-activator:hover { transform: scale(1.1); box-shadow: 0 6px 25px rgba(0,0,0,0.4); } ::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 3px; } ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; } ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); } `; if (style.styleSheet) { style.styleSheet.cssText = styleContent; } else { style.appendChild(document.createTextNode(styleContent)); } document.head.appendChild(style); const gui = document.createElement('div'); const loader = document.createElement('div'); loader.id = 'hack4king-loader'; const nav = document.createElement('div'); nav.className = 'hk-nav'; const logo = document.createElement('div'); logo.className = 'hk-nav-logo'; logo.textContent = '⚡ HACK4KING'; const navControls = document.createElement('div'); navControls.className = 'hk-nav-controls'; const runAllNavBtn = document.createElement('button'); runAllNavBtn.className = 'hk-nav-btn'; runAllNavBtn.textContent = '▶ RUN ALL'; runAllNavBtn.onclick = function() { window.hkRunAll && window.hkRunAll(); }; const clearAllNavBtn = document.createElement('button'); clearAllNavBtn.className = 'hk-nav-btn'; clearAllNavBtn.textContent = '🗑 CLEAR'; clearAllNavBtn.onclick = function() { window.hkClearAll && window.hkClearAll(); }; const closeNavBtn = document.createElement('button'); closeNavBtn.className = 'hk-nav-btn'; closeNavBtn.textContent = '✕ CLOSE'; closeNavBtn.onclick = function() { window.hkClose && window.hkClose(); }; navControls.appendChild(runAllNavBtn); navControls.appendChild(clearAllNavBtn); navControls.appendChild(closeNavBtn); nav.appendChild(logo); nav.appendChild(navControls); const mainContainer = document.createElement('div'); mainContainer.className = 'hk-main-container'; const glassCard = document.createElement('div'); glassCard.className = 'hk-glass-card'; const contentLayout = document.createElement('div'); contentLayout.className = 'hk-content-layout'; const sidebar = document.createElement('div'); sidebar.className = 'hk-sidebar'; const sidebarHeader = document.createElement('div'); sidebarHeader.className = 'hk-sidebar-header'; const searchBox = document.createElement('input'); searchBox.type = 'text'; searchBox.className = 'hk-search-input'; searchBox.placeholder = 'Search scripts...'; searchBox.oninput = function(e) { window.hkFilterScripts && window.hkFilterScripts(e.target.value); }; const categoryFilter = document.createElement('div'); categoryFilter.className = 'hk-category-filter'; categoryFilter.id = 'hk-category-filter'; const statsDiv = document.createElement('div'); statsDiv.className = 'hk-stats'; statsDiv.id = 'hk-stats'; statsDiv.textContent = '0 scripts'; sidebarHeader.appendChild(searchBox); sidebarHeader.appendChild(categoryFilter); sidebarHeader.appendChild(statsDiv); const scriptList = document.createElement('div'); scriptList.className = 'hk-script-list'; scriptList.id = 'hk-script-nav'; const emptyState = document.createElement('div'); emptyState.className = 'hk-empty-state'; const emptyIcon = document.createElement('div'); emptyIcon.className = 'icon'; emptyIcon.textContent = '📁'; const emptyText = document.createElement('div'); emptyText.textContent = 'No scripts loaded'; emptyState.appendChild(emptyIcon); emptyState.appendChild(emptyText); scriptList.appendChild(emptyState); const pagination = document.createElement('div'); pagination.className = 'hk-pagination'; pagination.id = 'hk-pagination'; pagination.style.display = 'none'; sidebar.appendChild(sidebarHeader); sidebar.appendChild(scriptList); sidebar.appendChild(pagination); const mainArea = document.createElement('div'); mainArea.className = 'hk-main-area'; const scriptViewer = document.createElement('div'); scriptViewer.className = 'hk-script-viewer'; scriptViewer.id = 'hk-script-viewer'; scriptViewer.style.display = 'none'; const scriptHeader = document.createElement('div'); scriptHeader.className = 'hk-script-header'; const headerInfo = document.createElement('div'); const scriptTitle = document.createElement('div'); scriptTitle.className = 'hk-script-title'; scriptTitle.id = 'current-script-title'; scriptTitle.textContent = 'No script selected'; const scriptMeta = document.createElement('div'); scriptMeta.className = 'hk-script-meta'; scriptMeta.id = 'current-script-meta'; headerInfo.appendChild(scriptTitle); headerInfo.appendChild(scriptMeta); const scriptActions = document.createElement('div'); scriptActions.className = 'hk-script-actions'; const runBtn = document.createElement('button'); runBtn.className = 'hk-btn success'; runBtn.textContent = '▶ RUN'; runBtn.onclick = function() { window.hkRunCurrent && window.hkRunCurrent(); }; const deleteBtn = document.createElement('button'); deleteBtn.className = 'hk-btn danger'; deleteBtn.textContent = 'DELETE'; deleteBtn.onclick = function() { window.hkDeleteCurrent && window.hkDeleteCurrent(); }; const addMoreBtn = document.createElement('button'); addMoreBtn.className = 'hk-btn'; addMoreBtn.textContent = '+ ADD'; addMoreBtn.onclick = function() { window.hkShowUpload && window.hkShowUpload(); }; scriptActions.appendChild(runBtn); scriptActions.appendChild(deleteBtn); scriptActions.appendChild(addMoreBtn); scriptHeader.appendChild(headerInfo); scriptHeader.appendChild(scriptActions); const codeContainer = document.createElement('div'); codeContainer.className = 'hk-code-container'; const codeToolbar = document.createElement('div'); codeToolbar.className = 'hk-code-toolbar'; const copyBtn = document.createElement('button'); copyBtn.className = 'hk-btn'; copyBtn.textContent = 'COPY'; copyBtn.onclick = function() { window.hkCopyCode && window.hkCopyCode(); }; const exportBtn = document.createElement('button'); exportBtn.className = 'hk-btn'; exportBtn.textContent = 'EXPORT'; exportBtn.onclick = function() { window.hkExportScript && window.hkExportScript(); }; const spacer = document.createElement('div'); spacer.style.flex = '1'; const codeStats = document.createElement('div'); codeStats.style.color = '#666'; codeStats.style.fontSize = '11px'; const codeLinesSpan = document.createElement('span'); codeLinesSpan.id = 'code-lines'; codeLinesSpan.textContent = '0'; const codeSizeSpan = document.createElement('span'); codeSizeSpan.id = 'code-size'; codeSizeSpan.textContent = '0'; codeStats.appendChild(document.createTextNode('Lines: ')); codeStats.appendChild(codeLinesSpan); codeStats.appendChild(document.createTextNode(' | Size: ')); codeStats.appendChild(codeSizeSpan); codeStats.appendChild(document.createTextNode(' B')); codeToolbar.appendChild(copyBtn); codeToolbar.appendChild(exportBtn); codeToolbar.appendChild(spacer); codeToolbar.appendChild(codeStats); const codeViewer = document.createElement('div'); codeViewer.className = 'hk-code-viewer'; codeViewer.id = 'hk-code-viewer'; codeViewer.textContent = '// Select a script to view code'; codeContainer.appendChild(codeToolbar); codeContainer.appendChild(codeViewer); const logArea = document.createElement('div'); logArea.className = 'hk-log-area'; const logHeader = document.createElement('div'); logHeader.className = 'hk-log-header'; logHeader.textContent = 'EXECUTION LOG'; const logContent = document.createElement('div'); logContent.className = 'hk-log-content'; logContent.id = 'hk-log-content'; logContent.textContent = '> Ready for execution'; logArea.appendChild(logHeader); logArea.appendChild(logContent); scriptViewer.appendChild(scriptHeader); scriptViewer.appendChild(codeContainer); scriptViewer.appendChild(logArea); const fileDrop = document.createElement('div'); fileDrop.id = 'hk-file-drop'; fileDrop.className = 'hk-file-drop'; fileDrop.style.display = 'none'; const fileIconEl = document.createElement('div'); fileIconEl.className = 'hk-file-icon'; fileIconEl.textContent = '📁'; const fileTextEl = document.createElement('div'); fileTextEl.className = 'hk-file-text'; fileTextEl.textContent = 'DROP FILES HERE'; const fileHintEl = document.createElement('div'); fileHintEl.className = 'hk-file-hint'; fileHintEl.textContent = '.hack4king, .js, .txt'; const fileInput = document.createElement('input'); fileInput.type = 'file'; fileInput.id = 'hk-file-input'; fileInput.multiple = true; fileInput.accept = '.hack4king,.js,.txt'; fileInput.style.display = 'none'; const backBtn = document.createElement('button'); backBtn.className = 'hk-btn'; backBtn.textContent = '← BACK TO SCRIPTS'; backBtn.style.marginTop = '20px'; backBtn.onclick = function() { window.hkShowScripts && window.hkShowScripts(); }; fileDrop.appendChild(fileIconEl); fileDrop.appendChild(fileTextEl); fileDrop.appendChild(fileHintEl); fileDrop.appendChild(fileInput); fileDrop.appendChild(backBtn); mainArea.appendChild(scriptViewer); mainArea.appendChild(fileDrop); contentLayout.appendChild(sidebar); contentLayout.appendChild(mainArea); glassCard.appendChild(contentLayout); mainContainer.appendChild(glassCard); loader.appendChild(nav); loader.appendChild(mainContainer); const activator = document.createElement('button'); activator.id = 'hk-activator'; activator.textContent = '📜'; activator.onclick = function() { window.hkToggle && window.hkToggle(); }; gui.appendChild(loader); gui.appendChild(activator); document.body.appendChild(gui); let scripts = []; let filteredScripts = []; let currentScriptIndex = -1; let currentPage = 0; const scriptsPerPage = 15; let searchQuery = ''; let currentCategory = 'all'; function init() { loadSavedScripts(); setupDragDrop(); setupFileInput(); updateCategories(); updateStats(); if (scripts.length > 0) { window.hkShowScripts(); } else { window.hkShowUpload(); } logMessage('System initialized', 'info'); } function setupDragDrop() { fileDrop.addEventListener('click', (e) => { if (e.target !== backBtn && e.target !== fileInput) { fileInput.value = ''; fileInput.click(); } }); ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { fileDrop.addEventListener(eventName, preventDefaults, false); }); ['dragenter', 'dragover'].forEach(eventName => { fileDrop.addEventListener(eventName, () => { fileDrop.classList.add('dragover'); }, false); }); ['dragleave', 'drop'].forEach(eventName => { fileDrop.addEventListener(eventName, () => { fileDrop.classList.remove('dragover'); }, false); }); fileDrop.addEventListener('drop', handleDrop, false); } function setupFileInput() { const input = document.getElementById('hk-file-input'); if (input) { input.addEventListener('change', function(e) { if (this.files && this.files.length > 0) { processFiles(this.files); this.value = ''; } }); } } function preventDefaults(e) { e.preventDefault(); e.stopPropagation(); } function handleDrop(e) { const dt = e.dataTransfer; const files = dt.files; if (files.length > 0) { processFiles(files); } } function isValidExtension(filename) { const ext = filename.toLowerCase().split('.').pop(); return ['hack4king', 'js', 'txt'].includes(ext); } function processFiles(fileList) { const validFiles = []; const invalidFiles = []; for (let file of fileList) { if (isValidExtension(file.name)) { validFiles.push(file); } else { invalidFiles.push(file.name); } } if (invalidFiles.length > 0) { logMessage(`Rejected ${invalidFiles.length} file(s) with invalid extensions`, 'warning'); } if (validFiles.length === 0) { if (invalidFiles.length > 0) { alert('Only .hack4king, .js and .txt files are allowed!'); } return; } logMessage(`Loading ${validFiles.length} valid file(s)...`, 'info'); let loadedCount = 0; let errorCount = 0; const processNextFile = (index) => { if (index >= validFiles.length) { saveScripts(); updateCategories(); filterAndRender(); updateStats(); if (loadedCount > 0) { window.hkShowScripts(); selectScript(scripts.length - 1); } logMessage(`Complete: ${loadedCount} loaded, ${errorCount} failed`, errorCount === 0 ? 'success' : 'warning'); return; } const file = validFiles[index]; const reader = new FileReader(); reader.onload = function(e) { try { const content = e.target.result; if (content.length > 1024 * 1024) { logMessage(`File too large: ${file.name}`, 'error'); errorCount++; processNextFile(index + 1); return; } const script = { id: Date.now() + index + Math.random(), name: file.name.replace(/\.[^/.]+$/, ""), filename: file.name, extension: file.name.split('.').pop().toLowerCase(), code: content, size: file.size, loadedAt: new Date().toLocaleString(), lines: content.split('\n').length, category: getCategoryFromExtension(file.name.split('.').pop().toLowerCase()) }; scripts.push(script); loadedCount++; logMessage(`Loaded: ${file.name}`, 'success'); processNextFile(index + 1); } catch (error) { errorCount++; logMessage(`Error reading ${file.name}: ${error.message}`, 'error'); processNextFile(index + 1); } }; reader.onerror = function() { errorCount++; logMessage(`Failed to read: ${file.name}`, 'error'); processNextFile(index + 1); }; reader.readAsText(file); }; processNextFile(0); } function getCategoryFromExtension(ext) { switch(ext) { case 'hack4king': return 'hacks'; case 'js': return 'scripts'; case 'txt': return 'text'; default: return 'other'; } } function formatSize(bytes) { if (bytes < 1024) return bytes; if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + 'K'; return (bytes / (1024 * 1024)).toFixed(1) + 'M'; } function logMessage(message, type = 'info') { const line = document.createElement('div'); line.className = `hk-log-line ${type}`; line.textContent = `> ${new Date().toLocaleTimeString()} ${message}`; logContent.appendChild(line); logContent.scrollTop = logContent.scrollHeight; console.log(`[Hack4King] ${message}`); } function saveScripts() { try { const dataToSave = scripts.map(script => ({ id: script.id, name: script.name, filename: script.filename, extension: script.extension, code: script.code, size: script.size, loadedAt: script.loadedAt, lines: script.lines, category: script.category })); localStorage.setItem('hack4king_scripts', JSON.stringify(dataToSave)); } catch (error) { logMessage(`Failed to save scripts: ${error.message}`, 'error'); } } function loadSavedScripts() { try { const saved = localStorage.getItem('hack4king_scripts'); if (saved) { const data = JSON.parse(saved); scripts = data.map(script => ({ ...script, category: script.category || getCategoryFromExtension(script.extension) })); if (scripts.length > 0) { logMessage(`Loaded ${scripts.length} saved script(s)`, 'success'); } } } catch (error) { logMessage(`Failed to load saved scripts: ${error.message}`, 'error'); } } function updateCategories() { const categories = ['all', 'hacks', 'scripts', 'text', 'other']; const categoryCounts = { 'all': scripts.length, 'hacks': scripts.filter(s => s.category === 'hacks').length, 'scripts': scripts.filter(s => s.category === 'scripts').length, 'text': scripts.filter(s => s.category === 'text').length, 'other': scripts.filter(s => s.category === 'other').length }; categoryFilter.innerHTML = ''; categories.forEach(cat => { if (categoryCounts[cat] > 0 || cat === 'all') { const btn = document.createElement('button'); btn.className = `hk-category-btn ${currentCategory === cat ? 'active' : ''}`; btn.textContent = `${cat} (${categoryCounts[cat]})`; btn.onclick = () => { currentCategory = cat; filterAndRender(); }; categoryFilter.appendChild(btn); } }); } function filterAndRender() { if (searchQuery) { filteredScripts = scripts.filter(script => (script.name.toLowerCase().includes(searchQuery) || script.filename.toLowerCase().includes(searchQuery) || script.code.toLowerCase().includes(searchQuery)) && (currentCategory === 'all' || script.category === currentCategory) ); } else { filteredScripts = currentCategory === 'all' ? [...scripts] : scripts.filter(s => s.category === currentCategory); } currentPage = 0; renderScriptNavigation(); updateStats(); } window.hkFilterScripts = function(query) { searchQuery = query.toLowerCase(); filterAndRender(); }; function updateStats() { const total = scripts.length; const filtered = filteredScripts.length; let statsText = `${filtered} scripts`; if (currentCategory !== 'all') { statsText += ` in ${currentCategory}`; } if (searchQuery && filtered !== total) { statsText += ` (filtered)`; } statsDiv.textContent = statsText; } function renderScriptNavigation() { scriptList.innerHTML = ''; if (filteredScripts.length === 0) { const emptyStateDiv = document.createElement('div'); emptyStateDiv.className = 'hk-empty-state'; const emptyIconDiv = document.createElement('div'); emptyIconDiv.className = 'icon'; emptyIconDiv.textContent = searchQuery ? '🔍' : '📁'; const emptyTextDiv = document.createElement('div'); emptyTextDiv.textContent = searchQuery ? 'No scripts found' : 'No scripts loaded'; emptyStateDiv.appendChild(emptyIconDiv); emptyStateDiv.appendChild(emptyTextDiv); scriptList.appendChild(emptyStateDiv); pagination.style.display = 'none'; return; } const totalPages = Math.ceil(filteredScripts.length / scriptsPerPage); const startIndex = currentPage * scriptsPerPage; const endIndex = Math.min(startIndex + scriptsPerPage, filteredScripts.length); const pageScripts = filteredScripts.slice(startIndex, endIndex); pageScripts.forEach((script) => { const globalIndex = scripts.findIndex(s => s.id === script.id); const isActive = globalIndex === currentScriptIndex; const item = document.createElement('div'); item.className = `hk-script-item ${isActive ? 'active' : ''}`; item.onclick = () => selectScript(globalIndex); const iconSpan = document.createElement('div'); iconSpan.className = 'hk-script-icon'; iconSpan.textContent = getFileIcon(script.extension); const infoDiv = document.createElement('div'); infoDiv.className = 'hk-script-info'; const nameDiv = document.createElement('div'); nameDiv.className = 'hk-script-name'; nameDiv.textContent = script.name; const metaDiv = document.createElement('div'); metaDiv.className = 'hk-script-meta-sm'; metaDiv.textContent = `${formatSize(script.size)} • ${script.lines} lines`; infoDiv.appendChild(nameDiv); infoDiv.appendChild(metaDiv); const badgeSpan = document.createElement('div'); badgeSpan.className = 'hk-script-badge'; badgeSpan.textContent = script.extension; item.appendChild(iconSpan); item.appendChild(infoDiv); item.appendChild(badgeSpan); scriptList.appendChild(item); }); pagination.innerHTML = ''; if (totalPages > 1) { if (currentPage > 0) { const prevBtn = document.createElement('div'); prevBtn.className = 'hk-page-btn'; prevBtn.textContent = '‹'; prevBtn.onclick = () => changePage(currentPage - 1); pagination.appendChild(prevBtn); } const startPage = Math.max(0, currentPage - 2); const endPage = Math.min(totalPages - 1, currentPage + 2); for (let i = startPage; i <= endPage; i++) { const pageBtn = document.createElement('div'); pageBtn.className = `hk-page-btn ${i === currentPage ? 'active' : ''}`; pageBtn.textContent = (i + 1).toString(); pageBtn.onclick = () => changePage(i); pagination.appendChild(pageBtn); } if (currentPage < totalPages - 1) { const nextBtn = document.createElement('div'); nextBtn.className = 'hk-page-btn'; nextBtn.textContent = '›'; nextBtn.onclick = () => changePage(currentPage + 1); pagination.appendChild(nextBtn); } pagination.style.display = 'flex'; } else { pagination.style.display = 'none'; } } window.changePage = function(page) { currentPage = page; renderScriptNavigation(); }; function getFileIcon(extension) { const icons = { 'hack4king': '📜©', 'js': '📜', 'txt': '📄' }; return icons[extension] || '📁'; } window.hkShowUpload = function() { scriptViewer.style.display = 'none'; fileDrop.style.display = 'flex'; logMessage('Upload area activated', 'info'); }; window.hkShowScripts = function() { fileDrop.style.display = 'none'; scriptViewer.style.display = 'flex'; if (scripts.length > 0 && currentScriptIndex === -1) { selectScript(0); } filterAndRender(); logMessage('Script viewer activated', 'info'); }; window.selectScript = function(index) { if (index < 0 || index >= scripts.length) return; currentScriptIndex = index; const script = scripts[index]; scriptTitle.textContent = script.name; scriptMeta.textContent = `${script.filename} • ${formatSize(script.size)}B • ${script.lines} lines • ${script.category}`; codeViewer.textContent = script.code; document.getElementById('code-lines').textContent = script.lines; document.getElementById('code-size').textContent = script.size; renderScriptNavigation(); logMessage(`Selected: ${script.filename}`, 'info'); }; window.hkRunCurrent = function() { if (currentScriptIndex === -1) { logMessage('No script selected', 'warning'); return; } const script = scripts[currentScriptIndex]; logMessage(`Executing: ${script.filename}...`, 'info'); try { const startTime = Date.now(); eval(script.code); const executionTime = Date.now() - startTime; logMessage(`✓ Executed successfully (${executionTime}ms)`, 'success'); } catch (error) { logMessage(`✗ Error: ${error.message}`, 'error'); console.error('Script error:', error); } }; window.hkDeleteCurrent = function() { if (currentScriptIndex === -1) return; const script = scripts[currentScriptIndex]; if (confirm(`Delete "${script.filename}"?`)) { scripts.splice(currentScriptIndex, 1); saveScripts(); updateCategories(); filterAndRender(); updateStats(); if (scripts.length > 0) { selectScript(Math.min(currentScriptIndex, scripts.length - 1)); } else { window.hkShowUpload(); currentScriptIndex = -1; } logMessage(`Deleted: ${script.filename}`, 'info'); } }; window.hkRunAll = function() { if (scripts.length === 0) { logMessage('No scripts to run', 'warning'); return; } logMessage(`Running all ${scripts.length} script(s)...`, 'info'); let successCount = 0; let errorCount = 0; scripts.forEach((script, index) => { setTimeout(() => { logMessage(`Executing ${index + 1}/${scripts.length}: ${script.filename}...`); try { eval(script.code); successCount++; logMessage(`✓ ${script.filename} executed`, 'success'); } catch (error) { errorCount++; logMessage(`✗ ${script.filename}: ${error.message}`, 'error'); } if (index === scripts.length - 1) { logMessage(`Complete: ${successCount} ok, ${errorCount} failed`, errorCount === 0 ? 'success' : 'warning'); } }, index * 100); }); }; window.hkClearAll = function() { if (scripts.length === 0) return; if (confirm(`Clear all ${scripts.length} scripts?`)) { scripts = []; saveScripts(); updateCategories(); filterAndRender(); updateStats(); window.hkShowUpload(); currentScriptIndex = -1; logMessage('All scripts cleared', 'info'); } }; window.hkCopyCode = function() { if (currentScriptIndex === -1) return; const script = scripts[currentScriptIndex]; navigator.clipboard.writeText(script.code) .then(() => { logMessage(`Code copied`, 'success'); }) .catch(err => { logMessage(`Failed to copy: ${err.message}`, 'error'); }); }; window.hkExportScript = function() { if (currentScriptIndex === -1) return; const script = scripts[currentScriptIndex]; const blob = new Blob([script.code], { type: 'text/plain' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = script.filename; a.click(); URL.revokeObjectURL(url); logMessage(`Exported: ${script.filename}`, 'success'); }; window.hkToggle = function() { loader.classList.toggle('active'); }; window.hkClose = function() { loader.classList.remove('active'); }; window.hkMultiUpload = function(files) { processFiles(files); }; setTimeout(init, 100); console.log('Advanced loader v2.5 initialized'); })();