📜
instafile.js
Back
📝 Javascript ⚡ Executable Ctrl+S: Save • Ctrl+R: Run • Ctrl+F: Find
(function () { window.FileCommands = window.FileCommands || []; window.FileCommands.push({ id: "instafile", label: "📝 Replace File (InstaFile)", appliesTo: (file) => !file.is_dir, action: async ({ file, currentPath, showToast, confirmModal, reload }) => { const fullPath = `${currentPath}/${file.name}`; console.log(`[instafile.js] Replacing: ${fullPath}`); // Build a temporary modal for text input const modal = document.getElementById("fmModal"); const titleEl = document.getElementById("fmModalTitle"); const bodyEl = document.getElementById("fmModalBody"); const btnCancel = document.getElementById("fmModalCancel"); const btnConfirm = document.getElementById("fmModalConfirm"); titleEl.textContent = `📝 Replace: ${file.name}`; btnConfirm.textContent = "Replace File"; btnConfirm.className = "fm-btn fm-btn--danger"; bodyEl.innerHTML = ` <p style="color: #94a3b8; margin-bottom: 12px;"> Paste new content to replace <strong>${file.name}</strong>: </p> <textarea id="instaReplaceContent" placeholder="Paste your content here..." style="width:100%; min-height:250px; padding:8px; background:#0f172a; border:1px solid #2a3648; border-radius:6px; color:#e6edf3; font-family:monospace; font-size:13px; resize:vertical;" ></textarea> `; modal.setAttribute("aria-hidden", "false"); setTimeout(() => { const ta = document.getElementById("instaReplaceContent"); if (ta) ta.focus(); }, 100); const cleanup = () => { modal.setAttribute("aria-hidden", "true"); btnCancel.removeEventListener("click", onCancel); btnConfirm.removeEventListener("click", onConfirm); }; const onCancel = () => cleanup(); const onConfirm = async () => { const content = document.getElementById("instaReplaceContent").value; if (!content) { showToast("Please enter some content", "error"); return; } try { btnConfirm.disabled = true; btnConfirm.textContent = "Replacing..."; const res = await fetch("instafile.php", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ path: fullPath, content }) }); const data = await res.json(); if (data.success) { showToast(`✅ ${file.name} replaced successfully!`); reload(); cleanup(); } else { throw new Error(data.message || "Replace failed"); } } catch (err) { showToast("Error: " + err.message, "error"); btnConfirm.disabled = false; btnConfirm.textContent = "Replace File"; } }; btnCancel.addEventListener("click", onCancel); btnConfirm.addEventListener("click", onConfirm); } }); console.log("[instafile.js] Registered InstaFile command"); })();