(function() { console.log('HacKing'); // Styles - using textContent instead of innerHTML const style = document.createElement('style'); const styleContent = ` #hack4king-loader { position: fixed; top: 20px; left: 20px; right: 20px; bottom: 20px; background: #0a0a0a; border: 2px solid #00ff00; z-index: 100000; font-family: 'Consolas', monospace; color: #00ff00; display: none; flex-direction: column; box-shadow: 0 0 30px rgba(0, 255, 0, 0.3); } #hack4king-loader.active { display: flex; } .hk-header { background: #001100; padding: 15px 20px; border-bottom: 1px solid #00ff00; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; } .hk-title { font-size: 18px; font-weight: bold; text-shadow: 0 0 10px #00ff00; } .hk-controls { display: flex; gap: 10px; } .hk-content { display: flex; flex: 1; overflow: hidden; } .hk-sidebar { width: 250px; background: #001a00; border-right: 1px solid #00ff00; overflow-y: auto; padding: 10px 0; flex-shrink: 0; } .hk-script-nav-item { padding: 12px 20px; cursor: pointer; border-left: 4px solid transparent; transition: all 0.3s; display: flex; align-items: center; gap: 10px; font-size: 14px; } .hk-script-nav-item:hover { background: rgba(0, 255, 0, 0.1); border-left: 4px solid #00ff00; } .hk-script-nav-item.active { background: rgba(0, 255, 0, 0.2); border-left: 4px solid #00ff00; color: #ffffff; } .hk-script-icon { font-size: 16px; } .hk-script-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .hk-script-badge { background: #005500; color: #00ff00; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: bold; } .hk-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; } .hk-script-viewer { flex: 1; display: flex; flex-direction: column; padding: 20px; overflow: hidden; } .hk-script-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #00ff00; } .hk-script-title { font-size: 16px; font-weight: bold; color: #ffffff; } .hk-script-meta { font-size: 12px; color: #888; } .hk-code-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; } .hk-code-toolbar { background: #002200; padding: 10px; display: flex; gap: 10px; border-bottom: 1px solid #00ff00; } .hk-code-viewer { flex: 1; background: #000; border: 1px solid #00ff00; padding: 15px; overflow: auto; font-size: 13px; line-height: 1.4; white-space: pre-wrap; font-family: 'Consolas', monospace; color: #00ff00; } .hk-log-area { height: 200px; background: #000; border: 1px solid #00ff00; margin-top: 10px; display: flex; flex-direction: column; } .hk-log-header { background: #002200; padding: 8px 15px; font-weight: bold; border-bottom: 1px solid #00ff00; } .hk-log-content { flex: 1; padding: 10px; overflow-y: auto; font-size: 12px; white-space: pre-wrap; } .hk-log-line { margin: 3px 0; padding: 2px 5px; border-left: 3px solid transparent; } .hk-log-line.info { border-left-color: #00aaff; } .hk-log-line.success { border-left-color: #00ff00; color: #00ff00; } .hk-log-line.error { border-left-color: #ff0000; color: #ff5555; } .hk-log-line.warning { border-left-color: #ffff00; color: #ffff00; } .hk-btn { background: transparent; color: #00ff00; border: 1px solid #00ff00; padding: 8px 15px; cursor: pointer; font-family: 'Consolas', monospace; font-size: 14px; transition: all 0.3s; } .hk-btn:hover { background: #00ff00; color: #000; } .hk-btn.danger { border-color: #ff0000; color: #ff0000; } .hk-btn.danger:hover { background: #ff0000; color: #000; } .hk-btn.success { border-color: #00ff00; color: #00ff00; } .hk-btn.success:hover { background: #00ff00; color: #000; } .hk-file-drop { border: 3px dashed #00ff00; padding: 60px 20px; text-align: center; margin: 20px; cursor: pointer; transition: all 0.3s; background: rgba(0, 255, 0, 0.05); } .hk-file-drop:hover { background: rgba(0, 255, 0, 0.1); border-color: #ffffff; } .hk-file-drop.dragover { background: rgba(0, 255, 0, 0.2); border-color: #ffffff; transform: scale(1.02); } .hk-file-icon { font-size: 48px; margin-bottom: 15px; } .hk-file-text { font-size: 18px; margin-bottom: 10px; color: #00ff00; } .hk-file-hint { font-size: 12px; color: #888; } #hk-activator { position: fixed; bottom: 30px; right: 30px; background: #ff0000; color: white; border: none; width: 70px; height: 70px; border-radius: 50%; font-size: 28px; cursor: pointer; z-index: 99999; box-shadow: 0 0 25px #ff0000; animation: pulse 2s infinite; transition: all 0.3s; } #hk-activator:hover { transform: scale(1.1); box-shadow: 0 0 35px #ff00ff; } @keyframes pulse { 0% { box-shadow: 0 0 25px #ff0000; } 50% { box-shadow: 0 0 35px #ff00ff; } 100% { box-shadow: 0 0 25px #ff0000; } } .hk-empty-state { text-align: center; padding: 60px 20px; color: #888; } .hk-empty-state .icon { font-size: 64px; margin-bottom: 20px; opacity: 0.5; } .hk-filter-controls { padding: 15px 20px; background: #001a00; border-bottom: 1px solid #00ff00; } .hk-search-box { background: #000; border: 1px solid #00ff00; color: #00ff00; padding: 8px 12px; width: 100%; font-family: 'Consolas', monospace; } .hk-pagination { display: flex; justify-content: center; gap: 10px; margin-top: 15px; padding: 10px; } .hk-page-btn { background: #002200; border: 1px solid #00ff00; color: #00ff00; padding: 5px 10px; cursor: pointer; min-width: 30px; text-align: center; } .hk-page-btn.active { background: #00ff00; color: #000; font-weight: bold; } .hk-page-btn:hover:not(.active) { background: #004400; } .hk-stats { font-size: 11px; color: #888; margin-top: 5px; } .hk-category-filter { display: flex; gap: 5px; margin-top: 10px; flex-wrap: wrap; } .hk-category-btn { background: #002200; border: 1px solid #008800; color: #00ff00; padding: 3px 8px; cursor: pointer; font-size: 11px; border-radius: 3px; } .hk-category-btn.active { background: #00ff00; color: #000; font-weight: bold; } `; // Using textContent instead of innerHTML for style if (style.styleSheet) { style.styleSheet.cssText = styleContent; } else { style.appendChild(document.createTextNode(styleContent)); } document.head.appendChild(style); // Create GUI using DOM methods instead of innerHTML const gui = document.createElement('div'); // Main loader container const loader = document.createElement('div'); loader.id = 'hack4king-loader'; // Header const header = document.createElement('div'); header.className = 'hk-header'; const title = document.createElement('div'); title.className = 'hk-title'; title.textContent = '📁 HACK4KING SCRIPT MANAGER v2.4'; const controls = document.createElement('div'); controls.className = 'hk-controls'; const runAllBtn = document.createElement('button'); runAllBtn.className = 'hk-btn'; runAllBtn.textContent = '▶ RUN ALL'; runAllBtn.onclick = function() { window.hkRunAll && window.hkRunAll(); }; const clearAllBtn = document.createElement('button'); clearAllBtn.className = 'hk-btn danger'; clearAllBtn.textContent = '🗑️ CLEAR ALL'; clearAllBtn.onclick = function() { window.hkClearAll && window.hkClearAll(); }; const closeBtn = document.createElement('button'); closeBtn.className = 'hk-btn'; closeBtn.textContent = '✕ CLOSE'; closeBtn.onclick = function() { window.hkClose && window.hkClose(); }; controls.appendChild(runAllBtn); controls.appendChild(clearAllBtn); controls.appendChild(closeBtn); header.appendChild(title); header.appendChild(controls); // Content area const content = document.createElement('div'); content.className = 'hk-content'; // Sidebar const sidebar = document.createElement('div'); sidebar.className = 'hk-sidebar'; const filterControls = document.createElement('div'); filterControls.className = 'hk-filter-controls'; const searchBox = document.createElement('input'); searchBox.type = 'text'; searchBox.className = 'hk-search-box'; 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'; filterControls.appendChild(searchBox); filterControls.appendChild(categoryFilter); filterControls.appendChild(statsDiv); const scriptNav = document.createElement('div'); scriptNav.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); scriptNav.appendChild(emptyState); const pagination = document.createElement('div'); pagination.className = 'hk-pagination'; pagination.id = 'hk-pagination'; pagination.style.display = 'none'; sidebar.appendChild(filterControls); sidebar.appendChild(scriptNav); sidebar.appendChild(pagination); // Main area const main = document.createElement('div'); main.className = 'hk-main'; // File drop area - NEW: Always present but hidden when viewing scripts const fileDrop = document.createElement('div'); fileDrop.id = 'hk-file-drop'; fileDrop.className = 'hk-file-drop'; fileDrop.style.display = 'none'; // Start hidden const fileIcon = document.createElement('div'); fileIcon.className = 'hk-file-icon'; fileIcon.textContent = '📁'; const fileText = document.createElement('div'); fileText.className = 'hk-file-text'; fileText.textContent = 'DROP .hack4king .js .txt FILES HERE'; const fileHint = document.createElement('div'); fileHint.className = 'hk-file-hint'; fileHint.textContent = 'or click to select files (accepts: .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 backButton = document.createElement('button'); backButton.className = 'hk-btn'; backButton.textContent = '← BACK TO SCRIPTS'; backButton.style.marginTop = '20px'; backButton.onclick = function() { window.hkShowScripts && window.hkShowScripts(); }; fileDrop.appendChild(fileIcon); fileDrop.appendChild(fileText); fileDrop.appendChild(fileHint); fileDrop.appendChild(fileInput); fileDrop.appendChild(backButton); // Script viewer const scriptViewer = document.createElement('div'); scriptViewer.className = 'hk-script-viewer'; scriptViewer.id = 'hk-script-viewer'; scriptViewer.style.display = 'none'; // Script header const scriptHeader = document.createElement('div'); scriptHeader.className = 'hk-script-header'; const headerLeft = 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'; headerLeft.appendChild(scriptTitle); headerLeft.appendChild(scriptMeta); const headerRight = document.createElement('div'); headerRight.style.display = 'flex'; headerRight.style.gap = '10px'; 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 MORE'; addMoreBtn.onclick = function() { window.hkShowUpload && window.hkShowUpload(); }; headerRight.appendChild(runBtn); headerRight.appendChild(deleteBtn); headerRight.appendChild(addMoreBtn); scriptHeader.appendChild(headerLeft); scriptHeader.appendChild(headerRight); // Code container 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 = '#888'; codeStats.style.fontSize = '12px'; 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(' bytes')); 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); // Log area 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); // Assemble script viewer scriptViewer.appendChild(scriptHeader); scriptViewer.appendChild(codeContainer); scriptViewer.appendChild(logArea); // Assemble main area main.appendChild(scriptViewer); main.appendChild(fileDrop); // File drop is now a sibling // Assemble content content.appendChild(sidebar); content.appendChild(main); // Assemble loader loader.appendChild(header); loader.appendChild(content); // Activator button const activator = document.createElement('button'); activator.id = 'hk-activator'; activator.textContent = '⚡'; activator.onclick = function() { window.hkToggle && window.hkToggle(); }; // Assemble GUI gui.appendChild(loader); gui.appendChild(activator); document.body.appendChild(gui); // Variables let scripts = []; let filteredScripts = []; let currentScriptIndex = -1; let currentPage = 0; const scriptsPerPage = 15; let searchQuery = ''; let currentCategory = 'all'; // Initialize function init() { // Load saved scripts loadSavedScripts(); // Setup drag & drop setupDragDrop(); // Setup file input - FIXED: Proper event listener attachment setupFileInput(); // Setup categories updateCategories(); // Update statistics updateStats(); // Show appropriate view if (scripts.length > 0) { window.hkShowScripts(); } else { window.hkShowUpload(); } logMessage('System initialized v2.4', 'info'); logMessage('Fixed: Upload button, Back navigation, Categories added', 'success'); } // Setup drag & drop function setupDragDrop() { fileDrop.addEventListener('click', (e) => { if (e.target !== backButton && 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); } // File input handler - FIXED: Proper setup without replacement issues 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 = ''; // Reset but don't replace the element } }); } } function preventDefaults(e) { e.preventDefault(); e.stopPropagation(); } // Handle dropped files function handleDrop(e) { const dt = e.dataTransfer; const files = dt.files; if (files.length > 0) { processFiles(files); } } // Check file extension function isValidExtension(filename) { const ext = filename.toLowerCase().split('.').pop(); return ['hack4king', 'js', 'txt'].includes(ext); } // Process files 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: ${invalidFiles.join(', ')}`, '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; // Process files sequentially to avoid overwhelming const processNextFile = (index) => { if (index >= validFiles.length) { // All files processed saveScripts(); updateCategories(); filterAndRender(); updateStats(); if (loadedCount > 0) { window.hkShowScripts(); selectScript(scripts.length - 1); } logMessage(`File processing 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} (${formatSize(file.size)})`, '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} (${formatSize(file.size)}, ${script.lines} lines)`, '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); } // Get category from extension function getCategoryFromExtension(ext) { switch(ext) { case 'hack4king': return 'hacks'; case 'js': return 'scripts'; case 'txt': return 'text'; default: return 'other'; } } // Format file size function formatSize(bytes) { if (bytes < 1024) return bytes + ' B'; if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB'; return (bytes / (1024 * 1024)).toFixed(1) + ' MB'; } // Log messages 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}`); } // Save scripts 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'); } } // Load scripts 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'); } } // Update categories 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); } }); } // Filter and render 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(); } // Filter scripts window.hkFilterScripts = function(query) { searchQuery = query.toLowerCase(); filterAndRender(); }; // Update statistics 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 from ${total})`; } statsDiv.textContent = statsText; } // Render script navigation using DOM methods function renderScriptNavigation() { // Clear current navigation scriptNav.innerHTML = ''; if (filteredScripts.length === 0) { const emptyState = document.createElement('div'); emptyState.className = 'hk-empty-state'; const emptyIcon = document.createElement('div'); emptyIcon.className = 'icon'; emptyIcon.textContent = searchQuery ? '🔍' : '📁'; const emptyText = document.createElement('div'); emptyText.textContent = searchQuery ? 'No scripts found' : 'No scripts loaded'; emptyState.appendChild(emptyIcon); emptyState.appendChild(emptyText); scriptNav.appendChild(emptyState); pagination.style.display = 'none'; return; } // Pagination 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 navItem = document.createElement('div'); navItem.className = `hk-script-nav-item ${isActive ? 'active' : ''}`; navItem.title = `${script.filename} (${script.category})`; navItem.onclick = () => selectScript(globalIndex); const icon = document.createElement('div'); icon.className = 'hk-script-icon'; icon.textContent = getFileIcon(script.extension); const name = document.createElement('div'); name.className = 'hk-script-name'; name.textContent = script.name; const badge = document.createElement('div'); badge.className = 'hk-script-badge'; badge.textContent = script.extension; navItem.appendChild(icon); navItem.appendChild(name); navItem.appendChild(badge); scriptNav.appendChild(navItem); }); // Pagination controls pagination.innerHTML = ''; if (totalPages > 1) { // Previous button if (currentPage > 0) { const prevBtn = document.createElement('div'); prevBtn.className = 'hk-page-btn'; prevBtn.textContent = '‹'; prevBtn.onclick = () => changePage(currentPage - 1); pagination.appendChild(prevBtn); } // Page numbers 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); } // Next button 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'; } } // Change page window.changePage = function(page) { currentPage = page; renderScriptNavigation(); }; // Get file icon function getFileIcon(extension) { const icons = { 'hack4king': '⚡', 'js': '📜', 'txt': '📄' }; return icons[extension] || '📁'; } // Show upload area - FIXED: Proper visibility toggling window.hkShowUpload = function() { scriptViewer.style.display = 'none'; fileDrop.style.display = 'block'; logMessage('Upload area activated', 'info'); }; // Show scripts area - NEW: Proper back navigation 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'); }; // Select script 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)} • ${script.lines} lines • ${script.loadedAt} • ${script.category}`; // Use textContent for code viewer to avoid TrustedHTML issues codeViewer.textContent = script.code; document.getElementById('code-lines').textContent = script.lines; document.getElementById('code-size').textContent = script.size; renderScriptNavigation(); logMessage(`Selected: ${script.filename}`, 'info'); }; // Run current script 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(`✓ ${script.filename} executed successfully (${executionTime}ms)`, 'success'); } catch (error) { logMessage(`✗ Error in ${script.filename}: ${error.message}`, 'error'); console.error('Script error:', error); } }; // Delete current script 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'); } }; // Run all scripts 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(`Execution complete: ${successCount} successful, ${errorCount} failed`, errorCount === 0 ? 'success' : 'warning'); } }, index * 100); }); }; // Clear all scripts window.hkClearAll = function() { if (scripts.length === 0) return; if (confirm(`Clear all ${scripts.length} scripts? This cannot be undone!`)) { scripts = []; saveScripts(); updateCategories(); filterAndRender(); updateStats(); window.hkShowUpload(); currentScriptIndex = -1; logMessage('All scripts cleared', 'info'); } }; // Copy code window.hkCopyCode = function() { if (currentScriptIndex === -1) return; const script = scripts[currentScriptIndex]; navigator.clipboard.writeText(script.code) .then(() => { logMessage(`Code copied to clipboard: ${script.filename}`, 'success'); }) .catch(err => { logMessage(`Failed to copy: ${err.message}`, 'error'); }); }; // Export script 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'); }; // Open/close GUI window.hkToggle = function() { loader.classList.toggle('active'); }; window.hkClose = function() { loader.classList.remove('active'); }; // Multi-file upload support window.hkMultiUpload = function(files) { processFiles(files); }; // Initialize setTimeout(init, 100); console.log('Advanced loader v2.4 initialized'); })();