Introduction
Introduction Statistics Contact Development Disclaimer Help
background.js - firefox-fix-web - Firefox extension: fix web
git clone git://git.codemadness.org/firefox-fix-web
Log
Files
Refs
README
LICENSE
---
background.js (2771B)
---
1 /* what this file does:
2 - rewrites User-Agent headers.
3 - sets consent cookie for Google and Youtube. */
4
5 function main(info) {
6
7 /* get current running Firefox version, to always keep up-to-date */
8 var ff_version = info.version || "72.0";
9
10 /* User-Agent's */
11 // Windows 7 (64-bit)
12 var ua_windows7 = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:" + ff_ve…
13 // Windows 10 (64-bit)
14 var ua_windows10 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:" + ff_…
15 // Windows 10 Chrome, NOTE: update version manually if needed.
16 var ua_windows10_chrome = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) App…
17
18 // OpenBSD amd64
19 var ua_openbsd = "Mozilla/5.0 (X11; OpenBSD amd64; rv:" + ff_version + "…
20
21 var ua_none = "";
22 var ua_default = ua_windows10;
23
24 var prefix = "^(http|https):\/\/([^\.]+\.)?"; // HTTP and HTTPS, optiona…
25 var patterns = [
26 // Twitter: remove User-Agent, this prevents an annoying redirec…
27 {
28 "re": new RegExp(prefix + "twitter\.com\/.*"),
29 "ua": ua_windows10
30 }
31 ];
32
33 function rewriteua(e) {
34 var headers = e.requestHeaders;
35 for (var j = 0; j < headers.length; j++) {
36 var header = headers[j];
37 if (header.name.toLowerCase() !== "user-agent")
38 continue;
39 var ua = ua_default;
40 var url = e.documentUrl || e.url || "";
41 for (var p of patterns) {
42 var m = p.re.exec(url);
43 if (m === null)
44 continue;
45 ua = p.ua;
46 break;
47 }
48 if (ua !== "")
49 header.value = ua;
50 else
51 delete headers[j];
52 }
53
54 return { requestHeaders: headers };
55 }
56
57 chrome.webRequest.onBeforeSendHeaders.addListener(
58 rewriteua,
59 { urls: [ "<all_urls>" ]},
60 ["blocking", "requestHeaders"]
61 );
62
63 // "forced consent"...
64 function google_forced_consent(e) {
65 var r = parseInt(100+(Math.random() * 899));
66 // var r = 101;
67 var value = "CONSENT=YES+cb.20210328-17-p0.en+FX+" + r.toString(…
68 var headers = e.requestHeaders;
69 var cookieset = 0;
70 for (var j = 0; j < headers.length; j++) {
71 var header = headers[j];
72 if (header.name.toLowerCase() !== "cookie")
73 continue;
74
75 header.value = value;
76
77 cookieset = 1;
78 }
79 if (!cookieset)
80 headers.set("Cookie", value);
81 return { requestHeaders: headers };
82 }
83
84 chrome.webRequest.onBeforeSendHeaders.addListener(
85 google_forced_consent,
86 {
87 // urls: [ "<all_urls>" ]},
88 urls: [
89 // "*://*/*",
90 "*://*.google.com/*",
91 "*://google.com/*",
92 "*://*.google.nl/*",
93 "*://google.nl/*",
94 "*://*.youtube.com/*",
95 "*://youtube.com/*",
96 "*://*.youtu.be/*",
97 "*://youtu.be/*",
98 "*://*.gstatic.com/*"
99 ]
100 },
101 ["blocking", "requestHeaders"]
102 );
103
104 }
105
106 browser.runtime.getBrowserInfo().then(main);
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.