Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #669 – Check target opacity for visibility #688

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ function shouldBadgeBeSmall(ratioCheck, itemHeight) {
}

function addFacebookBadge (target, badgeClassUId, socialAction) {
// Detect if target is visible

const htmlBadgeDiv = createBadgeFragment(socialAction);

const htmlBadgeFragmentPromptButtonCancel = htmlBadgeDiv.querySelector(".fbc-badge-prompt-btn-cancel");
Expand Down Expand Up @@ -318,12 +316,23 @@ function getOffsetsAndApplyClass(elemRect, bodyRect, target, htmlBadgeDiv) {
}
}

function isOpaque(target){
// Check if any parents have 0 opacity
let current = target;
while(current != null){
if( window.getComputedStyle(current, false).getPropertyValue("opacity") === "0" ) return false;
current = current.parentElement;
}
return true;
}

function isVisible(target) {
const currentComputedStyle = window.getComputedStyle(target, false);
const styleTransform = ( currentComputedStyle.getPropertyValue("transform") === "matrix(1, 0, 0, 0, 0, 0)" );
const styleHidden = ( currentComputedStyle.getPropertyValue("visibility") === "hidden" );
const styleDisplayNone = ( currentComputedStyle.getPropertyValue("display") === "none" );
if (styleTransform || styleHidden || styleDisplayNone) return false;
const styleOpacityNone = !isOpaque(target);
if (styleTransform || styleHidden || styleDisplayNone || styleOpacityNone ) return false;
return true;
}

Expand Down Expand Up @@ -420,6 +429,7 @@ function positionFacebookBadge (target, badgeClassUId, targetWidth, smallSwitch)
target = document.querySelector("." + target);
}

// Detect if target is visible
if (!checkVisibilityAndApplyClass(target, htmlBadgeDiv)) {
return;
}
Expand Down