Adrià Vilanova Martínez | ba3eeba | 2021-07-25 12:22:02 +0200 | [diff] [blame] | 1 | import {injectScript, injectStylesheet} from '../../common/contentScriptsUtils.js'; |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 2 | |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 3 | import AutoRefresh from './autoRefresh.js'; |
| 4 | |
Adrià Vilanova Martínez | 2b87179 | 2021-06-09 12:35:06 +0200 | [diff] [blame] | 5 | const SMEI_UNIFIED_PROFILES = 9; |
| 6 | |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 7 | chrome.storage.sync.get(null, function(items) { |
Adrià Vilanova Martínez | d2ac4ce | 2021-06-11 16:41:43 +0200 | [diff] [blame] | 8 | /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */ |
Adrià Vilanova Martínez | ba3eeba | 2021-07-25 12:22:02 +0200 | [diff] [blame] | 9 | if (items.loaddrafts || items.disableunifiedprofiles) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 10 | var startup = |
| 11 | JSON.parse(document.querySelector('html').getAttribute('data-startup')); |
avm99963 | c19497f | 2019-08-23 00:15:11 +0200 | [diff] [blame] | 12 | |
| 13 | if (items.loaddrafts) { |
| 14 | startup[4][13] = true; |
| 15 | } |
| 16 | |
Adrià Vilanova Martínez | 2b87179 | 2021-06-09 12:35:06 +0200 | [diff] [blame] | 17 | if (items.disableunifiedprofiles) { |
| 18 | var index = startup[1][6].indexOf(SMEI_UNIFIED_PROFILES); |
Adrià Vilanova Martínez | d2ac4ce | 2021-06-11 16:41:43 +0200 | [diff] [blame] | 19 | if (index > -1) startup[1][6].splice(index, 1); |
avm99963 | b38b741 | 2020-12-11 17:59:02 +0100 | [diff] [blame] | 20 | } |
| 21 | |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 22 | document.querySelector('html').setAttribute( |
| 23 | 'data-startup', JSON.stringify(startup)); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 24 | } |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 25 | |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 26 | // Initialized here instead of in main.js so the first |ViewForumResponse| |
| 27 | // event is received if it happens when the page loads. |
| 28 | if (items.autorefreshlist) |
avm99963 | fd22267 | 2021-08-12 23:23:01 +0200 | [diff] [blame] | 29 | window.TWPTAutoRefresh = new AutoRefresh(); |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 30 | |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 31 | if (items.ccdarktheme) { |
| 32 | switch (items.ccdarktheme_mode) { |
| 33 | case 'switch': |
| 34 | if (items.ccdarktheme_switch_status == true) |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 35 | injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css')); |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 36 | break; |
| 37 | |
| 38 | case 'system': |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 39 | injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), { |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 40 | 'media': '(prefers-color-scheme: dark)', |
| 41 | }); |
| 42 | break; |
| 43 | } |
| 44 | } |
Adrià Vilanova Martínez | 43ec2b9 | 2021-07-16 18:44:54 +0200 | [diff] [blame] | 45 | |
| 46 | injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js')); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 47 | }); |