forked from zusorio/GoodTwitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
35 lines (27 loc) · 967 Bytes
/
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
"use strict";
const targetPage = "https://*.twitter.com/*";
const ua = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) Waterfox/56.2 ";
function rewriteUserAgentHeader(e) {
if (!e.url.startsWith("https://mobile.twitter.com")) {
e.requestHeaders.forEach(function (header) {
if (header.name.toLowerCase() === "user-agent") {
header.value = ua;
}
});
return {requestHeaders: e.requestHeaders};
}
}
function clearCache() {
browser.browsingData.remove({"hostnames": ["twitter.com"]}, {"cache": true});
browser.tabs.query({url: "*://*.twitter.com/*"}, function (result) {
result.forEach(function (tab) {
browser.tabs.reload(tab.id)
})
});
}
browser.webRequest.onBeforeSendHeaders.addListener(
rewriteUserAgentHeader,
{urls: [targetPage]},
["blocking", "requestHeaders"]
);
browser.runtime.onInstalled.addListener(clearCache);