Skip to content

Commit

Permalink
feat: add OldTwitter support (#239)
Browse files Browse the repository at this point in the history
* feat: add OldTwitter support
* Update version string
* fix: remove unnecessary code
* chore: move code into content/index.ts
* chore: remove dangling import

---------

Co-authored-by: Rouge <14047458+rougetimelord@users.noreply.github.com>
  • Loading branch information
MeguminSama and rougetimelord authored Mar 13, 2024
1 parent 2aa7752 commit 7d74ea4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blue-blocker",
"version": "0.3.7",
"version": "0.3.8",
"author": "DanielleMiu",
"description": "Blocks all Twitter Blue verified users on twitter.com",
"type": "module",
Expand Down
24 changes: 24 additions & 0 deletions src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,27 @@ document.addEventListener("blue-blocker-event", function (e: CustomEvent<BlueBlo
}
});
});

// Add support for OldTwitter requests.
window.addEventListener('message', function (ev) {
if (ev.data.type !== 'OLDTWITTER_REQUEST_LOAD') return;
if (!ev.data.url || !ev.data.body || !ev.data.headers)
return console.error(logstr, 'OldTwitter sent an invalid payload.', ev.data);

const body_str = JSON.stringify(ev.data.body);

document.dispatchEvent(
new CustomEvent('blue-blocker-event', {
detail: {
parsedUrl: /(.+)/.exec(ev.data.url)!, // Have to turn the endpoint string into a regex result...
url: ev.data.url,
body: body_str as XMLHttpRequest['response'],
request: {
headers: ev.data.headers,
},
// OldTwitter only emits messages on success.
status: 200,
},
}),
);
});
2 changes: 1 addition & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineManifest } from "@crxjs/vite-plugin";
export default defineManifest({
name: "Blue Blocker",
description: "Blocks all Twitter Blue verified users on twitter.com",
version: "0.3.7",
version: "0.3.8",
manifest_version: 3,
icons: {
"128": "icon/icon-128.png",
Expand Down

0 comments on commit 7d74ea4

Please sign in to comment.