Better Twitter support

Attempt to load image/videos from fxtwitter before loading the full webpage
This commit is contained in:
twilight sparkle 2023-05-13 19:24:04 -07:00 committed by GitHub
parent ffc9b097db
commit 67c0192e87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 4 deletions

View File

@ -33,10 +33,40 @@ export class ImageUrlMutator {
}
protected init(): void {
// this.add(
// /^https?:\/\/.*twitter.com/,
// async(): Promise<string> => 'https://i.imgur.com/ScNLbsp.png'
// );
this.add(
/^https?:\/\/.*twitter.com\/(.*)/,
async(url: string, match: RegExpMatchArray): Promise<string> => {
const path = match[1];
try {
const result = await Axios.get(
`https://api.fxtwitter.com/${path}`
);
const imageUrl = _.get(result, 'data.tweet.media.photos.0.url', null);
if (!imageUrl) {
const videoUrl = _.get(result, 'data.tweet.media.videos.0.url', null);
if (!videoUrl) {
return url;
}
if (this.debug)
console.log('Twitter', url, videoUrl);
return videoUrl;
}
if (this.debug)
console.log('Twitter', url, imageUrl);
return imageUrl;
} catch (err) {
console.error('Twitter Failure', url, err);
return url;
}
}
);
this.add(
/^https?:\/\/rule34video.com\/videos\/([0-9a-zA-Z-_]+)/,