summaryrefslogtreecommitdiff
path: root/source/features/embed-gist-inline.tsx
diff options
context:
space:
mode:
authorGravatar Federico <me@fregante.com> 2021-06-04 23:39:17 +0700
committerGravatar Federico <me@fregante.com> 2021-06-04 23:39:17 +0700
commit1a9c4f9bc0d4ab4ed871424d1c8e18ba5cbe28da (patch)
tree438d3fe86f9f2f58b3a48df8f5c6995dbb0f4813 /source/features/embed-gist-inline.tsx
parent0af6c3f44b1c4928607aab3f465d76b84e8fe569 (diff)
downloadrefined-github-1a9c4f9bc0d4ab4ed871424d1c8e18ba5cbe28da.tar.gz
refined-github-1a9c4f9bc0d4ab4ed871424d1c8e18ba5cbe28da.tar.zst
refined-github-1a9c4f9bc0d4ab4ed871424d1c8e18ba5cbe28da.zip
`embed-gist-inline` improve gist detection
Diffstat (limited to 'source/features/embed-gist-inline.tsx')
-rw-r--r--source/features/embed-gist-inline.tsx11
1 files changed, 4 insertions, 7 deletions
diff --git a/source/features/embed-gist-inline.tsx b/source/features/embed-gist-inline.tsx
index efb096f5..b7dc4dd5 100644
--- a/source/features/embed-gist-inline.tsx
+++ b/source/features/embed-gist-inline.tsx
@@ -6,7 +6,7 @@ import * as pageDetect from 'github-url-detection';
import features from '.';
import {getCleanPathname} from '../github-helpers';
-function parseGistLink(link: HTMLAnchorElement): string | void {
+function parseGistLink(link: HTMLAnchorElement): string | undefined {
if (link.host === 'gist.github.com') {
return getCleanPathname(link);
}
@@ -14,15 +14,12 @@ function parseGistLink(link: HTMLAnchorElement): string | void {
if (link.host === location.host && link.pathname.startsWith('gist/')) {
return link.pathname.replace('/gist', '').replace(/\/$/, '');
}
+
+ return undefined;
}
function isGist(link: HTMLAnchorElement): boolean {
- const gistUrl = parseGistLink(link);
- return Boolean(
- gistUrl &&
- !gistUrl.includes('.') && // Exclude links to embed files
- gistUrl.includes('/', 1) // Exclude user links
- );
+ return parseGistLink(link)?.replace(/[^/]/g, '').length === 1; // Exclude user links and file links
}
const isOnlyChild = (link: HTMLAnchorElement): boolean => link.textContent!.trim() === link.parentNode!.textContent!.trim();