-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
40 lines (33 loc) · 1.36 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
32
33
34
35
36
37
38
39
40
const user_agent = "Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Xbox; Xbox One) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36 Mobile Edge/42.0.0.2028";
var browser = browser || chrome
browser.webRequest.onBeforeSendHeaders.addListener(
function (details) {
if (!details.requestHeaders) {
return;
}
for (let i = 0; i < details.requestHeaders.length; i++) {
if (details.requestHeaders[i].name.toLowerCase() === "user-agent") { // headers are case-insensitive
details.requestHeaders[i].value = user_agent;
break;
}
}
return { requestHeaders: details.requestHeaders };
},
{ urls: ["*://*.youtube.com/*"] },
["blocking", "requestHeaders"]
);
browser.webRequest.onBeforeRequest.addListener(
function(details) {
console.log("hello?");
if (details.url.startsWith("https://m.youtube.com") || details.url.startsWith("http://m.youtube.com")) {
console.log("detected!");
const urlString = details.url.replace("m.youtube.com", "www.youtube.com");
const url = new URL(urlString);
url.searchParams.set('app', 'desktop');
return { redirectUrl: url.href };
}
return {};
},
{ urls: ["*://m.youtube.com/*"] },
["blocking"]
);