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

Mutual Checker: Following icons in blog cards #992

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
55 changes: 36 additions & 19 deletions src/features/mutual_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const addIcons = function (postElements) {
if (isMutual) {
postElement.classList.add(mutualsClass);
const iconTarget = getPopoverWrapper(postAttribution) ?? postAttribution;
iconTarget?.before(createIcon(blogName));
iconTarget?.before(createMutualIcon(blogName));
} else if (showOnlyMutuals) {
getTimelineItemWrapper(postElement)?.setAttribute(hiddenAttribute, '');
}
Expand All @@ -100,11 +100,15 @@ const addBlogCardIcons = blogCardLinks =>
if (!blogName) return;

const followingBlog = await getIsFollowing(blogName, blogCardLink);
if (!followingBlog) return;

const isMutual = await getIsFollowingYou(blogName);
if (isMutual) {
blogCardLink.before(createIcon(blogName, getComputedStyle(blogCardLink).color));
const isFollowingYou = await getIsFollowingYou(blogName);
const isMutual = followingBlog && isFollowingYou;

if (isFollowingYou) {
blogCardLink.before(
isMutual
? createMutualIcon(blogName, getComputedStyle(blogCardLink).color)
: createFollowingIcon(blogName, getComputedStyle(blogCardLink).color)
);
}
});

Expand Down Expand Up @@ -148,24 +152,37 @@ export const main = async function () {
}
};

const createIcon = (blogName, color = 'rgb(var(--black))') => {
const createIcon = (content, color, tooltip) => dom('svg', {
xmlns: 'http://www.w3.org/2000/svg',
class: mutualIconClass,
viewBox: '0 0 1000 1000',
fill: color
}, null, [
dom('title', { xmlns: 'http://www.w3.org/2000/svg' }, null, [tooltip]),
content
]);

const createMutualIcon = (blogName, color = 'rgb(var(--black))') => {
const today = new Date();
const aprilFools = (today.getMonth() === 3 && today.getDate() === 1);

const icon = dom('svg', {
xmlns: 'http://www.w3.org/2000/svg',
class: mutualIconClass,
viewBox: '0 0 1000 1000',
fill: aprilFools ? '#00b8ff' : color
}, null, [
dom('title', { xmlns: 'http://www.w3.org/2000/svg' }, null, [
translate('{{blogNameLink /}} follows you!').replace('{{blogNameLink /}}', blogName)
]),
dom('path', { xmlns: 'http://www.w3.org/2000/svg', d: aprilFools ? aprilFoolsPath : regularPath })
]);
return icon;
return createIcon(
dom('path', {
xmlns: 'http://www.w3.org/2000/svg',
d: aprilFools ? aprilFoolsPath : regularPath
}),
aprilFools ? '#00b8ff' : color,
translate('Mutuals')
);
};

const createFollowingIcon = (blogName, color = 'rgb(var(--black))') =>
createIcon(
dom('use', { xmlns: 'http://www.w3.org/2000/svg', href: '#ri-user-shared-line' }),
color,
translate('{{blogNameLink /}} follows you!').replace('{{blogNameLink /}}', blogName)
);

export const clean = async function () {
onNewPosts.removeListener(addIcons);
pageModifications.unregister(addBlogCardIcons);
Expand Down