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

Fix: BlueSky expandos have issues on chromium browsers #5561

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions lib/css/modules/_styleTweaks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ blockquote.twitter-tweet {
}
}

// We need to style bluesky post expandos because they can't take advantage of bsky.app's embeded.js
blockquote.bluesky-embed {
padding: 15px;
border-left: 5px solid #ccc;
font-size: 14px;
line-height: 20px;

p {
margin-bottom: 15px;
}
}

// wow, Reddit only adds a visited style for submission titles!
// let's add visited styles to user-editable content (.md) if the user wants to.
.res-styleTweaks-visitedStyle {
Expand Down
41 changes: 30 additions & 11 deletions lib/modules/hosts/bluesky.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,49 @@

import $ from 'jquery';
import { Host } from '../../core/host';
import { ajax } from '../../environment';
import { ajax, i18n } from '../../environment';

export default new Host('bluesky', {
name: 'bluesky',
logo: 'https://bsky.app/static/favicon.png',
permissions: ['https://embed.bsky.app/oembed'],
domains: ['bsky.app'],
detect: ({ href }) => (/^^https?:\/\/(bsky)\.app\/profile\/[\w.-]+\/post+/i).exec(href),
detect: ({ href }) => (/^^https?:\/\/(bsky)\.app\/profile\/[^\\]+\/post+/i).exec(href),
options:{
forceReplaceNativeExpando: {
title: 'showImagesForceReplaceNativeExpandoTitle',
description: 'showImagesForceReplaceNativeExpandoDesc',
value: true,
type: 'boolean',
noconfig: true,
},
},
async handleLink(href) {
const post = await ajax({
url: 'https://embed.bsky.app/oembed',
query: { url: href },
type:'json',
});

let posthtml;
try {
const post = await ajax({
url: 'https://embed.bsky.app/oembed',
query: { url: href.replace(/\/+$/, '') }, // Remove trailing slashes, as the bluesky embed app does accept it.
type:'json',
});
// This removes the embedded script that we cannot use for security reasons.
posthtml = $.parseHTML(post.html)[0]
} catch (error) {
// If we get here, the embed API likely threw a 403, which happens when a user requests that the post is only viewed
// by logged in users on bsky.app. There is no way to embed this post.
posthtml = `<blockquote class="bluesky-embed">${ i18n('blueskyExpandoUserRequestedLoginToView') }</blockquote>`
}
// Script requires element to be attached to document when starting
const $dummy = $('<div>');

return {
type: 'GENERIC_EXPANDO',
muted: true,
expandoClass: 'selftext',
generate: () => $dummy[0],
onAttach: () => { $dummy.html(post.html); },
onAttach: () => {
$dummy.html(posthtml);
},
};
},
});
},
);
5 changes: 4 additions & 1 deletion locales/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4461,5 +4461,8 @@
},
"quarantineHideInSubDesc": {
"message": "Hide all warnings of quarantine while viewing a quarantined subreddit"
}
},
"blueskyExpandoUserRequestedLoginToView": {
"message": "Unable to render Bluesky Expando. User requested only logged in users to view content."
}
}