// == Universal Message Interceptor with Edit/Resend == (function() { const manager = window.netManager || window.fnNet; if (!manager) { console.warn("Net manager not found. Adjust the object name."); return; } const originalSend = manager.send; const messageHistory = []; // Store intercepted messages // Intercept all messages manager.send = function(msgType, payload) { const index = messageHistory.length; if (logger){console.log(`[Intercepted #${index}]`, msgType, payload);} // Deep copy to avoid reference issues messageHistory.push({ msgType, payload: JSON.parse(JSON.stringify(payload)) }); return originalSend.call(this, msgType, payload); }; /** * Resend a previously intercepted message, optionally modified * @param {number} index - Index of intercepted message (default: last one) * @param {object} edits - Object containing edits to apply to the payload */ window.editAndSendMessage = function(index = -1, edits = {}) { if (index === -1) index = messageHistory.length - 1; const record = messageHistory[index]; if (!record) return console.warn("No message at index", index); // Clone the payload to modify safely const msg = JSON.parse(JSON.stringify(record.payload)); // Apply edits Object.assign(msg, edits); console.log(`[Sending modified message #${index}]`, record.msgType, msg); originalSend.call(manager, record.msgType, msg); }; console.log("Message interceptor active. Use `editAndSendMessage(index, edits)` to resend messages with modifications."); })();