Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add OldTwitter support #239

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
36 changes: 36 additions & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
MakeToast,
RemoveUserBlockHistory,
} from './utilities';
import { ParseTimelineTweet } from './parsers/instructions';

// TODO: tbh this file shouldn't even exist anymore and should be
// split between content/startup.ts and utilities.ts
Expand Down Expand Up @@ -644,3 +645,38 @@ export async function BlockBlueVerified(user: BlueBlockerUser, config: Config) {
}
}
}

// 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);

api.storage.sync
.get(DefaultOptions)
.then((_config) => {
const config = _config as Config;

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,
},
}),
);

ParseTimelineTweet(ev.data, config);
rougetimelord marked this conversation as resolved.
Show resolved Hide resolved
})
.catch((err) => {
console.error(logstr, 'unexpected error occurred while processing OldTwitter request:', err);
MeguminSama marked this conversation as resolved.
Show resolved Hide resolved
});
});