/**
 * STONK KOC - Collector Bridge (ISOLATED world)
 * Lắng nghe messages từ hook → forward lên background
 */
(function () {
  window.addEventListener("message", event => {
    if (event.source !== window) return;
    const msg = event.data;
    if (!msg || msg.source !== "stonk-koc-hook") return;

    if (msg.type === "upload") {
      chrome.runtime.sendMessage({
        action: { type: "event", name: "collectorPush" },
        data: { url: msg.url, body: msg.body, timestamp: Date.now() },
      }, res => {
        if (chrome.runtime.lastError) {
          // Silently ignore — background may be restarting
        }
      });
    }
  });

  console.log("[STONK KOC] Collector Bridge Active");
})();
