Skip to content

Commit

Permalink
add support for MV3
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Aug 9, 2024
1 parent cf71df2 commit d4033bc
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 15 deletions.
9 changes: 7 additions & 2 deletions files/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32725,7 +32725,12 @@ document.body.addEventListener("click", function (e) {
var h = {},
m = null;
(h.getDecider = function (e) {
var t = "https://tweetdeck.twitter.com/decider?identifier=" + e;
var t;
if(window.chrome && window.chrome.runtime) {
t = `${chrome.runtime.getURL('/files/decider.json')}?identifier=` + e;
} else {
t = "https://tweetdeck.twitter.com/decider?identifier=" + e;
}
return h.drequest(
t,
{
Expand Down Expand Up @@ -32779,7 +32784,7 @@ document.body.addEventListener("click", function (e) {
(null === l || (0, c.default)(l)) && (l = h.getReq()),
i.request(g, n, l),
"/" == n.charAt(0) && (n = TD.config.api_root + n),
!(0, a.default)(n, "http://") && !(0, a.default)(n, "https://"))
!(0, a.default)(n, "http://") && !(0, a.default)(n, "https://") && !(0, a.default)(n, "moz-extension://") && !(0, a.default)(n, "chrome-extension://"))
)
return t.fail(new Error("Malformed url"));
l.headers = (0, r.default)(l.headers || {}, {
Expand Down
35 changes: 26 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "OldTweetDeck",
"description": "Returns old TweetDeck, for free!",
"version": "3.6.8",
"manifest_version": 2,
"version": "4.0.0",
"manifest_version": 3,
"homepage_url": "https://github.com/dimdenGD/OldTweetDeck",
"permissions": [
"webRequest",
"webRequestBlocking",
"webNavigation",
"cookies",
"declarativeNetRequest"
],
"host_permissions": [
"https://twitter.com/*",
"https://*.twitter.com/*",
"https://x.com/*",
Expand All @@ -17,10 +18,19 @@
"https://api.twitter.com/*",
"https://tweetdeck.com/"
],
"background": {
"scripts": ["src/background.js"]
},
"web_accessible_resources": ["images/*", "files/*", "src/*", "solver.html"],
"web_accessible_resources": [
{
"resources": ["images/*", "files/*", "src/*", "solver.html", "manifest.json"],
"matches": ["<all_urls>"]
}
],
"declarative_net_request": {
"rule_resources" : [{
"id": "ruleset",
"enabled": true,
"path": "ruleset.json"
}]
},
"icons": {
"16": "/images/logo16.png",
"32": "/images/logo32.png",
Expand All @@ -30,9 +40,16 @@
"content_scripts": [
{
"matches": ["https://twitter.com/i/tweetdeck", "https://x.com/i/tweetdeck", "https://x.com/i/tweetdeck?*"],
"js": ["src/notifications.js", "src/injection.js"],
"js": ["src/content.js"],
"all_frames": true,
"run_at": "document_start"
},
{
"matches": ["https://twitter.com/i/tweetdeck", "https://x.com/i/tweetdeck", "https://x.com/i/tweetdeck?*"],
"js": ["src/notifications.js", "src/injection.js"],
"all_frames": true,
"run_at": "document_start",
"world": "MAIN"
}
]
}
11 changes: 10 additions & 1 deletion pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ copyDir('./', '../OldTweetDeckFirefox').then(async () => {
strict_min_version: "90.0"
}
};
manifest.permissions.push("https://tweetdeck.dimden.dev/*", "https://raw.githubusercontent.com/*");
manifest.manifest_version = 2;
manifest.host_permissions.push("https://tweetdeck.dimden.dev/*", "https://raw.githubusercontent.com/*");
delete manifest.declarative_net_request;
manifest.permissions.push("webRequest", "webRequestBlocking", ...manifest.host_permissions);
delete manifest.host_permissions;
delete manifest.content_scripts.find(c => c.world === "MAIN").world;
manifest.background = {
scripts: ["src/background.js"],
}
manifest.web_accessible_resources = manifest.web_accessible_resources[0].resources;

fs.unlinkSync('../OldTweetDeckFirefox/pack.js');
fs.unlinkSync('../OldTweetDeckTempChrome/pack.js');
Expand Down
80 changes: 80 additions & 0 deletions ruleset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[
{
"id": 1,
"priority": 1,
"action": {
"type": "modifyHeaders",
"responseHeaders": [
{
"header": "content-security-policy",
"operation": "remove"
},
{
"header": "x-frame-options",
"operation": "remove"
}
]
},
"condition": {
"urlFilter": "https://twitter.com/i/tweetdeck",
"resourceTypes": ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "xmlhttprequest", "other"]
}
},
{
"id": 2,
"priority": 1,
"action": {
"type": "modifyHeaders",
"responseHeaders": [
{
"header": "content-security-policy",
"operation": "remove"
},
{
"header": "x-frame-options",
"operation": "remove"
}
]
},
"condition": {
"urlFilter": "https://x.com/i/tweetdeck",
"resourceTypes": ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "xmlhttprequest", "other"]
}
},
{
"id": 3,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://x.com/i/tweetdeck" }
},
"condition": {
"urlFilter": "*://tweetdeck.com/*",
"resourceTypes": ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "xmlhttprequest", "other"]
}
},
{
"id": 4,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://x.com/i/tweetdeck" }
},
"condition": {
"urlFilter": "*://tweetdeck.x.com/*",
"resourceTypes": ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "xmlhttprequest", "other"]
}
},
{
"id": 5,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://x.com/i/tweetdeck" }
},
"condition": {
"urlFilter": "*://tweetdeck.twitter.com/*",
"resourceTypes": ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "xmlhttprequest", "other"]
}
}
]
6 changes: 6 additions & 0 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
window.addEventListener('message', e => {
if(e.data === 'extensionId') {
let extId = chrome.runtime.getURL('/injection.js').split("/")[2];
window.postMessage({ extensionId: extId }, '*');
}
});
21 changes: 19 additions & 2 deletions src/injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@ if(document.head) {
observer.observe(document.documentElement, { childList: true, subtree: true });
}

(async () => {
let extId;
let isFirefox = navigator.userAgent.indexOf('Firefox') > -1;
if(!window.chrome) window.chrome = {};
if(!window.chrome.runtime) window.chrome.runtime = {};
window.chrome.runtime.getURL = url => {
if(!url.startsWith('/')) url = `/${url}`;
return `${isFirefox ? 'moz-extension://' : 'chrome-extension://'}${extId}${url}`;
}
window.addEventListener('message', e => {
if(e.data.extensionId) {
console.log("got extensionId", e.data.extensionId);
extId = e.data.extensionId;
main();
}
});
window.postMessage('extensionId', '*');

async function main() {
let html = await fetch(chrome.runtime.getURL('/files/index.html')).then(r => r.text());
document.documentElement.innerHTML = html;

Expand Down Expand Up @@ -177,4 +194,4 @@ if(document.head) {
});
}
setInterval(injectAccount, 1000);
})();
};
3 changes: 2 additions & 1 deletion src/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function minVersionCheck(ver, minVer) {
async function showNotifications() {
let notifsToDisplay = await getNotifications();
if(notifsToDisplay.length === 0) return;
let currentVersion = chrome.runtime.getManifest().version;
let manifest = await fetch(chrome.runtime.getURL('/manifest.json')).then(r => r.json());
let currentVersion = manifest.version;

for(let notif of notifsToDisplay) {
if(!localStorage.OTDnotifsReadOnce && notif.ignoreOnInstall) {
Expand Down

0 comments on commit d4033bc

Please sign in to comment.