Source code sb3 to html
Konverter Scratch (.sb3) ke HTML Mandiri
<!-- Navbar / Header -->
<header class="bg-white border-b border-slate-200 sticky top-0 z-10">
<div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between">
<div class="flex items-center space-x-3">
<div class="bg-orange-500 text-white p-2 rounded-xl shadow-sm">
<i data-lucide="file-code-2" class="w-6 h-6"></i>
</div>
<div>
<h1 class="text-lg font-bold text-slate-900 leading-tight">Scratch to HTML</h1>
<p class="text-xs text-slate-500">Konverter Proyek .sb3 ke Halaman Web Mandiri</p>
</div>
</div>
<div class="hidden sm:flex items-center space-x-2 text-xs font-medium text-slate-500 bg-slate-100 px-3 py-1.5 rounded-full">
<span class="w-2 h-2 rounded-full bg-emerald-500"></span>
<span>100% Berjalan di Browser</span>
</div>
</div>
</header>
<!-- Konten Utama -->
<main class="flex-grow max-w-5xl w-full mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Kotak Pesan Notifikasi (Pengganti alert) -->
<div id="notificationBox" class="hidden mb-6 p-4 rounded-xl border flex items-start justify-between transition-all duration-300">
<div class="flex items-center space-x-3">
<i id="notificationIcon" data-lucide="info" class="w-5 h-5 flex-shrink-0"></i>
<p id="notificationText" class="text-sm font-medium"></p>
</div>
<button onclick="hideNotification()" class="text-slate-400 hover:text-slate-600">
<i data-lucide="x" class="w-4 h-4"></i>
</button>
</div>
<div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
<!-- Kolom Kiri: Area Unggah & Pengaturan -->
<div class="lg:col-span-7 space-y-6">
<!-- Area Unggah File -->
<div class="bg-white p-6 rounded-2xl shadow-sm border border-slate-200">
<h2 class="text-base font-semibold text-slate-900 mb-4 flex items-center gap-2">
<span class="bg-orange-100 text-orange-600 w-6 h-6 rounded-full inline-flex items-center justify-center text-xs font-bold">1</span>
Pilih File Proyek Scratch (.sb3)
</h2>
<div id="dropZone" class="drop-zone border-2 border-dashed border-slate-300 rounded-2xl p-8 text-center cursor-pointer hover:border-orange-400 hover:bg-slate-50">
<input type="file" id="fileInput" accept=".sb3" class="hidden">
<div id="uploadPrompt">
<div class="w-14 h-14 bg-orange-50 text-orange-500 rounded-2xl flex items-center justify-center mx-auto mb-4">
<i data-lucide="upload-cloud" class="w-8 h-8"></i>
</div>
<p class="text-sm font-semibold text-slate-700 mb-1">Klik untuk memilih file atau seret ke sini</p>
<p class="text-xs text-slate-500">Mendukung format file Scratch 3.0 (<code class="bg-slate-100 px-1.5 py-0.5 rounded text-orange-600">.sb3</code>)</p>
</div>
<div id="fileInfo" class="hidden">
<div class="w-14 h-14 bg-emerald-50 text-emerald-600 rounded-2xl flex items-center justify-center mx-auto mb-3">
<i data-lucide="check-circle-2" class="w-8 h-8"></i>
</div>
<p id="fileName" class="text-sm font-bold text-slate-800 truncate max-w-xs mx-auto"></p>
<p id="fileSize" class="text-xs text-slate-500 mt-1"></p>
<button type="button" id="changeFileBtn" class="mt-3 text-xs font-medium text-orange-600 hover:text-orange-700 underline">
Ganti file lain
</button>
</div>
</div>
</div>
<!-- Pengaturan Tampilan Website -->
<div class="bg-white p-6 rounded-2xl shadow-sm border border-slate-200">
<h2 class="text-base font-semibold text-slate-900 mb-4 flex items-center gap-2">
<span class="bg-orange-100 text-orange-600 w-6 h-6 rounded-full inline-flex items-center justify-center text-xs font-bold">2</span>
Kustomisasi Halaman Web
</h2>
<div class="space-y-4">
<div>
<label for="pageTitle" class="block text-xs font-semibold text-slate-700 mb-1.5">Judul Halaman Website</label>
<input type="text" id="pageTitle" value="Game Scratch Saya" placeholder="Masukkan judul proyek..."
class="w-full px-3.5 py-2.5 text-sm bg-slate-50 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-orange-500 focus:bg-white transition-all">
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="bgColor" class="block text-xs font-semibold text-slate-700 mb-1.5">Warna Latar Belakang</label>
<div class="flex items-center space-x-2">
<input type="color" id="bgColor" value="#0f172a" class="h-10 w-12 rounded-lg cursor-pointer border border-slate-200 p-1 bg-white">
<input type="text" id="bgColorHex" value="#0f172a" readonly class="w-full px-3 py-2 text-xs font-mono bg-slate-50 border border-slate-200 rounded-xl text-slate-600">
</div>
</div>
<div>
<label for="aspectRatio" class="block text-xs font-semibold text-slate-700 mb-1.5">Ukuran Layar (Stage)</label>
<select id="aspectRatio" class="w-full px-3.5 py-2.5 text-sm bg-slate-50 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-orange-500">
<option value="responsive">Responsif (Otomatis Penuh)</option>
<option value="standard">Standar Scratch (480 x 360)</option>
<option value="large">Besar HD (960 x 720)</option>
</select>
</div>
</div>
<!-- Opsi Tambahan -->
<div class="pt-2 space-y-3 border-t border-slate-100">
<label class="flex items-center justify-between cursor-pointer">
<div>
<span class="text-sm font-medium text-slate-700 block">Optimalkan untuk Post WordPress</span>
<span class="text-xs text-slate-500">Menghasilkan kode blok rapi & responsif di dalam artikel</span>
</div>
<input type="checkbox" id="wpEmbedMode" checked class="w-5 h-5 accent-orange-500 rounded cursor-pointer">
</label>
<label class="flex items-center justify-between cursor-pointer">
<div>
<span class="text-sm font-medium text-slate-700 block">Tampilkan Tombol Kontrol</span>
<span class="text-xs text-slate-500">Menampilkan bendera hijau, stop, dan layar penuh</span>
</div>
<input type="checkbox" id="showControls" checked class="w-5 h-5 accent-orange-500 rounded cursor-pointer">
</label>
<label class="flex items-center justify-between cursor-pointer">
<div>
<span class="text-sm font-medium text-slate-700 block">Mulai Otomatis (Auto-Start)</span>
<span class="text-xs text-slate-500">Proyek langsung berjalan saat website dibuka</span>
</div>
<input type="checkbox" id="autoStart" checked class="w-5 h-5 accent-orange-500 rounded cursor-pointer">
</label>
<label class="flex items-center justify-between cursor-pointer">
<div>
<span class="text-sm font-medium text-slate-700 block">Mode Turbo (60 FPS)</span>
<span class="text-xs text-slate-500">Meningkatkan kelancaran animasi dan game berat</span>
</div>
<input type="checkbox" id="turboMode" class="w-5 h-5 accent-orange-500 rounded cursor-pointer">
</label>
</div>
</div>
</div>
<!-- Tombol Aksi Utama -->
<button id="convertBtn" disabled
class="w-full py-3.5 px-6 rounded-xl font-semibold text-white bg-slate-300 cursor-not-allowed transition-all flex items-center justify-center space-x-2 shadow-sm">
<i data-lucide="wand-2" class="w-5 h-5"></i>
<span>Konversi ke File HTML Sekarang</span>
</button>
</div>
<!-- Kolom Kanan: Info Proyek & Hasil -->
<div class="lg:col-span-5 space-y-6">
<!-- Card Ringkasan Proyek -->
<div class="bg-white p-6 rounded-2xl shadow-sm border border-slate-200">
<h3 class="text-sm font-bold text-slate-900 uppercase tracking-wider mb-4 flex items-center gap-2">
<i data-lucide="layers" class="w-4 h-4 text-orange-500"></i>
Detail Proyek Scratch
</h3>
<div id="projectStatsEmpty" class="text-center py-8 px-4 bg-slate-50 rounded-xl border border-dashed border-slate-200">
<p class="text-xs text-slate-500">Unggah file <code class="text-orange-600">.sb3</code> untuk melihat analisis sprite, kostum, dan suara di dalam proyek Anda.</p>
</div>
<div id="projectStats" class="hidden space-y-3">
<div class="grid grid-cols-3 gap-2 text-center">
<div class="bg-slate-50 p-3 rounded-xl border border-slate-100">
<span id="statSprites" class="block text-xl font-bold text-slate-800">0</span>
<span class="text-[11px] text-slate-500 font-medium">Sprite</span>
</div>
<div class="bg-slate-50 p-3 rounded-xl border border-slate-100">
<span id="statCostumes" class="block text-xl font-bold text-slate-800">0</span>
<span class="text-[11px] text-slate-500 font-medium">Kostum</span>
</div>
<div class="bg-slate-50 p-3 rounded-xl border border-slate-100">
<span id="statSounds" class="block text-xl font-bold text-slate-800">0</span>
<span class="text-[11px] text-slate-500 font-medium">Suara</span>
</div>
</div>
<div class="text-xs text-slate-600 bg-orange-50/70 border border-orange-100 p-3 rounded-xl flex items-center gap-2">
<i data-lucide="check" class="w-4 h-4 text-orange-600 flex-shrink-0"></i>
<span>Aset berhasil dibaca dan siap dibundel ke dalam HTML.</span>
</div>
</div>
</div>
<!-- Card Hasil Unduhan & Pratinjau -->
<div id="resultCard" class="hidden bg-gradient-to-br from-slate-900 to-slate-800 text-white p-6 rounded-2xl shadow-lg border border-slate-700 space-y-5">
<div class="flex items-center space-x-3">
<div class="p-2.5 bg-emerald-500/20 text-emerald-400 rounded-xl">
<i data-lucide="sparkles" class="w-6 h-6"></i>
</div>
<div>
<h3 class="font-bold text-base">Konversi Berhasil!</h3>
<p class="text-xs text-slate-300">File HTML siap diunggah ke hosting atau dibuka offline.</p>
</div>
</div>
<div class="bg-slate-950/50 p-3.5 rounded-xl border border-slate-700/80 flex items-center justify-between text-xs">
<span class="text-slate-400">Ukuran File Hasil:</span>
<span id="outputSize" class="font-mono font-semibold text-emerald-400">0 KB</span>
</div>
<div class="space-y-2.5">
<button id="downloadBtn" class="w-full py-3 px-4 bg-emerald-500 hover:bg-emerald-600 text-white font-semibold rounded-xl text-sm transition-all flex items-center justify-center gap-2 shadow-md">
<i data-lucide="download" class="w-4 h-4"></i>
<span>Unduh File HTML (.html)</span>
</button>
<button id="copyWpCodeBtn" class="w-full py-2.5 px-4 bg-orange-500 hover:bg-orange-600 text-white font-semibold rounded-xl text-sm transition-all flex items-center justify-center gap-2 shadow-sm">
<i data-lucide="copy" class="w-4 h-4"></i>
<span>Salin Kode Blok HTML WordPress</span>
</button>
<button id="previewBtn" class="w-full py-2.5 px-4 bg-slate-700 hover:bg-slate-600 text-slate-100 font-medium rounded-xl text-sm transition-all flex items-center justify-center gap-2">
<i data-lucide="play" class="w-4 h-4"></i>
<span>Uji Coba Langsung di Tab Baru</span>
</button>
</div>
</div>
<!-- Panduan Singkat -->
<div class="bg-white p-6 rounded-2xl shadow-sm border border-slate-200 space-y-3">
<h3 class="text-sm font-bold text-slate-900 flex items-center gap-2">
<i data-lucide="help-circle" class="w-4 h-4 text-slate-400"></i>
Cara Pasang di Post WordPress
</h3>
<ul class="text-xs text-slate-600 space-y-2 list-disc pl-4 leading-relaxed">
<li><strong>Cara 1 (Langsung di Post):</strong> Klik <em>"Salin Kode Blok HTML WordPress"</em>, lalu di editor postingan WordPress tambahkan blok <strong>Custom HTML</strong> dan tempel (Paste) kodenya.</li>
<li><strong>Cara 2 (Via Media/Hosting):</strong> Unduh file <code>.html</code>, unggah ke hosting/Media Library, lalu sematkan menggunakan tag <code><iframe></code> agar lebih ringan.</li>
</ul>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-white border-t border-slate-200 py-6 mt-12">
<div class="max-w-5xl mx-auto px-4 text-center text-xs text-slate-500">
Dibuat untuk memudahkan publikasi karya Scratch ke Website • Mendukung Scratch 3.0 (.sb3)
</div>
</footer>
<script>
// Inisialisasi Ikon Lucide
lucide.createIcons();
// Referensi Elemen DOM
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const uploadPrompt = document.getElementById('uploadPrompt');
const fileInfo = document.getElementById('fileInfo');
const fileNameEl = document.getElementById('fileName');
const fileSizeEl = document.getElementById('fileSize');
const changeFileBtn = document.getElementById('changeFileBtn');
const pageTitleInput = document.getElementById('pageTitle');
const bgColorInput = document.getElementById('bgColor');
const bgColorHexInput = document.getElementById('bgColorHex');
const aspectRatioSelect = document.getElementById('aspectRatio');
const wpEmbedModeCheck = document.getElementById('wpEmbedMode');
const showControlsCheck = document.getElementById('showControls');
const autoStartCheck = document.getElementById('autoStart');
const turboModeCheck = document.getElementById('turboMode');
const convertBtn = document.getElementById('convertBtn');
const resultCard = document.getElementById('resultCard');
const outputSizeEl = document.getElementById('outputSize');
const downloadBtn = document.getElementById('downloadBtn');
const copyWpCodeBtn = document.getElementById('copyWpCodeBtn');
const previewBtn = document.getElementById('previewBtn');
const projectStatsEmpty = document.getElementById('projectStatsEmpty');
const projectStats = document.getElementById('projectStats');
const statSprites = document.getElementById('statSprites');
const statCostumes = document.getElementById('statCostumes');
const statSounds = document.getElementById('statSounds');
// State Aplikasi
let selectedFile = null;
let projectBase64 = null;
let generatedHtmlString = '';
let generatedWpSnippetString = '';
let generatedHtmlBlob = null;
let generatedFileName = 'scratch-project.html';
// Fungsi Utilitas: Menampilkan Notifikasi Kustom (Pengganti alert)
function showNotification(message, type = 'info') {
const box = document.getElementById('notificationBox');
const text = document.getElementById('notificationText');
const icon = document.getElementById('notificationIcon');
box.className = 'mb-6 p-4 rounded-xl border flex items-start justify-between transition-all duration-300';
if (type === 'error') {
box.classList.add('bg-red-50', 'border-red-200', 'text-red-800');
icon.setAttribute('data-lucide', 'alert-circle');
} else if (type === 'success') {
box.classList.add('bg-emerald-50', 'border-emerald-200', 'text-emerald-800');
icon.setAttribute('data-lucide', 'check-circle');
} else {
box.classList.add('bg-blue-50', 'border-blue-200', 'text-blue-800');
icon.setAttribute('data-lucide', 'info');
}
text.textContent = message;
box.classList.remove('hidden');
lucide.createIcons();
}
function hideNotification() {
document.getElementById('notificationBox').classList.add('hidden');
}
// Format ukuran byte ke KB / MB
function formatBytes(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
// Sinkronisasi pemilih warna
bgColorInput.addEventListener('input', (e) => {
bgColorHexInput.value = e.target.value;
});
// Event Drag & Drop dan Klik File
dropZone.addEventListener('click', () => fileInput.click());
changeFileBtn.addEventListener('click', (e) => {
e.stopPropagation();
fileInput.click();
});
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('dragover');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('dragover');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
if (e.dataTransfer.files.length > 0) {
handleFileSelection(e.dataTransfer.files[0]);
}
});
fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
handleFileSelection(e.target.files[0]);
}
});
// Memproses File .sb3 yang dipilih
async function handleFileSelection(file) {
hideNotification();
resultCard.classList.add('hidden');
if (!file.name.toLowerCase().endsWith('.sb3')) {
showNotification('Format file tidak valid! Harap pilih file proyek Scratch dengan ekstensi .sb3', 'error');
return;
}
selectedFile = file;
const cleanName = file.name.replace(/\.sb3$/i, '');
generatedFileName = cleanName.toLowerCase().replace(/[^a-z0-9]/g, '-') + '.html';
pageTitleInput.value = cleanName;
// Update UI file
uploadPrompt.classList.add('hidden');
fileInfo.classList.remove('hidden');
fileNameEl.textContent = file.name;
fileSizeEl.textContent = formatBytes(file.size);
try {
// Analisis isi .sb3 menggunakan JSZip
const zip = await JSZip.loadAsync(file);
const projectJsonFile = zip.file('project.json');
if (!projectJsonFile) {
throw new Error('File project.json tidak ditemukan di dalam arsip .sb3.');
}
const projectJsonText = await projectJsonFile.async('text');
const projectData = JSON.parse(projectJsonText);
// Hitung statistik sprite, kostum, suara
let spriteCount = 0;
let costumeCount = 0;
let soundCount = 0;
if (Array.isArray(projectData.targets)) {
projectData.targets.forEach(target => {
if (!target.isStage) spriteCount++;
if (Array.isArray(target.costumes)) costumeCount += target.costumes.length;
if (Array.isArray(target.sounds)) soundCount += target.sounds.length;
});
}
statSprites.textContent = spriteCount;
statCostumes.textContent = costumeCount;
statSounds.textContent = soundCount;
projectStatsEmpty.classList.add('hidden');
projectStats.classList.remove('hidden');
// Konversi file ke Base64 untuk ditanamkan ke HTML
const reader = new FileReader();
reader.onload = function(event) {
// Ambil string base64 murni tanpa prefix data:...
const base64String = event.target.result.split(',')[1];
projectBase64 = base64String;
// Aktifkan tombol konversi
convertBtn.disabled = false;
convertBtn.classList.remove('bg-slate-300', 'cursor-not-allowed');
convertBtn.classList.add('bg-orange-500', 'hover:bg-orange-600', 'cursor-pointer');
};
reader.readAsDataURL(file);
} catch (err) {
console.error(err);
showNotification('Gagal membaca file .sb3: ' + err.message, 'error');
resetFileSelection();
}
}
function resetFileSelection() {
selectedFile = null;
projectBase64 = null;
uploadPrompt.classList.remove('hidden');
fileInfo.classList.add('hidden');
projectStatsEmpty.classList.remove('hidden');
projectStats.classList.add('hidden');
convertBtn.disabled = true;
convertBtn.classList.add('bg-slate-300', 'cursor-not-allowed');
convertBtn.classList.remove('bg-orange-500', 'hover:bg-orange-600', 'cursor-pointer');
}
// Proses Pembuatan File HTML Mandiri
convertBtn.addEventListener('click', () => {
if (!projectBase64) return;
// Ubah status tombol menjadi loading
const originalBtnContent = convertBtn.innerHTML;
convertBtn.disabled = true;
convertBtn.innerHTML = `<svg class="animate-spin-custom w-5 h-5 mr-2 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg><span>Mengompilasi HTML...</span>`;
setTimeout(() => {
try {
const options = {
title: pageTitleInput.value || 'Proyek Scratch',
bgColor: bgColorInput.value,
aspectRatio: aspectRatioSelect.value,
wpEmbedMode: wpEmbedModeCheck.checked,
showControls: showControlsCheck.checked,
autoStart: autoStartCheck.checked,
turboMode: turboModeCheck.checked,
base64Data: projectBase64
};
generatedWpSnippetString = buildWordPressEmbedSnippet(options);
generatedHtmlString = buildStandaloneHTML(options);
generatedHtmlBlob = new Blob([generatedHtmlString], { type: 'text/html;charset=utf-8' });
outputSizeEl.textContent = formatBytes(generatedHtmlBlob.size);
resultCard.classList.remove('hidden');
showNotification('Berhasil! Anda dapat menyalin kode langsung untuk blok Custom HTML WordPress atau mengunduh filenya.', 'success');
} catch (error) {
showNotification('Terjadi kesalahan saat membuat file HTML: ' + error.message, 'error');
} finally {
convertBtn.disabled = false;
convertBtn.innerHTML = originalBtnContent;
lucide.createIcons();
}
}, 400);
});
// Generator Snippet Khusus Blok Custom HTML WordPress (Scoped & Responsif di dalam Artikel)
function buildWordPressEmbedSnippet(options) {
const safeTitle = options.title.replace(/</g, "<").replace(/>/g, ">");
const uniqueId = 'sc-wp-' + Math.random().toString(36).substring(2, 8);
let maxWidthRule = 'max-width: 760px;';
if (options.aspectRatio === 'standard') maxWidthRule = 'max-width: 500px;';
if (options.aspectRatio === 'large') maxWidthRule = 'max-width: 960px;';
return `<!-- Mulai Blok Game Scratch WordPress -->
<div id="${uniqueId}-header">
<div id="${uniqueId}-title-wrap">
<span id="${uniqueId}-badge">Interaktif</span>
<h4 id="${uniqueId}-title">${safeTitle}</h4>
</div>
<div id="${uniqueId}-actions">
<button type="button" id="${uniqueId}-start" class="${uniqueId}-btn">â–¶ Mulai</button>
<button type="button" id="${uniqueId}-stop" class="${uniqueId}-btn">â– Stop</button>
<button type="button" id="${uniqueId}-fs" class="${uniqueId}-btn" title="Layar Penuh">â›¶ Fullscreen</button>
</div>
</div>
<div id="${uniqueId}-stage-box">
<div id="${uniqueId}-loader">
<div class="${uniqueId}-spin"></div>
<span id="${uniqueId}-status">Menyiapkan Game Scratch...</span>
</div>
</div>
<div id="${uniqueId}-footer">
<span>Gunakan keyboard atau klik layar untuk bermain</span>
<span>Scratch 3.0 Web Player</span>
</div>
<script src="https://cdn.jsdelivr.net/npm/@turbowarp/scaffolding@0.2.0/dist/scaffolding-with-music.js"><\/script>
<script>
(function() {
const b64 = "${options.base64Data}";
function b64ToBuf(str) {
const bin = window.atob(str);
const bytes = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
return bytes.buffer;
}
async function boot() {
const box = document.getElementById('${uniqueId}-stage-box');
const loader = document.getElementById('${uniqueId}-loader');
const status = document.getElementById('${uniqueId}-status');
try {
if (typeof Scaffolding === 'undefined') {
await new Promise(r => setTimeout(r, 600));
}
const sc = new Scaffolding.Scaffolding();
sc.width = 480;
sc.height = 360;
sc.resizeMode = 'preserve-ratio';
sc.editableLists = false;
sc.shouldConnectPeripherals = true;
sc.usePackagedRuntime = true;
sc.setup();
sc.appendTo(box);
sc.vm.setTurboMode(${options.turboMode});
status.textContent = 'Memuat Aset...';
await sc.loadProject(b64ToBuf(b64));
loader.style.display = 'none';
document.getElementById('${uniqueId}-start').addEventListener('click', () => sc.greenFlag());
document.getElementById('${uniqueId}-stop').addEventListener('click', () => sc.stopAll());
document.getElementById('${uniqueId}-fs').addEventListener('click', () => {
const wrap = document.getElementById('${uniqueId}-container');
if (!document.fullscreenElement) wrap.requestFullscreen().catch(() => {});
else document.exitFullscreen();
});
if (${options.autoStart}) sc.greenFlag();
} catch (e) {
status.textContent = 'Gagal memuat game: ' + e.message;
status.style.color = '#f87171';
}
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);
else boot();
})();
<\/script>
`; }
// Fungsi Generator Kode HTML Mandiri (Halaman Penuh / Iframe WordPress)
function buildStandaloneHTML(options) {
const safeTitle = options.title.replace(/</g, "<").replace(/>/g, ">");
const snippet = buildWordPressEmbedSnippet(options);
return `<!DOCTYPE html>
${safeTitle} ${snippet} `; }
// Tombol Salin Kode Blok HTML WordPress (Menggunakan execCommand agar aman di iFrame)
copyWpCodeBtn.addEventListener('click', () => {
if (!generatedWpSnippetString) return;
const textArea = document.createElement('textarea');
textArea.value = generatedWpSnippetString;
textArea.style.position = 'fixed';
textArea.style.left = '-9999px';
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
showNotification('Kode blok WordPress berhasil disalin! Tempelkan ke blok "Custom HTML" di post WordPress Anda.', 'success');
} catch (err) {
showNotification('Gagal menyalin otomatis. Silakan unduh file HTML dan salin isinya.', 'error');
} finally {
document.body.removeChild(textArea);
}
});
// Tombol Unduh File HTML
downloadBtn.addEventListener('click', () => {
if (!generatedHtmlBlob) return;
const url = URL.createObjectURL(generatedHtmlBlob);
const a = document.createElement('a');
a.href = url;
a.download = generatedFileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
// Tombol Uji Coba Langsung di Tab Baru
previewBtn.addEventListener('click', () => {
if (!generatedHtmlBlob) return;
const url = URL.createObjectURL(generatedHtmlBlob);
window.open(url, '_blank');
});
</script>