mozilla / contain-facebook

Facebook Container isolates your Facebook activity from the rest of your web activity in order to prevent Facebook from tracking you outside of the Facebook website via third party cookies.
Mozilla Public License 2.0
987 stars 177 forks source link

Add fallback images for Share/Like buttons #277

Open maxxcrawford opened 5 years ago

maxxcrawford commented 5 years ago

Part of previous PR #266:

Notes

Needing to setup similar attribute detection for Like and Share buttons from the FB docs:

Example Screenshots

image

image

maxxcrawford commented 5 years ago

Code cleanup:

function detectFacebookLoginButton () {
  // TODO: Refactor detectFacebookLoginButton to add HTML badge instead of class/psudeo element
  // Test for standard implementation (Example: Facebook Docs)
  const loginButton = document.querySelectorAll(".fb-login-button");
  for (let item of loginButton) {
    const fbcClassResetArr = ["fbc-overlay-small", "fbc-overlay"];
    const replacementClassArr = ["fbc-loginButton"];
    replacementClassArr.push("fbc-size-" + item.getAttribute("data-size"));
    replacementClassArr.push("fbc-button-type-" + item.getAttribute("data-button-type"));
    // Remove previous detection classes
    item.classList.remove(...fbcClassResetArr);
    // Add declared size values
    item.classList.add(...replacementClassArr);
    // Remeasure elements and add correct badge size
    item.classList.add(...itemWidthCheck(item));
  }
}
maxxcrawford commented 4 years ago

Issues for this include: