/* -------------------------------------------------- */ /* Start of Webpack Chrome Hot Extension Middleware */ /* ================================================== */ /* This will be converted into a lodash templ., any */ /* external argument must be provided using it */ /* -------------------------------------------------- */ (function (chrome, window) { var signals = JSON.parse('{"SIGN_CHANGE":"SIGN_CHANGE","SIGN_RELOAD":"SIGN_RELOAD","SIGN_RELOADED":"SIGN_RELOADED","SIGN_LOG":"SIGN_LOG","SIGN_CONNECT":"SIGN_CONNECT"}'); var config = JSON.parse('{"RECONNECT_INTERVAL":2000,"SOCKET_ERR_CODE_REF":"https://tools.ietf.org/html/rfc6455#section-7.4.1"}'); var reloadPage = "true" === "true"; var wsHost = "ws://localhost:9090"; var SIGN_CHANGE = signals.SIGN_CHANGE, SIGN_RELOAD = signals.SIGN_RELOAD, SIGN_RELOADED = signals.SIGN_RELOADED, SIGN_LOG = signals.SIGN_LOG, SIGN_CONNECT = signals.SIGN_CONNECT; var RECONNECT_INTERVAL = config.RECONNECT_INTERVAL, SOCKET_ERR_CODE_REF = config.SOCKET_ERR_CODE_REF; var runtime = chrome.runtime, tabs = chrome.tabs; var manifest = runtime.getManifest(); var formatter = function formatter(msg) { return '[ WCER: ' + msg + ' ]'; }; var logger = function logger(msg) { var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "info"; return console[level](formatter(msg)); }; var timeFormatter = function timeFormatter(date) { return date.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"); }; function contentScriptWorker() { runtime.sendMessage({ type: SIGN_CONNECT }, function (msg) { return console.info(msg); }); runtime.onMessage.addListener(function (_ref) { var type = _ref.type, payload = _ref.payload; switch (type) { case SIGN_RELOAD: logger("Detected Changes. Reloading ..."); reloadPage && window.location.reload(); break; case SIGN_LOG: console.info(payload); break; } }); } function backgroundWorker(socket) { runtime.onMessage.addListener(function (action, sender, sendResponse) { if (action.type === SIGN_CONNECT) { sendResponse(formatter("Connected to Chrome Extension Hot Reloader")); } }); socket.addEventListener("message", function (_ref2) { var data = _ref2.data; var _JSON$parse = JSON.parse(data), type = _JSON$parse.type, payload = _JSON$parse.payload; if (type === SIGN_CHANGE) { tabs.query({ status: "complete" }, function (loadedTabs) { loadedTabs.forEach(function (tab) { return tabs.sendMessage(tab.id, { type: SIGN_RELOAD }); }); socket.send(JSON.stringify({ type: SIGN_RELOADED, payload: formatter(timeFormatter(new Date()) + ' - ' + manifest.name + ' successfully reloaded') })); runtime.reload(); }); } else { runtime.sendMessage({ type: type, payload: payload }); } }); socket.addEventListener("close", function (_ref3) { var code = _ref3.code; logger('Socket connection closed. Code ' + code + '. See more in ' + SOCKET_ERR_CODE_REF, "warn"); var intId = setInterval(function () { logger("WEPR Attempting to reconnect ..."); var ws = new WebSocket(wsHost); ws.addEventListener("open", function () { clearInterval(intId); logger("Reconnected. Reloading plugin"); runtime.reload(); }); }, RECONNECT_INTERVAL); }); } runtime.reload ? backgroundWorker(new WebSocket(wsHost)) : contentScriptWorker(); })(chrome, window); /* ----------------------------------------------- */ /* End of Webpack Chrome Hot Extension Middleware */ /* ----------------------------------------------- *//******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "./src/js/index.js"); /******/ }) /************************************************************************/ /******/ ({ /***/ "./src/js/index.js": /*!*************************!*\ !*** ./src/js/index.js ***! \*************************/ /*! no static exports found */ /***/ (function(module, exports) { eval("alert(\"ok\")\n\n\n//# sourceURL=webpack:///./src/js/index.js?"); /***/ }) /******/ });