(function(){
  var s = document.currentScript;
  if (!s) return;
  var base = s.dataset.base || '';
  var id = s.dataset.id || '';
  if (!window.chrome) window.chrome = {};
  if (!window.chrome.runtime) window.chrome.runtime = {};
  if (!window.chrome.runtime.id) window.chrome.runtime.id = id;
  if (!window.chrome.runtime.getURL) window.chrome.runtime.getURL = function(p){ return base + p; };
  if (!window.chrome.runtime.sendMessage) {
    window.chrome.runtime.sendMessage = function(message, sendResponse) {
      var mid = 'raw_' + Date.now() + '_' + Math.random();
      window.postMessage({ type: 'raw_runtime_sendMessage', messageId: mid, message: message, source: 'mcj_page' }, '*');
      if (typeof sendResponse === 'function') {
        var handler = function(e) {
          if (e.data && e.data.type === 'raw_runtime_sendMessage_response' && e.data.messageId === mid) {
            window.removeEventListener('message', handler);
            sendResponse(e.data.response);
          }
        };
        window.addEventListener('message', handler);
      }
    };
  }
  if (!window.browser) window.browser = { runtime: {} };
  if (!window.browser.runtime.getURL) window.browser.runtime.getURL = function(p){ return base + p; };
  window.__mcj_main_world__ = true;
})();
