Skip to content

Commit

Permalink
Merge pull request #59 from wseagar/fix/multiple_text_node_siblings
Browse files Browse the repository at this point in the history
Fix/multiple text node siblings
  • Loading branch information
wseagar authored Nov 21, 2022
2 parents de40a0e + 94f3f37 commit 407dc58
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function changeVerified(prependHTML, elm, isSmall, isIndeterminate) {
// Ideally, we wouldn't mutate the parent element, because those 2 styles won't be managed by us further on.
// That is, if the `aria-label`-selected element changes, the parent styles won't be properly updated.
// This approach is tolerable, because it's unlikely that a `aria-label`-selected element changes from a
// "React text node + React element node" sibling configuration to a "single React element node" sibling configuration.
// "React text node(s) + React element node" sibling configuration to a "single React element node" sibling configuration.
elm.parentElement.style.display = "inline-flex";
elm.parentElement.style.alignItems = "center";
}
Expand Down Expand Up @@ -196,7 +196,7 @@ function changeBlueVerified(prependHTML, elm, isSmall) {
// Ideally, we wouldn't mutate the parent element, because those 2 styles won't be managed by us further on.
// That is, if the `aria-label`-selected element changes, the parent styles won't be properly updated.
// This approach is tolerable, because it's unlikely that a `aria-label`-selected element changes from a
// "React text node + React element node" sibling configuration to a "single React element node" sibling configuration.
// "React text node(s) + React element node" sibling configuration to a "single React element node" sibling configuration.
elm.parentElement.style.display = "inline-flex";
elm.parentElement.style.alignItems = "center";
}
Expand All @@ -220,6 +220,16 @@ function querySelectorAllIncludingMe(node, selector) {
return [...node.querySelectorAll(selector)]
}

function getPreviusSiblingsOuterHTML(node) {
let prev = node.previousElementSibling;
let html = [];
while (prev) {
html.push(prev.outerHTML);
prev = prev.previousElementSibling;
}
return html.reverse().join('');
}

// From https://stackoverflow.com/a/74240138/2230249
function getReactProps(parent, target) {
const keyof_ReactProps = Object.keys(parent).find(k => k.startsWith("__reactProps$"));
Expand Down Expand Up @@ -314,7 +324,7 @@ function evaluateBlueCheck() {

const isSmall = checkIfSmall(blueCheckComponent)
const isKnownBadData = checkIfKnownBadData(blueCheckComponent)
const prependHTML = blueCheckComponent.previousElementSibling?.outerHTML
const prependHTML = getPreviusSiblingsOuterHTML(blueCheckComponent)

if (isKnownBadData && nestedProps.isVerified && nestedProps.isBlueVerified) {
changeVerified(prependHTML, blueCheckComponent, isSmall, true);
Expand Down

0 comments on commit 407dc58

Please sign in to comment.