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

Include basic fix for photos page #25

Open
wants to merge 1 commit into
base: master
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
30 changes: 30 additions & 0 deletions facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const emoji_map = {
const show_facebook_cv_tags = function() {
const TAG_PREFIX = "Image may contain: ";
const images = [...document.getElementsByTagName('img')];
const mediaThumbs = [...document.querySelectorAll('a.uiMediaThumb')];

images.forEach(function(el) {
if (el.hasAttribute("data-prev-alt") && el.getAttribute("data-prev-alt") === el.getAttribute("alt"))
Expand Down Expand Up @@ -107,6 +108,35 @@ const show_facebook_cv_tags = function() {
el.insertAdjacentHTML('afterend', html);
}
});

mediaThumbs.forEach(function(el) {
if (el.hasAttribute("data-prev-aria-label") && el.getAttribute("data-prev-aria-label") === el.getAttribute("alt"))
return;

el.setAttribute("data-prev-aria-label", el.attributes['aria-label'].value);

const ariaLabelText = el.attributes['aria-label'].value;
const isCVTag = ariaLabelText.startsWith(TAG_PREFIX);

if (isCVTag) {
const tags = ariaLabelText.slice(TAG_PREFIX.length).split(/, | and /);
let html = "<ul style='z-index: 2;position:absolute;top:10px;right:10px;padding:5px;font-size:12px;line-height:1.8;background-color:rgba(0,0,0,0.7);color:#fff;border-radius:5px'>";

tags.forEach(function(tag){
let prefix = "∙";

if (tag in emoji_map)
prefix = emoji_map[tag];

html += `<li>${prefix} ${tag}</li>`;
});

html += "</ul>";

el.style.position = 'relative';
el.insertAdjacentHTML('afterend', html);
}
});
};

const observer = new MutationObserver(function(mutations) {
Expand Down