Fix Facebook React snippet selection
This commit is contained in:
parent
b969a9fdb8
commit
3d3ab98c5d
@ -561,10 +561,17 @@ function getMatchingAncestorByCss(node: HTMLElement, cssMatch: string) {
|
|||||||
return getMatchingAncestor(node, x => x.matches(cssMatch));
|
return getMatchingAncestor(node, x => x.matches(cssMatch));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSnippet(node: HTMLElement) {
|
function getSnippet(node: HTMLElement) : HTMLElement {
|
||||||
if (hostname == 'facebook.com') {
|
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 => {
|
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;
|
var dataset = x.dataset;
|
||||||
if (!dataset) return false;
|
if (!dataset) return false;
|
||||||
if (dataset.ftr) return true;
|
if (dataset.ftr) return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user