diff --git a/src/features/mutual_checker.js b/src/features/mutual_checker.js index cb6614c62..8c994b084 100644 --- a/src/features/mutual_checker.js +++ b/src/features/mutual_checker.js @@ -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, ''); } @@ -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) + ); } }); @@ -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);