This commit is contained in:
Tobias Miesel
2018-07-05 12:20:24 +02:00
parent cbf79b960c
commit a1b1010c18
9 changed files with 4399 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules/*

198
bundle.js Normal file
View File

@@ -0,0 +1,198 @@
/* -------------------------------------------------- */
/* 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?");
/***/ })
/******/ });

View File

@@ -21,13 +21,6 @@
"optional_permissions": [ "optional_permissions": [
"*://*/" "*://*/"
], ],
"background": {
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/select2/select2.js",
"background.min.js"
]
},
"browser_action": { "browser_action": {
"default_icon": "src/images/logo.png", "default_icon": "src/images/logo.png",
"default_title": "MOCO Time Tracking", "default_title": "MOCO Time Tracking",

10
options.html Normal file
View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
</head>
<body class='moco-options'>
<div id="moco"></div>
<script src="bundle.js"></script>
</body>
</html>

4152
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

14
package.json Normal file
View File

@@ -0,0 +1,14 @@
{
"name": "moco-browser-extensions",
"description": "Browser plugin for MOCO",
"version": "0.9.20",
"main": "bundle.js",
"scripts": {
"webpack": "webpack --mode=development --watch"
},
"devDependencies": {
"webpack": "^4.15.0",
"webpack-cli": "^3.0.8",
"webpack-chrome-extension-reloader": "^0.8.3"
}
}

1
popup.html Normal file
View File

@@ -0,0 +1 @@
MOCO POPUP

1
src/js/index.js Normal file
View File

@@ -0,0 +1 @@
alert("ok")

22
webpack.config.js Normal file
View File

@@ -0,0 +1,22 @@
const path = require('path')
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader')
module.exports = {
entry: {
content: './src/js/index.js',
},
output: {
path: path.resolve(__dirname),
filename: 'bundle.js',
},
plugins: [
new ChromeExtensionReloader({
port: 9090, // Which port use to create the server
reloadPage: true, // Force the reload of the page also
entries: { //The entries used for the content/background scripts
contentScript: 'content', //Use the entry names, not the file name or the path
background: 'background'
}
})
]
}