-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.ts
49 lines (44 loc) · 1.09 KB
/
background.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const medium_post_url_regex = RegExp("(/@[^/]+)?/[^@][^/]*-[^/]+")
function redirect(requestDetails: {
requestId: string;
url: string;
method: string;
frameId: number;
parentFrameId: number;
requestBody?: {
error?: string;
formData?: { [key: string]: string[] };
raw?: browser.webRequest.UploadData[];
};
tabId: number;
type: browser.webRequest.ResourceType;
timeStamp: number;
originUrl: string;
}) {
let new_url = new URL(requestDetails.url)
const path = new_url.pathname
if (path.startsWith("/m/global-identity")) {
const url = new_url.searchParams.get('redirectUrl')
if (!url) return {}
new_url = new URL(url);
} else if (!medium_post_url_regex.test(path)) {
return {}
}
new_url.hostname = "scribe.rip"
new_url.search = ""
return {
redirectUrl: new_url.href
}
}
browser.webRequest.onBeforeRequest.addListener(
redirect,
{
urls: [
"https://medium.com/*",
"https://*.medium.com/*",
],
types:["main_frame", "xmlhttprequest", "sub_frame", "other"]
},
["blocking"],
)
export {}