(defaultEnabledCategories)
| 14 | * @param {string[]} [defaultEnabledCategories] |
| 15 | */ |
| 16 | export const manageExistingScripts = (defaultEnabledCategories) => { |
| 17 | const { |
| 18 | _acceptedServices, |
| 19 | _lastChangedServices, |
| 20 | _allCategoryNames, |
| 21 | _allDefinedServices, |
| 22 | _allScriptTags, |
| 23 | _savedCookieContent, |
| 24 | _lastChangedCategoryNames, |
| 25 | } = globalObj._state; |
| 26 | |
| 27 | /** |
| 28 | * Automatically Enable/Disable internal services |
| 29 | */ |
| 30 | for (const categoryName of _allCategoryNames) { |
| 31 | const lastChangedServices = _lastChangedServices[categoryName] |
| 32 | || _acceptedServices[categoryName] |
| 33 | || []; |
| 34 | |
| 35 | for (const serviceName of lastChangedServices) { |
| 36 | const service = _allDefinedServices[categoryName][serviceName]; |
| 37 | |
| 38 | if (!service) |
| 39 | continue; |
| 40 | |
| 41 | const { onAccept, onReject } = service; |
| 42 | |
| 43 | if ( |
| 44 | !service._enabled |
| 45 | && elContains(_acceptedServices[categoryName], serviceName) |
| 46 | ) { |
| 47 | service._enabled = true; |
| 48 | isFunction(onAccept) && onAccept(); |
| 49 | } |
| 50 | |
| 51 | else if ( |
| 52 | service._enabled |
| 53 | && !elContains(_acceptedServices[categoryName], serviceName) |
| 54 | ) { |
| 55 | service._enabled = false; |
| 56 | isFunction(onReject) && onReject(); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if (!globalObj._config.manageScriptTags) |
| 62 | return; |
| 63 | |
| 64 | const scripts = _allScriptTags; |
| 65 | const acceptedCategories = defaultEnabledCategories |
| 66 | || _savedCookieContent.categories |
| 67 | || []; |
| 68 | |
| 69 | /** |
| 70 | * Load scripts (sequentially), using a recursive function |
| 71 | * which loops through the scripts array |
| 72 | * @param {import('../core/global').ScriptInfo[]} scripts scripts to load |
| 73 | * @param {number} index current script to load |
no test coverage detected
searching dependent graphs…