summaryrefslogtreecommitdiff
path: root/source/features/embed-gist-inline.tsx
diff options
context:
space:
mode:
authorGravatar Federico <me@fregante.com> 2021-01-06 15:19:41 -0600
committerGravatar GitHub <noreply@github.com> 2021-01-06 15:19:41 -0600
commite5a7fa02be0f56f034ffaf3bca7fdb523d3ef90f (patch)
tree86aec7be8425b6dfe6136b2ee5b03afa56e09ded /source/features/embed-gist-inline.tsx
parent62809a1ba44c1fb1eb451ba97427bef822cbc00c (diff)
downloadrefined-github-e5a7fa02be0f56f034ffaf3bca7fdb523d3ef90f.tar.gz
refined-github-e5a7fa02be0f56f034ffaf3bca7fdb523d3ef90f.tar.zst
refined-github-e5a7fa02be0f56f034ffaf3bca7fdb523d3ef90f.zip
Fix `embed-gist-inline` style and preserve the original link (#3866)
Diffstat (limited to 'source/features/embed-gist-inline.tsx')
-rw-r--r--source/features/embed-gist-inline.tsx15
1 files changed, 8 insertions, 7 deletions
diff --git a/source/features/embed-gist-inline.tsx b/source/features/embed-gist-inline.tsx
index 10b9c203..13fc2022 100644
--- a/source/features/embed-gist-inline.tsx
+++ b/source/features/embed-gist-inline.tsx
@@ -19,16 +19,15 @@ async function embedGist(link: HTMLAnchorElement): Promise<void> {
link.after(info);
try {
- // Get the gist via background.js due to CORB policies introduced in Chrome 73
- const gistData = await browser.runtime.sendMessage({request: `${link.href}.json`});
-
- const files = domify.one(JSON.parse(gistData).div)!;
- const fileCount = files.children.length;
+ // Fetch via background.js due to CORB policies
+ const gistData = await browser.runtime.sendMessage({fetchJSON: `${link.href}.json`});
+ const fileCount: number = gistData.files.length;
if (fileCount > 1) {
info.textContent = ` (${fileCount} files)`;
} else {
- link.parentElement!.attachShadow({mode: 'open'}).append(
+ const container = <div/>;
+ container.attachShadow({mode: 'open'}).append(
<style>{`
.gist .gist-data {
max-height: 16em;
@@ -37,8 +36,10 @@ async function embedGist(link: HTMLAnchorElement): Promise<void> {
`}
</style>,
<link rel="stylesheet" href={gistData.stylesheet}/>,
- files
+ domify.one(gistData.div)!
);
+ link.parentElement!.after(container);
+ info.remove();
}
} catch {
info.remove();