Skip to content

Commit

Permalink
firefox fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Jul 19, 2022
1 parent e7e5747 commit 5e2d583
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
6 changes: 4 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Old Twitter Layout (2022)",
"description": "A new extension that returns old Twitter's look.",
"version": "1.0.4",
"version": "1.0.5",
"manifest_version": 3,
"homepage_url": "https://github.com/dimdenGD/OldTwitter",
"background": {
Expand All @@ -13,7 +13,9 @@
],
"host_permissions": [
"*://*.twitter.com/*",
"*://twitter.com/*"
"*://twitter.com/*",
"*://twimg.com/*",
"*://*.twimg.com/*"
],
"declarative_net_request": {
"rule_resources" : [{
Expand Down
64 changes: 43 additions & 21 deletions pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,54 @@ copyDir('./', '../OldTwitterFirefox').then(async () => {

let content = fs.readFileSync('../OldTwitterFirefox/scripts/content.js', 'utf8');
content = content.replace("document.open();", "");
content = content.replace("document.write(html);", "if(document.body) {document.body.remove()}; document.documentElement.innerHTML = html;");
content = content.replace("document.write(html);", `
if(document.body) {
document.body.remove();
};
setInterval(() => {
let body = document.querySelector('body[style="background-color: #FFFFFF;"]');
if(body) {
body.remove();
};
}, 1000);
document.documentElement.innerHTML = html;`);
content = content.replace("document.close();", "");

let background = fs.readFileSync('../OldTwitterFirefox/scripts/background.js', 'utf8');
background = background.replace(/chrome\.storage\.sync\./, "chrome.storage.local.");
background += `
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {cancel: !details.url.includes("mobile.twitter.com") && (details.url.includes("://twitter.com/manifest.json") || details.url.includes("https://abs.twimg.com/responsive-web/client-web/"))};
},
{urls: ["*://twitter.com/*"]},
["blocking"]
);
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name.toLowerCase() === 'content-security-policy') {
details.requestHeaders.splice(i, 1);
break;
}
}
return {requestHeaders: details.requestHeaders};
},
{urls: ["*://twitter.com/*"]},
["blocking", "requestHeaders"]
);
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {
cancel: !details.url.includes("mobile.twitter.com") && (details.url.includes("://twitter.com/manifest.json") || details.url.includes("https://abs.twimg.com/responsive-web/client-web/"))
};
}, {
urls: ["*://twitter.com/*"]
},
["blocking"]
);
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
if (details.url.includes("twimg.com")) {
if(!details.requestHeaders.find(h => h.name.toLowerCase() === 'origin')) details.requestHeaders.push({
name: "Origin",
value: "https://twitter.com"
});
}
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name.toLowerCase() === 'content-security-policy') {
details.requestHeaders.splice(i, 1);
break;
}
}
return {
requestHeaders: details.requestHeaders
};
}, {
urls: ["*://twitter.com/*", "*://*.twitter.com/*", "*://*.twimg.com/*", "*://twimg.com/*"]
},
["blocking", "requestHeaders"]
);
`;

let headerStyle = fs.readFileSync('../OldTwitterFirefox/layouts/header/style.css', 'utf8');
Expand Down

0 comments on commit 5e2d583

Please sign in to comment.