-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
background.js
31 lines (29 loc) · 1.38 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Pattern matching the prefix of at least one stripped query string
* parameter. We'll search the query string portion of the URL for this
* pattern to determine if there's any stripping work to do.
*/
const searchPattern = new RegExp('utm_|stm_|clid|_hs|icid|igshid|mc_|mkt_tok|yclid|_openstat|wicked|otc|oly_|rb_clickid|soc_|cvid|oicd|vgo_ee', 'i');
/*
* Pattern matching the query string parameters (key=value) that will be
* stripped from the final URL.
*/
const replacePattern = new RegExp(
'([?&]' +
'(icid|mkt_tok|(g|fb)clid|igshid|_hs(enc|mi)|mc_[ce]id|(utm|stm)_(id|source|medium|term|campaign|content|cid|internal|reader|referrer|name|social|social-type|klaviyo_id)|rb_clickid|yclid|_openstat|wickedid|otc|oly_(anon|enc)_id|soc_(src|trk)|cvid|oicd|vgo_ee)' +
'=[^&#]*)',
'ig');
chrome.webRequest.onBeforeRequest.addListener((details) => {
const url = details.url;
const queryStringIndex = url.indexOf('?');
if (url.search(searchPattern) > queryStringIndex) {
let stripped = url.replace(replacePattern, '');
if (stripped.charAt(queryStringIndex) === '&') {
stripped = `${stripped.substr(0, queryStringIndex)}?${stripped.substr(queryStringIndex + 1)}`;
}
if (stripped != url) {
return {redirectUrl: stripped};
}
}
},
{urls: ['https://*/*?*', 'http://*/*?*'], types: ['main_frame']}, ['blocking']);