Skip to content

Commit

Permalink
better injection
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Aug 13, 2024
1 parent 3fd454b commit fee70f5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
{
"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/destroyer.js", "src/notifications.js", "src/injection.js"],
"all_frames": true,
"run_at": "document_start",
"world": "MAIN"
Expand Down
7 changes: 6 additions & 1 deletion pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ copyDir('./', '../OldTweetDeckFirefox').then(async () => {
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;
for(let content_script of manifest.content_scripts) {
if(content_script.world === "MAIN") {
delete content_script.world;
}
content_script.js = content_script.js.filter(js => js !== "src/destroyer.js");
}
manifest.background = {
scripts: ["src/background.js"],
}
Expand Down
56 changes: 56 additions & 0 deletions src/destroyer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Step 1: fool twitter into thinking scripts loaded
window.__SCRIPTS_LOADED__ = Object.freeze({
main: true,
vendor: true,
runtime: false
});

// Step 2: continously wreck havoc
let _destroyerInt = setInterval(() => {
delete window.webpackChunk_twitter_responsive_web;
window.__SCRIPTS_LOADED__ = Object.freeze({
main: true,
vendor: true,
runtime: false
});
if(document.getElementById('ScriptLoadFailure')) {
document.getElementById('ScriptLoadFailure').remove();
}
});

// Step 3: destroy twitter critical modules
let _originalPush = Array.prototype.push;
Array.prototype.push = function() {
try {
if(arguments[0]?.[0]?.[0] === "vendor" || arguments[0]?.[0]?.[0] === "main") {
throw "Twitter killing magic killed Twitter https://lune.dimden.dev/f016efffcd3d.png (thats fine)";
}
} catch(e) {
Array.prototype.push = _originalPush;
} finally {
return _originalPush.apply(this, arguments);
}
}

// Step 4: prevent twitter from reporting it
let _originalTest = RegExp.prototype.test;
RegExp.prototype.test = function() {
try {
if(this.toString() === '/[?&]failedScript=/') {
RegExp.prototype.test = _originalTest;
throw "hehe";
};
} catch(e) {
RegExp.prototype.test = _originalTest;
} finally {
return _originalTest.apply(this, arguments);
}
}

// Step 5: self destruct
setTimeout(() => {
clearInterval(_destroyerInt);
Array.prototype.push = _originalPush;
}, 5000);

// Step 6: Live OTD reaction: https://lune.dimden.dev/6743b45eb1de.png
20 changes: 0 additions & 20 deletions src/injection.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
let script = document.createElement('script');
script.innerHTML = `
Object.defineProperty(window, '__SCRIPTS_LOADED__', {
value: { main: true, vendor: true },
writable: false,
configurable: false
});
`;
if(document.head) {
document.head.appendChild(script);
} else {
let observer = new MutationObserver(() => {
if(document.head) {
document.head.appendChild(script);
observer.disconnect();
}
});
observer.observe(document.documentElement, { childList: true, subtree: true });
}

let extId;
let isFirefox = navigator.userAgent.indexOf('Firefox') > -1;
if(!window.chrome) window.chrome = {};
Expand Down

0 comments on commit fee70f5

Please sign in to comment.