MCPcopy Index your code
hub / github.com/mailvelope/mailvelope / initScriptInjection

Function initScriptInjection

src/lib/inject.js:15–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13export let watchlistRegex;
14
15export 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
43function filterURLsFromWatchList(watchList) {
44 const schemes = ['http', 'https'];

Callers 3

mainFunction · 0.90
onOkMethod · 0.90
setWatchListMethod · 0.90

Calls 6

getWatchListFunction · 0.90
getWatchListCacheFunction · 0.90
matchPattern2RegExStringFunction · 0.90
filterURLsFromWatchListFunction · 0.85
injectOpenTabsFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected