()
| 13 | export let watchlistRegex; |
| 14 | |
| 15 | export async function initScriptInjection() { |
| 16 | try { |
| 17 | watchlistRegex = []; |
| 18 | const watchList = isChrome ? await getWatchList() : await getWatchListCache(); |
| 19 | const filterURL = filterURLsFromWatchList(watchList); |
| 20 | const matchPatterns = filterURL.map(({schemes, host}) => { |
| 21 | const scheme = schemes.includes('http') ? '*' : 'https'; |
| 22 | // filter out port numbers |
| 23 | host = host.includes(':') ? host.replace(/:\d{1,5}$/, '') : host; |
| 24 | return `${scheme}://${host}/*`; |
| 25 | }); |
| 26 | const originAndPathFilter = {url: filterURL.map(({schemes, host}) => { |
| 27 | const originAndPathMatches = `^${schemes.includes('http') ? 'https?' : 'https'}:\/\/${matchPattern2RegExString(host)}/.*`; |
| 28 | watchlistRegex.push(new RegExp(originAndPathMatches)); |
| 29 | return {schemes, originAndPathMatches}; |
| 30 | })}; |
| 31 | if (chrome.webNavigation.onDOMContentLoaded.hasListener(watchListNavigationHandler)) { |
| 32 | chrome.webNavigation.onDOMContentLoaded.removeListener(watchListNavigationHandler); |
| 33 | } |
| 34 | if (matchPatterns.length) { |
| 35 | chrome.webNavigation.onDOMContentLoaded.addListener(watchListNavigationHandler, originAndPathFilter); |
| 36 | } |
| 37 | return injectOpenTabs(matchPatterns); |
| 38 | } catch (e) { |
| 39 | console.log('mailvelope initScriptInjection', e); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | function filterURLsFromWatchList(watchList) { |
| 44 | const schemes = ['http', 'https']; |
no test coverage detected