blob: c7de08fa51169cb6b4070bdaa730ea7b6ea05326 [file] [log] [blame]
avm999633e238882020-12-07 18:38:54 +01001// In order to pass i18n strings and settings values to the injected scripts,
2// which don't have access to the chrome.* APIs, we use event listeners.
avm999632c994fd2020-12-08 13:04:40 +01003chrome.storage.sync.get(null, function(options) {
4 window.addEventListener('TWPT_sendRequest', evt => {
5 var request = evt.detail;
6 switch (request.data.action) {
7 case 'geti18nMessage':
8 var data = chrome.i18n.getMessage(
9 request.data.msg,
10 (Array.isArray(request.data.placeholders) ?
11 request.data.placeholders :
12 []));
13 break;
avm999633e238882020-12-07 18:38:54 +010014
avm999632c994fd2020-12-08 13:04:40 +010015 case 'getProfileIndicatorOptions':
16 var data = {
17 'indicatorDot': options.profileindicator,
18 'numPosts': options.profileindicatoralt
19 };
20 break;
avm999633e238882020-12-07 18:38:54 +010021
avm999632c994fd2020-12-08 13:04:40 +010022 case 'getNumPostMonths':
23 var data = options.profileindicatoralt_months;
24 break;
avm999633e238882020-12-07 18:38:54 +010025
avm999632c994fd2020-12-08 13:04:40 +010026 default:
27 var data = 'unknownAction';
28 console.warn('Unknown action ' + request.data.action + '.');
29 break;
30 }
avm999633e238882020-12-07 18:38:54 +010031
avm999632c994fd2020-12-08 13:04:40 +010032 var response = {
33 data,
34 requestId: request.id,
35 prefix: (request.prefix || 'TWPT'),
36 };
avm999633e238882020-12-07 18:38:54 +010037
avm999632c994fd2020-12-08 13:04:40 +010038 window.postMessage(response, '*');
39 });
avm999633e238882020-12-07 18:38:54 +010040});