Fix regression: some requests in the CS/I bridge failed
Commit 3e23888, where the content scripts/injections bridge was
refactored, introduced the regression being fixed in this change.
Basically, the options variable was no longer set at the content script
part of the bridge, and so some requests would fail.
Change-Id: I3861ac638dd2733c8be81ee3496322ce6fa16d6a
diff --git a/src/common/cs_event_listener.js b/src/common/cs_event_listener.js
index c32d9b8..c7de08f 100644
--- a/src/common/cs_event_listener.js
+++ b/src/common/cs_event_listener.js
@@ -1,38 +1,40 @@
// 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.
-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;
+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 'getProfileIndicatorOptions':
+ var data = {
+ 'indicatorDot': options.profileindicator,
+ 'numPosts': options.profileindicatoralt
+ };
+ break;
- case 'getNumPostMonths':
- var data = options.profileindicatoralt_months;
- break;
+ case 'getNumPostMonths':
+ var data = options.profileindicatoralt_months;
+ break;
- default:
- var data = 'unknownAction';
- console.warn('Unknown action ' + request.data.action + '.');
- break;
- }
+ default:
+ var data = 'unknownAction';
+ console.warn('Unknown action ' + request.data.action + '.');
+ break;
+ }
- var response = {
- data,
- requestId: request.id,
- prefix: (request.prefix || 'TWPT'),
- };
+ var response = {
+ data,
+ requestId: request.id,
+ prefix: (request.prefix || 'TWPT'),
+ };
- window.postMessage(response, '*');
+ window.postMessage(response, '*');
+ });
});