what's the API for this <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" />…
- User
what's the API for this
<!-- Developer Mode embedded UI --> <section id="developerModeUI" style="border-top:1px solid #555; margin-top:12px; padding-top:12px; color:#ffcc66; display:none; user-select:text;"> <h3>Developer Mode</h3> <button id="toggleDevMode">Enable Developer Mode</button> <div style="margin-top:12px; display:none;" id="devModeContainer"> <label for="devPageSelect">Select Page:</label> <select id="devPageSelect"></select> <button id="addDevPageBtn" title="Add New Page" style="margin-left:10px;">+ Add Page</button> <div id="devGamesArea" style="margin-top:18px; max-height:250px; overflow-y:auto; background:#222; border-radius:12px; padding:12px;"></div> <button id="addDevGameBtn" style="margin-top:12px; background:#44aa44; color:#eee; border:none; padding:8px 18px; border-radius:14px; font-weight:700;">+ Add Dev Game</button> </div> </section><div id="video-container" aria-live="polite" aria-atomic="true"></div> <div id="likedVideosContainer" style="display:none;"> <h4>Liked Videos <span style="font-weight: 400; font-size: 0.85rem;">(Click ♥ to Unlike)</span></h4> <ul id="likedVideosList" tabindex="0" aria-label="List of liked videos"></ul> </div><!-- Developer game buttons will be injected here --> <button id="nextPageButton" class="page-button" aria-label="Next Page">Next Page</button> </div><button id="prevPageButton" class="page-button" aria-label="Previous Page">Previous Page</button> </div><div id="consoleOutputWrapper" role="log" aria-live="polite" aria-atomic="true" style="white-space: pre-wrap; font-family: monospace; background:#000; color:#0f0; padding:16px; border-radius:16px; height:130px; overflow-y:auto; margin-top:14px;"></div> <div id="consoleControls" style="margin-top: 16px; display:flex; flex-wrap: wrap; gap: 8px; justify-content: center; user-select:none;"> <button id="runConsoleCode" title="Run Console Code">Run</button> <button id="saveCodeButton" title="Save Code">Save</button> <button id="deleteCodeButton" title="Delete All Code">Delete All</button> <button id="downloadCodeButton" title="Download Code">Download</button> <button id="uploadCodeButton" title="Upload Code">Upload</button> <button id="expandButton" title="Expand/Minimize Console">Expand</button> <button id="newTabButton" title="New Tab">New Tab</button> <button id="openRawConsoleLogs" title="Open raw console logs in new window">Open Logs</button> </div>`); newWin.document.close(); }; // --- TOAST ALIAS window.toast = createToast; // --- API Exposed to Console Code --- window.api = { toast: createToast, wait: async (seconds) => new Promise(res => setTimeout(res, seconds * 1000)), log: logConsoleOutput, listTabs: () => Object.keys(consoleTabs), openTab: (index) => { switchConsoleTab(index); }, createTab: () => addConsoleTabHandler(), saveCurrentCode: (code) => { consoleTabs[tabName(activeConsoleTab)] = code; saveConsoleTabs(); codeMirrorInstance.setValue(code); createToast('Saved current code via API'); }, getSettings: () => ({ ...settings }), updateSettings: (newSettings) => { Object.entries(newSettings).forEach(([k, v]) => { if (settings.hasOwnProperty(k)) settings[k] = v; }); syncSettingsUI(); applyAppSettings(); createToast('Settings updated via API'); }, listGames: () => { return Array.from(document.querySelectorAll('.glist a.game-link')).map(el => ({ title: el.textContent, url: el.dataset.link, favorite: el.classList.contains('favorite') })); }, addFavorite: (url) => { const el = document.querySelector(`.glist a[data-link="${url}"]`); if (el && !el.classList.contains('favorite')) { el.classList.add('favorite'); reorderFavorites(); saveGameOrder(); createToast(`Added to favorites: ${el.textContent}`, 'success'); } }, removeFavorite: (url) => { const el = document.querySelector(`.glist a[data-link="${url}"]`); if (el && el.classList.contains('favorite')) { el.classList.remove('favorite'); reorderFavorites(); saveGameOrder(); createToast(`Removed from favorites: ${el.textContent}`, 'info'); } }, // Developer Mode APIs (only active if developerMode enabled) addDevGame: (label, clickCode, pageId = activeDevPage) => { if (!settings.developerMode) { createToast('Developer Mode not enabled', 'error'); return; } addDevGame(label, clickCode, pageId); }, removeDevGame: id => { if (!settings.developerMode) { createToast('Developer Mode not enabled', 'error'); return; } devGames = devGames.filter(g => g.id !== id); safeLocalSet(LS_KEYS.DEVGAMES, devGames); refreshDevGamesUI(); createToast('Dev game removed', 'warning'); }, listDevGames: () => { if (!settings.developerMode) { createToast('Developer Mode not enabled', 'error'); return; } return devGames; }, showPage: pageId => { activeDevPage = pageId; showPage(pageId); if (settings.developerMode) refreshDevGamesUI(); }, }; // --- Dev Mode UI Management --- function toggleDeveloperModeUI(enabled) { developerModeUI.style.display = enabled ? 'block' : 'none'; developerModeToggle.textContent = enabled ? 'Disable Developer Mode' : 'Enable Developer Mode'; developerModeToggle.style.backgroundColor = enabled ? '#2d8f2d' : '#cc9933'; safeLocalSet(LS_KEYS.SETTINGS, settings); if (enabled) { buildDevPagesSelect(); refreshDevGamesUI(); } } developerModeToggle.onclick = () => { settings.developerMode = !settings.developerMode; applyAppSettings(); }; // Dev Page Select setup + Adding new pages function buildDevPagesSelect() { devPageSelect.innerHTML = ''; devPages.forEach(page => { const option = document.createElement('option'); option.value = page.id; option.textContent = page.label; devPageSelect.appendChild(option); }); devPageSelect.value = activeDevPage; devPageSelect.onchange = e => { activeDevPage = e.target.value; refreshDevGamesUI(); showPage(activeDevPage); }; addDevPageBtn.onclick = () => { const label = prompt('Enter new page label (e.g. Custom Page)'); if (!label) return; const id = 'custom-' + Date.now(); devPages.push({ id, label }); safeLocalSet(LS_KEYS.DEVPAGES, devPages); buildDevPagesSelect(); devPageSelect.value = id; devPageSelect.dispatchEvent(new Event('change')); createToast(`New page created: ${label}`, 'success'); }; } // Dev games UI rendering function refreshDevGamesUI() { devGamesArea.innerHTML = ''; const gamesOnPage = devGames.filter(g => g.pageId === activeDevPage); if (gamesOnPage.length === 0) { devGamesArea.innerHTML = `<p style="color:#aaa; font-style: italic;">No developer games on this page.</p>`; return; } gamesOnPage.forEach(game => { const div = document.createElement('div'); div.style.display = 'flex'; div.style.justifyContent = 'space-between'; div.style.alignItems = 'center'; div.style.backgroundColor = '#555'; div.style.padding = '6px 12px'; div.style.borderRadius = '10px'; div.style.marginBottom = '10px'; div.style.color = 'white'; const span = document.createElement('span'); span.textContent = game.label; const btnsContainer = document.createElement('div'); btnsContainer.style.display = 'flex'; btnsContainer.style.gap = '12px'; const runBtn = document.createElement('button'); runBtn.textContent = 'Run'; runBtn.style.backgroundColor = '#4c9aff'; runBtn.onclick = () => { try { const fn = new Function('toast', 'api', `'use strict'; ${game.clickCode}`); fn(createToast, window.api); createToast(`Ran dev game "${game.label}"`, 'success'); } catch (e) { createToast(`Error running dev game: ${e.message}`, 'error'); } }; const editBtn = document.createElement('button'); editBtn.textContent = 'Edit'; editBtn.style.backgroundColor = '#ffaa33'; editBtn.onclick = () => editDevGame(game.id); const delBtn = document.createElement('button'); delBtn.textContent = 'Delete'; delBtn.style.backgroundColor = '#cc2222'; delBtn.onclick = () => { if (confirm(`Delete "${game.label}"? This cannot be undone.`)) { devGames = devGames.filter(g => g.id !== game.id); safeLocalSet(LS_KEYS.DEVGAMES, devGames); refreshDevGamesUI(); createToast('Deleted dev game', 'warning'); } }; btnsContainer.appendChild(runBtn); btnsContainer.appendChild(editBtn); btnsContainer.appendChild(delBtn); div.appendChild(span); div.appendChild(btnsContainer); devGamesArea.appendChild(div); }); } // Edit dev game popup function editDevGame(id) { const game = devGames.find(g => g.id === id); if (!game) { createToast('Game not found', 'error'); return; } createModalPrompt({ title: `Edit "${game.label}"`, body: ` <label>Label:<br><input id="editDevLabel" type="text" value="${game.label}" style="width: calc(100% - 16px); padding: 6px; font-weight: 600; font-size: 1rem;"></label><br> <label>Click Code (JS):<br><textarea id="editDevCode" style="width: calc(100% - 16px); height: 140px; font-family: monospace; font-weight: 700; font-size: 1rem;">${game.clickCode}</textarea></label><br> <label>Page:<br> <select id="editDevPageSelect">${devPages.map(p => `<option value="${p.id}" ${p.id === game.pageId ? 'selected' : ''}>${p.label}</option>`).join('')}</select> </label> <div style="text-align: right;"> <button id="saveDevGameBtn" style="background: #4c9aff; padding: 12px 28px; font-weight: 700; color: white; border:none; border-radius:14px; cursor:pointer;">Save</button> <button id="cancelDevGameBtn" style="margin-left: 16px; padding: 12px 28px; font-weight: 700; background:#ccc; border:none; border-radius:14px; cursor:pointer;">Cancel</button> </div> `, onSave: () => { const newLabel = document.getElementById('editDevLabel').value.trim(); const newCode = document.getElementById('editDevCode').value; const newPage = document.getElementById('editDevPageSelect').value; if (newLabel.length === 0) { alert('Label cannot be empty'); return false; } game.label = newLabel; game.clickCode = newCode; game.pageId = newPage; safeLocalSet(LS_KEYS.DEVGAMES, devGames); refreshDevGamesUI(); createToast('Saved dev game changes', 'success'); return true; // close modal } }); } // Modal prompt constructor function createModalPrompt({ title, body, onSave }) { const overlay = document.createElement('div'); overlay.style.cssText = ` position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 101000; display: flex; align-items: center; justify-content: center; user-select:none; `; const modal = document.createElement('div'); modal.style.cssText = ` background: #222; border-radius: 24px; padding: 20px 28px; max-width: 460px; color: white; font-weight: 700; user-select: text; `; const h2 = document.createElement('h2'); h2.textContent = title; h2.style.marginTop = 0; h2.style.textAlign = 'center'; const bodyWrapper = document.createElement('div'); bodyWrapper.innerHTML = body; bodyWrapper.style.marginBottom = '12px'; modal.appendChild(h2); modal.appendChild(bodyWrapper); overlay.appendChild(modal); document.body.appendChild(overlay); function close() { document.body.removeChild(overlay); } document.getElementById('saveDevGameBtn').onclick = () => { const success = onSave(); if (success) close(); }; document.getElementById('cancelDevGameBtn').onclick = close; return modal; } // Add dev game button click inside developer mode UI addDevGameBtn.onclick = () => { createModalPrompt({ title: 'Add New Dev Game', body: ` <label>Label:<br><input id="newDevLabel" type="text" style="width: calc(100% - 16px); padding: 8px;" value="New Dev Game"></label><br> <label>Click JS Code:<br><textarea id="newDevCode" style="width: calc(100% - 16px); height: 140px; font-family: monospace; font-weight: 700; font-size: 1rem;">toast('Hello from new dev game!');</textarea></label><br> <label>Page:<br> <select id="newDevPageSelect">${devPages.map(p => `<option value="${p.id}">${p.label}</option>`).join('')}</select> </label> <div style="text-align: right;"> <button id="newDevSaveBtn" style="background: #4c9aff; padding: 12px 28px; font-weight: 700; color: white; border:none; border-radius:14px; cursor:pointer;">Add</button> <button id="newDevCancelBtn" style="margin-left: 16px; padding: 12px 28px; font-weight: 700; background:#ccc; border:none; border-radius:14px; cursor:pointer;">Cancel</button> </div> `, onSave: () => { const label = document.getElementById('newDevLabel').value.trim(); const code = document.getElementById('newDevCode').value; const pageId = document.getElementById('newDevPageSelect').value; if (!label) { alert('Label cannot be empty'); return false; } addDevGame(label, code, pageId); return true; } }); }; function addDevGame(label, clickCode, pageId = 'gamePage1') { const newGame = { id: 'devgame-' + Date.now() + '-' + Math.floor(Math.random() * 1e6), label, clickCode, pageId }; devGames.push(newGame); safeLocalSet(LS_KEYS.DEVGAMES, devGames); if (pageId === activeDevPage && settings.developerMode) { refreshDevGamesUI(); } createToast(`Developer game "${label}" added!`, 'success'); } // --- Developer mode toggle refresh --- function refreshDevGamesUI() { devGamesArea.innerHTML = ''; const filteredGames = devGames.filter(g => g.pageId === activeDevPage); if (filteredGames.length === 0) { devGamesArea.innerHTML = '<p style="color:#ccc; font-style:italic;">No developer games on this page.</p>'; return; } filteredGames.forEach(game => { const div = document.createElement('div'); const labelSpan = document.createElement('span'); labelSpan.textContent = game.label; labelSpan.style.fontWeight = '700'; const btnRun = document.createElement('button'); btnRun.textContent = 'Run JS'; btnRun.onclick = () => { try { const fn = new Function('toast', 'api', `'use strict'; ${game.clickCode}`); fn(createToast, window.api); createToast(`Ran developer game "${game.label}"`, 'success'); } catch (e) { createToast(`Error: ${e.message}`, 'error'); } }; const btnEdit = document.createElement('button'); btnEdit.textContent = 'Edit'; btnEdit.style.backgroundColor = '#ffaa33'; btnEdit.onclick = () => editDevGame(game.id); const btnDelete = document.createElement('button'); btnDelete.textContent = 'Delete'; btnDelete.style.backgroundColor = '#cc2222'; btnDelete.onclick = () => { if (confirm(`Delete dev game "${game.label}"?`)) { devGames = devGames.filter(g => g.id !== game.id); safeLocalSet(LS_KEYS.DEVGAMES, devGames); refreshDevGamesUI(); createToast('Deleted dev game', 'warning'); } }; div.style.display = 'flex'; div.style.justifyContent = 'space-between'; div.style.alignItems = 'center'; div.style.marginBottom = '12px'; const btnGroup = document.createElement('div'); btnGroup.style.display = 'flex'; btnGroup.style.gap = '10px'; btnGroup.appendChild(btnRun); btnGroup.appendChild(btnEdit); btnGroup.appendChild(btnDelete); div.appendChild(labelSpan); div.appendChild(btnGroup); devGamesArea.appendChild(div); }); } // --- Initial Setup --- function showPage(id) { gamePage1.style.display = gamePage2.style.display = youtubeEmbedUI.classList.remove('active') && consoleUI.classList.remove('active') && 'none'; switch (id) { case 'gamePage1': gamePage1.style.display = 'flex'; break; case 'gamePage2': gamePage2.style.display = 'flex'; break; case 'youtubeEmbedUI': youtubeEmbedUI.classList.add('active'); break; case 'consoleUI': consoleUI.classList.add('active'); break; default: break; } } // --- YouTube Embed & Likes --- let likedVideosMap = new Map(safeLocalGet(LS_KEYS.LIKEDVIDEOS, [])); function saveLikedVideos() { safeLocalSet(LS_KEYS.LIKEDVIDEOS, Array.from(likedVideosMap.entries())); } function refreshLikedVideosUI() { likedVideosList.innerHTML = ''; if (likedVideosMap.size === 0) { likedVideosList.innerHTML = '<li>No liked videos yet.</li>'; return; } likedVideosMap.forEach((title, id) => { const li = document.createElement('li'); li.textContent = title; li.tabIndex = 0; li.title = `Play or unlike ${title}`; const spanLike = document.createElement('span'); spanLike.textContent = '♥'; spanLike.className = 'likeBtn'; spanLike.tabIndex = 0; spanLike.title = "Unlike video"; spanLike.onclick = e => { e.stopPropagation(); likedVideosMap.delete(id); saveLikedVideos(); refreshLikedVideosUI(); createToast(`Unliked video: ${title}`, 'warning'); }; spanLike.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); spanLike.onclick(); } }; li.appendChild(spanLike); li.onclick = () => playYouTube(videoId = id, title); li.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); li.onclick(); } }; likedVideosList.appendChild(li); }); } function playYouTube(videoId, title = '') { youtubeEmbedUI.querySelector('#video-container').innerHTML = `<iframe width="100%" height="100%" src="https://www.youtube-nocookie.com/embed/${videoId}" frameborder="0" allowfullscreen></iframe>`; likedVideosContainer.style.display = 'none'; videoContainer.style.display = 'block'; showLikeButton(videoId); createToast(`Playing ${title || 'video'}`, 'info'); } function showLikeButton(videoId) { let existingBtn = document.getElementById('youtubeLikeBtn'); if (existingBtn) existingBtn.remove(); const btn = document.createElement('button'); btn.id = 'youtubeLikeBtn'; btn.style.marginTop = '10px'; btn.style.padding = '12px 30px'; btn.style.borderRadius = '20px'; btn.style.fontWeight = '700'; btn.style.fontSize = '1.1rem'; btn.style.userSelect = 'none'; btn.style.cursor = 'pointer'; const liked = likedVideosMap.has(videoId); btn.textContent = liked ? '♥ Unlike' : '♡ Like'; btn.style.backgroundColor = liked ? 'gold' : '#4c9aff'; btn.style.color = liked ? 'black' : 'white'; btn.onclick = () => { if (likedVideosMap.has(videoId)) { likedVideosMap.delete(videoId); btn.textContent = '♡ Like'; btn.style.backgroundColor = '#4c9aff'; btn.style.color = 'white'; createToast('Video unliked', 'warning'); } else { likedVideosMap.set(videoId, videoId); btn.textContent = '♥ Unlike'; btn.style.backgroundColor = 'gold'; btn.style.color = 'black'; createToast('Video liked', 'success'); } saveLikedVideos(); refreshLikedVideosUI(); }; videoContainer.appendChild(btn); } // Load video or playlist or liked list based on YouTube UI loadVideoButton.onclick = async () => { likedVideosContainer.style.display = 'none'; videoContainer.style.display = 'none'; videoContainer.innerHTML = ''; youtubeChangeButton.style.display = 'inline-block'; youtubeURLInput.style.display = 'none'; loadVideoButton.style.display = 'none'; const url = youtubeURLInput.value.trim(); if (!url) { createToast('Please enter a YouTube link URL!', 'warning'); youtubeURLInput.style.display = 'block'; loadVideoButton.style.display = 'inline-block'; youtubeChangeButton.style.display = 'none'; return; } const type = youtubeTypeSelect.value; if (type === 'video') { const videoId = extractYouTubeVideoID(url); if (!videoId) { createToast('Invalid YouTube video URL!', 'error'); youtubeURLInput.style.display = 'block'; loadVideoButton.style.display = 'inline-block'; youtubeChangeButton.style.display = 'none'; return; } playYouTube(videoId); videoContainer.style.display = 'block'; } else if (type === 'playlist') { const playlistId = extractYouTubePlaylistId(url); if (!playlistId) { createToast('Invalid playlist URL!', 'error'); youtubeURLInput.style.display = 'block'; loadVideoButton.style.display = 'inline-block'; youtubeChangeButton.style.display = 'none'; return; } videoContainer.innerHTML = `<iframe src="https://www.youtube-nocookie.com/embed/videoseries?list=${playlistId}" width="100%" height="100%" frameborder="0" allowfullscreen></iframe>`; videoContainer.style.display = 'block'; createToast('Playlist loaded', 'success'); } else if (type === 'liked') { likedVideosContainer.style.display = 'block'; refreshLikedVideosUI(); } }; youtubeChangeButton.onclick = () => { likedVideosContainer.style.display = 'none'; videoContainer.style.display = 'none'; videoContainer.innerHTML = ''; youtubeChangeButton.style.display = 'none'; youtubeURLInput.style.display = 'block'; youtubeURLInput.value = ''; youtubeURLInput.focus(); loadVideoButton.style.display = 'inline-block'; }; // --- Games List page navigation nextPageButton.onclick = () => { showPage('gamePage2'); gsearchbar2.value = ''; gsearchbar2.dispatchEvent(new Event('input')); }; prevPageButton.onclick = () => { showPage('gamePage1'); gsearchbar1.value = ''; gsearchbar1.dispatchEvent(new Event('input')); }; gamesListButton.onclick = () => showPage('gamePage1'); youtubeUnblockerButton.onclick = () => { if (youtubeEmbedUI.classList.contains('active')) showPage('gamePage1'); else showPage('youtubeEmbedUI'); }; consoleButton.onclick = () => { if (consoleUI.classList.contains('active')) showPage('gamePage1'); else showPage('consoleUI'); }; // --- Initialize CodeMirror for Console --- function setupConsole() { codeMirrorInstance = CodeMirror.fromTextArea(consoleTextArea, { mode: 'javascript', theme: settings.consoleTheme, lineNumbers: true, autoCloseBrackets: true, matchBrackets: true, lineWrapping: true, extraKeys: { 'Ctrl-Space': 'autocomplete' }, viewportMargin: Infinity }); codeMirrorInstance.on('change', () => { if (settings.autoSaveConsole) { const key = `tab-${activeConsoleTab}`; consoleTabs[key] = codeMirrorInstance.getValue(); saveConsoleTabs(); } }); rebuildConsoleTabsUI(); runConsoleCodeBtn.onclick = runConsoleCode; saveConsoleCodeBtn.onclick = () => { const key = `tab-${activeConsoleTab}`; consoleTabs[key] = codeMirrorInstance.getValue(); saveConsoleTabs(); createToast('Console saved', 'success'); }; deleteConsoleCodeBtn.onclick = () => { if (confirm('Delete all console code?')) { consoleTabs = { 'tab-0': ''}; activeConsoleTab = 0; saveConsoleTabs(); rebuildConsoleTabsUI(); codeMirrorInstance.setValue(''); createToast('Console cleared', 'warning'); } }; downloadConsoleCodeBtn.onclick = () => { const code = codeMirrorInstance.getValue(); const blob = new Blob([code], {type:'text/plain'}); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.style.display = 'none'; a.href = url; a.download = `console_tab_${activeConsoleTab + 1}.txt`; document.body.appendChild(a); a.click(); URL.revokeObjectURL(url); a.remove(); createToast('Console code downloaded', 'success'); }; uploadConsoleCodeBtn.onclick = () => { const input = document.createElement('input'); input.type = 'file'; input.accept = '.txt'; input.onclick = e => e.stopPropagation(); input.onchange = e => { const file = e.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = ev => { codeMirrorInstance.setValue(ev.target.result); createToast(`Loaded ${file.name}`, 'success'); }; reader.readAsText(file); }; input.click(); }; expandConsoleBtn.onclick = () => { document.body.classList.toggle('fullscreen-console'); const collapsed = !document.body.classList.contains('fullscreen-console'); expandConsoleBtn.textContent = collapsed ? 'Expand' : 'Minimize'; setTimeout(() => codeMirrorInstance.refresh(), 200); }; newTabBtn.onclick = () => { let idx = Object.keys(consoleTabs).length > 0 ? Math.max(...Object.keys(consoleTabs).map(k => parseInt(k.split('-')[1]))) + 1 : 0; consoleTabs[`tab-${idx}`] = ''; saveConsoleTabs(); rebuildConsoleTabsUI(); switchConsoleTab(idx); createToast('New tab created', 'success'); }; openRawConsoleLogsBtn.onclick = () => { const newWin = window.open(); if (!newWin) return alert('Popup blocked. Allow popups please.'); const safeContent = consoleOutput.textContent.replace(/</g,'<').replace(/>/g,'>'); newWin.document.write(`<textarea style="width:100vw;height:100vh;font-family:monospace;" readonly>${safeContent}</textarea>`); newWin.document.title = 'Console Logs'; newWin.document.close(); }; } function rebuildConsoleTabsUI() { codeTabs.innerHTML = ''; Object.keys(consoleTabs).sort((a,b) => parseInt(a.split('-')[1]) - parseInt(b.split('-')[1])) .forEach(k => addConsoleTab(k)); addNewConsoleTabButton(); switchConsoleTab(activeConsoleTab); } function addConsoleTab(tabKey) { const index = parseInt(tabKey.split('-')[1]); const tab = document.createElement('div'); tab.className = 'code-tab'; tab.tabIndex = 0; tab.textContent = `Tab ${index + 1}`; tab.dataset.tabKey = tabKey; if (index === activeConsoleTab) tab.classList.add('active'); tab.onclick = () => { switchConsoleTab(index); }; tab.onkeydown = e => { if(e.key === 'Enter' || e.key === ' ') { e.preventDefault(); switchConsoleTab(index); } }; const closeBtn = document.createElement('span'); closeBtn.textContent = '×'; closeBtn.className = 'close-tab'; closeBtn.tabIndex = 0; closeBtn.title = 'Close tab'; closeBtn.onclick = e => { e.stopPropagation(); removeConsoleTab(index); }; closeBtn.onkeydown = e => { if(e.key === 'Enter' || e.key === ' ') { e.preventDefault(); removeConsoleTab(index); } }; tab.appendChild(closeBtn); codeTabs.appendChild(tab); } function addNewConsoleTabButton() { const btn = document.createElement('div'); btn.className = 'code-tab'; btn.textContent = '+'; btn.title = 'New tab'; btn.tabIndex = 0; btn.onclick = () => { let idx = Object.keys(consoleTabs).length > 0 ? Math.max(...Object.keys(consoleTabs).map(k => parseInt(k.split('-')[1]))) + 1 : 0; consoleTabs[`tab-${idx}`] = ''; saveConsoleTabs(); rebuildConsoleTabsUI(); switchConsoleTab(idx); createToast('New tab created', 'success'); }; btn.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); btn.onclick(); } }; codeTabs.appendChild(btn); } function switchConsoleTab(index) { if (!consoleTabs.hasOwnProperty(`tab-${index}`)) return; activeConsoleTab = index; Array.from(document.querySelectorAll('.code-tab')).forEach(t => { t.classList.remove('active'); if (t.dataset.tabKey === `tab-${index}`) t.classList.add('active'); }); if (codeMirrorInstance) { codeMirrorInstance.setValue(consoleTabs[`tab-${index}`]); codeMirrorInstance.focus(); } createToast(`Switched to Tab ${index + 1}`, 'info'); } function removeConsoleTab(index) { if (!consoleTabs.hasOwnProperty(`tab-${index}`)) return; if (!confirm(`Close tab ${index + 1}?`)) return; delete consoleTabs[`tab-${index}`]; saveConsoleTabs(); rebuildConsoleTabsUI(); const keys = Object.keys(consoleTabs); if (keys.length > 0) { switchConsoleTab(Math.min(...keys.map(k => parseInt(k.split('-')[1])))); } else { consoleTabs = { 'tab-0': '' }; saveConsoleTabs(); rebuildConsoleTabsUI(); switchConsoleTab(0); } createToast(`Closed tab ${index + 1}`, 'warning'); } // --- Console code execution --- function runConsoleCode() { const code = codeMirrorInstance.getValue(); // Treat as HTML if (/<\s*!doctype\s+html>/i.test(code) || /<html/i.test(code)) { const newWin = window.open(); newWin.document.write(code); newWin.document.close(); createToast("HTML content opened new tab", "success"); return; } try { const api = window.api; const fn = new Function("api", `"use strict"; return (async function(api) {${code}})(api);`); const result = fn(api); if (result?.then) { result.then(res => { if (res !== undefined) logConsoleOutput(res); }) .catch(err => { logConsoleOutput('Error ' + err.message); createToast('Error: ' + err.message, 'error'); }); } else if (result !== undefined) logConsoleOutput(result); } catch (e) { logConsoleOutput('Error: ' + e.message); createToast('Error: ' + e.message, 'error'); } } function logConsoleOutput(msg) { const now = new Date().toLocaleTimeString(); let out = typeof msg === 'string' ? msg : JSON.stringify(msg, null, 2); consoleOutput.textContent += `[${now}] ${out}\n`; consoleOutputWrapper.scrollTop = consoleOutputWrapper.scrollHeight; } // --- Initialization --- function applyGameFontSize(size) { const finalSize = size || settings.gameFontSize || 18; document.querySelectorAll('a.game-link').forEach(el => { el.style.fontSize = finalSize + 'px'; }); } // Load localStorage data function loadPersistentData() { settings = Object.assign(settings, safeLocalGet(LS_KEYS.SETTINGS, {})); devGames = safeLocalGet(LS_KEYS.DEVGAMES, []); devPages = safeLocalGet(LS_KEYS.DEVPAGES, devPages); // default pages above consoleTabs = safeLocalGet(LS_KEYS.CONSOLETABS, { 'tab-0': '' }); likedVideosMap = new Map( safeLocalGet(LS_KEYS.LIKEDVIDEOS, []) ); } // Save localStorage data function saveAllData() { safeLocalSet(LS_KEYS.SETTINGS, settings); safeLocalSet(LS_KEYS.DEVGAMES, devGames); safeLocalSet(LS_KEYS.DEVPAGES, devPages); safeLocalSet(LS_KEYS.CONSOLETABS, consoleTabs); safeLocalSet(LS_KEYS.LIKEDVIDEOS, Array.from(likedVideosMap.entries())); } // Set up event handlers for UI function setEventListeners() { // Settings checkbox event handlers handle above in onChange nextPageButton.onclick = () => { showPage('gamePage2'); gsearchbar2.value = ''; gsearchbar2.dispatchEvent(new Event('input')); }; prevPageButton.onclick = () => { showPage('gamePage1'); gsearchbar1.value = ''; gsearchbar1.dispatchEvent(new Event('input')); }; // Game link confirmation handled above loadVideoButton.onclick = () => { // handled above }; youtubeChangeButton.onclick = () => { // handled above }; } // Initialize everything async function initializeApp() { loadPersistentData(); syncSettingsUI(); applyAppSettings(); setupBackgroundAnimation(settings.theme); enableDrag(settings.enableDrag); addFavoriteClickHandler(settings.toggleFavorites); applyGameFontSize(settings.gameFontSize); setupConsole(); showPage('gamePage1'); setEventListeners(); } initializeApp(); // Expose API object for Console and other uses window.api = { toast: createToast, wait: async seconds => new Promise(res => setTimeout(res, seconds * 1000)), log: logConsoleOutput, listTabs: () => Object.keys(consoleTabs), openTab: idx => switchConsoleTab(idx), createTab: () => addConsoleTabHandler(), saveCurrentCode: code => { consoleTabs[`tab-${activeConsoleTab}`] = code; saveConsoleTabs(); codeMirrorInstance.setValue(code); createToast('Saved console code via API'); }, getSettings: () => ({ ...settings }), updateSettings: obj => { Object.entries(obj).forEach(([k, v]) => { if (settings.hasOwnProperty(k)) settings[k] = v; }); syncSettingsUI(); applyAppSettings(); createToast('Updated settings via API'); }, listGames: () => Array.from(document.querySelectorAll('a.game-link')).map(el => ({ title: el.textContent, url: el.dataset.link, favorite: el.classList.contains('favorite') })), addFavorite: url => { const el = document.querySelector(`a[data-link="${url}"]`); if (!el) return createToast('Game not found', 'error'); if (!el.classList.contains('favorite')) { el.classList.add('favorite'); reorderFavorites(); saveGameOrder(); createToast('Favorited game via API', 'success'); } }, removeFavorite: url => { const el = document.querySelector(`a[data-link="${url}"]`); if (!el) return createToast('Game not found', 'error'); if (el.classList.contains('favorite')) { el.classList.remove('favorite'); reorderFavorites(); saveGameOrder(); createToast('Unfavorited game via API', 'info'); } }, // Developer Mode API addDevGame: (label, clickCode, pageId = activeDevPage) => { if (!settings.developerMode) return createToast('Developer Mode not enabled', 'error'); addDevGame(label, clickCode, pageId); }, removeDevGame: id => { if (!settings.developerMode) return createToast('Developer Mode not enabled', 'error'); devGames = devGames.filter(g => g.id !== id); safeLocalSet(LS_KEYS.DEVGAMES, devGames); refreshDevGamesUI(); createToast('Dev game removed via API', 'warning'); }, listDevGames: () => { if (!settings.developerMode) return createToast('Developer Mode not enabled', 'error'); return devGames; }, showPage: pageId => { activeDevPage = pageId; showPage(pageId); if (settings.developerMode) refreshDevGamesUI(); } }; })(); - Assistant
- User
now remake the entire script revampe this and make it 100x better with better css animations sliders buttons so its not all clamped TOGHETOR and better things using jsdeliver for websites and all tis cool stuff
- Assistant