avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 1 | chrome.storage.sync.get(null, function(options) { |
| 2 | if (options.profileindicator || options.profileindicatoralt) { |
| 3 | // In order to pass i18n strings and settings values to the injected script, |
| 4 | // which doesn't have access to the chrome.* APIs, we use event listeners. |
| 5 | window.addEventListener('TWPT_sendRequest', evt => { |
| 6 | var request = evt.detail; |
| 7 | switch (request.data.action) { |
| 8 | case 'geti18nMessage': |
| 9 | var data = chrome.i18n.getMessage( |
| 10 | request.data.msg, |
| 11 | (Array.isArray(request.data.placeholders) ? |
| 12 | request.data.placeholders : |
| 13 | [])); |
| 14 | break; |
| 15 | |
| 16 | case 'getProfileIndicatorOptions': |
| 17 | var data = { |
| 18 | 'indicatorDot': options.profileindicator, |
| 19 | 'numPosts': options.profileindicatoralt |
| 20 | }; |
| 21 | break; |
| 22 | |
| 23 | case 'getNumPostMonths': |
| 24 | var data = options.profileindicatoralt_months; |
| 25 | break; |
| 26 | |
| 27 | default: |
| 28 | var data = 'unknownAction'; |
| 29 | break; |
| 30 | } |
| 31 | var response = {data, requestId: request.id, prefix: 'TWPT'}; |
| 32 | |
| 33 | window.postMessage(response, '*'); |
| 34 | }); |
| 35 | |
| 36 | injectScript( |
| 37 | chrome.runtime.getURL('injections/profileindicator_inject.js')); |
| 38 | injectStylesheet( |
| 39 | chrome.runtime.getURL('injections/profileindicator_inject.css')); |
| 40 | } |
| 41 | }); |