diff options
author | 2019-04-17 08:42:27 -0400 | |
---|---|---|
committer | 2019-04-17 20:42:27 +0800 | |
commit | 7b3b275ad9a1b1409c56310c0b8ab286bef1f75f (patch) | |
tree | 90de3c1682fbad57234cffa2e71f51baab7680c4 /source/features/embed-gist-inline.tsx | |
parent | 438f98c7d7760b5e24ebf0bd9634d0c447226196 (diff) | |
download | refined-github-7b3b275ad9a1b1409c56310c0b8ab286bef1f75f.tar.gz refined-github-7b3b275ad9a1b1409c56310c0b8ab286bef1f75f.tar.zst refined-github-7b3b275ad9a1b1409c56310c0b8ab286bef1f75f.zip |
Enable strict-mode for TypeScript (#1783)
Co-authored-by: Federico Brigante <github@bfred.it>
Diffstat (limited to 'source/features/embed-gist-inline.tsx')
-rw-r--r-- | source/features/embed-gist-inline.tsx | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/source/features/embed-gist-inline.tsx b/source/features/embed-gist-inline.tsx index 4fd76cd8..8e5ea3ad 100644 --- a/source/features/embed-gist-inline.tsx +++ b/source/features/embed-gist-inline.tsx @@ -3,16 +3,16 @@ import domify from 'doma'; import select from 'select-dom'; import features from '../libs/features'; -const isGist = link => +const isGist = (link: HTMLAnchorElement) => !link.pathname.includes('.') && // Exclude links to embed files ( link.hostname.startsWith('gist.') || link.pathname.startsWith('gist/') ); -const isOnlyChild = link => link.textContent.trim() === link.parentNode.textContent.trim(); +const isOnlyChild = (link: HTMLAnchorElement) => link.textContent!.trim() === link.parentNode!.textContent!.trim(); -async function embedGist(link) { +async function embedGist(link: HTMLAnchorElement) { const info = <em> (loading)</em>; link.after(info); @@ -20,13 +20,13 @@ async function embedGist(link) { const response = await fetch(`${link.href}.json`); const gistData = await response.json(); - const files = domify.one(gistData.div); + const files = domify.one(gistData.div)!; const fileCount = files.children.length; if (fileCount > 1) { info.textContent = ` (${fileCount} files)`; } else { - link.parentNode.attachShadow({mode: 'open'}).append( + link.parentElement!.attachShadow({mode: 'open'}).append( <style>{` .gist .gist-data { max-height: 16em; @@ -38,12 +38,12 @@ async function embedGist(link) { ); } } catch { - info.remove(' (embed failed)'); + info.replaceWith(' (embed failed)'); } } function init() { - select.all('.js-comment-body p a:only-child') + select.all<HTMLAnchorElement>('.js-comment-body p a:only-child') .filter(item => isGist(item) && isOnlyChild(item)) .forEach(embedGist); } |