Refactor extension to webpack
This change is the biggest in the history of the project. The entire
project has been refactored so it is built with webpack.
This involves:
- Creating webpack and npm config files.
- Fixing some bugs in the code due to the fact that webpack uses strict
mode.
- Merging some pieces of code which were shared throughout the codebase
(not exhaustive, more work should be done in this direction).
- Splitting the console_inject.js file into separate files (it had 1000+
lines).
- Adapting all the build-related files (Makefile, bash scripts, etc.)
- Changing the docs to explain the new build process.
- Changing the Zuul playbook/roles to adapt to the new build process.
Change-Id: I16476d47825461c3a318b3f1a1eddb06b2df2e89
diff --git a/src/common/csEventListener.js b/src/common/csEventListener.js
new file mode 100644
index 0000000..14b4295
--- /dev/null
+++ b/src/common/csEventListener.js
@@ -0,0 +1,43 @@
+// In order to pass i18n strings and settings values to the injected scripts,
+// which don't have access to the chrome.* APIs, we use event listeners.
+
+export function setUpListener() {
+ chrome.storage.sync.get(null, function(options) {
+ window.addEventListener('TWPT_sendRequest', evt => {
+ var request = evt.detail;
+ switch (request.data.action) {
+ case 'geti18nMessage':
+ var data = chrome.i18n.getMessage(
+ request.data.msg,
+ (Array.isArray(request.data.placeholders) ?
+ request.data.placeholders :
+ []));
+ break;
+
+ case 'getProfileIndicatorOptions':
+ var data = {
+ 'indicatorDot': options.profileindicator,
+ 'numPosts': options.profileindicatoralt
+ };
+ break;
+
+ case 'getNumPostMonths':
+ var data = options.profileindicatoralt_months;
+ break;
+
+ default:
+ var data = 'unknownAction';
+ console.warn('Unknown action ' + request.data.action + '.');
+ break;
+ }
+
+ var response = {
+ data,
+ requestId: request.id,
+ prefix: (request.prefix || 'TWPT'),
+ };
+
+ window.postMessage(response, '*');
+ });
+ });
+}