Adrià Vilanova Martínez | 43ec2b9 | 2021-07-16 18:44:54 +0200 | [diff] [blame] | 1 | import {injectStylesheet, injectScript} from '../../common/contentScriptsUtils.js'; |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 2 | |
Adrià Vilanova Martínez | 2b87179 | 2021-06-09 12:35:06 +0200 | [diff] [blame] | 3 | const SMEI_SORT_DIRECTION = 8; |
| 4 | const SMEI_UNIFIED_PROFILES = 9; |
| 5 | |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 6 | chrome.storage.sync.get(null, function(items) { |
Adrià Vilanova Martínez | d2ac4ce | 2021-06-11 16:41:43 +0200 | [diff] [blame] | 7 | /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */ |
| 8 | if (items.loaddrafts || items.smei_sortdirection || |
| 9 | 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 | |
avm99963 | b38b741 | 2020-12-11 17:59:02 +0100 | [diff] [blame] | 17 | if (items.smei_sortdirection) { |
Adrià Vilanova Martínez | 2b87179 | 2021-06-09 12:35:06 +0200 | [diff] [blame] | 18 | if (!startup[1][6].includes(SMEI_SORT_DIRECTION)) |
| 19 | startup[1][6].push(SMEI_SORT_DIRECTION); |
| 20 | } |
| 21 | |
| 22 | if (items.disableunifiedprofiles) { |
| 23 | var index = startup[1][6].indexOf(SMEI_UNIFIED_PROFILES); |
Adrià Vilanova Martínez | d2ac4ce | 2021-06-11 16:41:43 +0200 | [diff] [blame] | 24 | if (index > -1) startup[1][6].splice(index, 1); |
avm99963 | b38b741 | 2020-12-11 17:59:02 +0100 | [diff] [blame] | 25 | } |
| 26 | |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 27 | document.querySelector('html').setAttribute( |
| 28 | 'data-startup', JSON.stringify(startup)); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 29 | } |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 30 | |
| 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 | }); |