Introduction
Introduction Statistics Contact Development Disclaimer Help
add support for web request header filtering - firefox-fix-web - Firefox extens…
git clone git://git.codemadness.org/firefox-fix-web
Log
Files
Refs
README
LICENSE
---
commit c1a70013f87cc63d47ae971168b21aa31ba3ca67
parent f0549950ceb52a2e435fb476d3288932feee9e76
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 22 Mar 2020 23:32:17 +0100
add support for web request header filtering
For now only used for setting the User-Agent. It detects the current running
versions, but spoofs the rest. By default Windows is used.
For twitter.com the User-Agent is reset so it doesn't redirect and doesn't
give an annoying message.
Diffstat:
A extension/background.js | 54 +++++++++++++++++++++++++++++…
M extension/manifest.json | 4 ++--
2 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/extension/background.js b/extension/background.js
@@ -0,0 +1,54 @@
+browser.runtime.getBrowserInfo().then(main);
+
+function main(info) {
+
+/* get current running Firefox version, to always keep up-to-date */
+var ff_version = info.version || "72.0";
+
+/* User-Agent's */
+var ua_windows = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:" + ff_version +…
+var ua_openbsd = "Mozilla/5.0 (X11; OpenBSD amd64; rv:" + ff_version + ") Geck…
+var ua_none = "";
+var ua_default = ua_windows;
+
+var prefix = "^(http|https):\/\/([^\.]+\.)?"; // HTTP and HTTPS, optional subd…
+var patterns = [
+ // Twitter: remove User-Agent, this prevents an annoying redirect to "…
+ {
+ "re": new RegExp(prefix + "twitter\.com\/.*"),
+ "ua": ua_none
+ }
+];
+
+function rewriteua(e) {
+ var headers = e.requestHeaders;
+ for (var j = 0; j < headers.length; j++) {
+ var header = headers[j];
+ if (header.name.toLowerCase() !== "user-agent")
+ continue;
+ var ua = ua_default;
+ var url = e.originUrl || e.url || "";
+ for (var p of patterns) {
+ var m = p.re.exec(url);
+ if (m === null)
+ continue;
+ ua = p.ua;
+ break;
+ }
+ if (ua !== "")
+ header.value = ua;
+ else
+ delete headers[j];
+ }
+
+// console.log(e); // DEBUG
+ return { requestHeaders: headers };
+}
+
+chrome.webRequest.onBeforeSendHeaders.addListener(
+ rewriteua,
+ { urls: [ "<all_urls>" ]},
+ ["blocking", "requestHeaders"]
+);
+
+}
diff --git a/extension/manifest.json b/extension/manifest.json
@@ -3,8 +3,8 @@
"name": "fix-web",
"version": "1.0",
"description": "Scripts to make the web suck less and fixup some thing…
- "permissions": [ "activeTab" ],
- "background": { "scripts": [] },
+ "permissions": [ "<all_urls>", "webRequest", "webRequestBlocking" ],
+ "background": { "scripts": [ "background.js" ] },
"applications": {
"gecko": {
"id": "[email protected]"
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.