From 3d3ab98c5d55e897b5360515fb997c41e5dec116 Mon Sep 17 00:00:00 2001 From: shinigami-eyes <43276258+shinigami-eyes@users.noreply.github.com> Date: Sat, 26 Dec 2020 06:54:24 +0000 Subject: [PATCH] Fix Facebook React snippet selection --- extension/content.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/extension/content.ts b/extension/content.ts index 4ad8ed4..ba72e6a 100644 --- a/extension/content.ts +++ b/extension/content.ts @@ -561,10 +561,17 @@ function getMatchingAncestorByCss(node: HTMLElement, cssMatch: string) { return getMatchingAncestor(node, x => x.matches(cssMatch)); } -function getSnippet(node: HTMLElement) { +function getSnippet(node: HTMLElement) : HTMLElement { if (hostname == 'facebook.com') { + const pathname = window.location.pathname; + const isPhotoPage = pathname.startsWith('/photo') || pathname.includes('/photos/') || pathname.startsWith('/video') || pathname.includes('/videos/'); + if (isPhotoPage) { + const sidebar = document.querySelector('[role=complementary]'); + if (sidebar) return sidebar.parentElement; + } + const isSearchPage = pathname.startsWith('/search/'); return getMatchingAncestor(node, x => { - if (x.getAttribute('role') == 'article' && x.getAttribute('aria-labelledby')) return true; + if (x.getAttribute('role') == 'article' && (isSearchPage || x.getAttribute('aria-labelledby'))) return true; var dataset = x.dataset; if (!dataset) return false; if (dataset.ftr) return true;