Skip to content

Commit 679396a

Browse files
authored
Fix: BlueSky expandos have issues on chromium browsers (#5561)
* Added support for bluesky expandos * Fixed several bluesky expando issues. * fixed yarn errors
1 parent dac2846 commit 679396a

3 files changed

Lines changed: 46 additions & 12 deletions

File tree

lib/css/modules/_styleTweaks.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ blockquote.twitter-tweet {
1111
}
1212
}
1313

14+
// We need to style bluesky post expandos because they can't take advantage of bsky.app's embeded.js
15+
blockquote.bluesky-embed {
16+
padding: 15px;
17+
border-left: 5px solid #ccc;
18+
font-size: 14px;
19+
line-height: 20px;
20+
21+
p {
22+
margin-bottom: 15px;
23+
}
24+
}
25+
1426
// wow, Reddit only adds a visited style for submission titles!
1527
// let's add visited styles to user-editable content (.md) if the user wants to.
1628
.res-styleTweaks-visitedStyle {

lib/modules/hosts/bluesky.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,49 @@
22

33
import $ from 'jquery';
44
import { Host } from '../../core/host';
5-
import { ajax } from '../../environment';
5+
import { ajax, i18n } from '../../environment';
66

77
export default new Host('bluesky', {
88
name: 'bluesky',
99
logo: 'https://bsky.app/static/favicon.png',
1010
permissions: ['https://embed.bsky.app/oembed'],
1111
domains: ['bsky.app'],
12-
detect: ({ href }) => (/^^https?:\/\/(bsky)\.app\/profile\/[\w.-]+\/post+/i).exec(href),
12+
detect: ({ href }) => (/^^https?:\/\/(bsky)\.app\/profile\/[^\\]+\/post+/i).exec(href),
13+
options:{
14+
forceReplaceNativeExpando: {
15+
title: 'showImagesForceReplaceNativeExpandoTitle',
16+
description: 'showImagesForceReplaceNativeExpandoDesc',
17+
value: true,
18+
type: 'boolean',
19+
noconfig: true,
20+
},
21+
},
1322
async handleLink(href) {
14-
const post = await ajax({
15-
url: 'https://embed.bsky.app/oembed',
16-
query: { url: href },
17-
type:'json',
18-
});
19-
23+
let posthtml;
24+
try {
25+
const post = await ajax({
26+
url: 'https://embed.bsky.app/oembed',
27+
query: { url: href.replace(/\/+$/, '') }, // Remove trailing slashes, as the bluesky embed app does accept it.
28+
type:'json',
29+
});
30+
// This removes the embedded script that we cannot use for security reasons.
31+
posthtml = $.parseHTML(post.html)[0]
32+
} catch (error) {
33+
// If we get here, the embed API likely threw a 403, which happens when a user requests that the post is only viewed
34+
// by logged in users on bsky.app. There is no way to embed this post.
35+
posthtml = `<blockquote class="bluesky-embed">${ i18n('blueskyExpandoUserRequestedLoginToView') }</blockquote>`
36+
}
2037
// Script requires element to be attached to document when starting
2138
const $dummy = $('<div>');
22-
2339
return {
2440
type: 'GENERIC_EXPANDO',
2541
muted: true,
2642
expandoClass: 'selftext',
2743
generate: () => $dummy[0],
28-
onAttach: () => { $dummy.html(post.html); },
44+
onAttach: () => {
45+
$dummy.html(posthtml);
46+
},
2947
};
3048
},
31-
});
49+
},
50+
);

locales/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4461,5 +4461,8 @@
44614461
},
44624462
"quarantineHideInSubDesc": {
44634463
"message": "Hide all warnings of quarantine while viewing a quarantined subreddit"
4464-
}
4464+
},
4465+
"blueskyExpandoUserRequestedLoginToView": {
4466+
"message": "Unable to render Bluesky Expando. User requested only logged in users to view content."
4467+
}
44654468
}

0 commit comments

Comments
 (0)