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
Changes from 1 commit
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
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
});
});