Skip to content

Commit

Permalink
improve and simplify location detection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Jan 20, 2024
1 parent b6f1c88 commit 9ab7dcc
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/scripts/show_originals.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const hiddenAttribute = 'data-show-originals-hidden';
const lengthenedClass = 'xkit-show-originals-lengthened';
const controlsClass = 'xkit-show-originals-controls';

const blogTimelineRegex = /^\/v2\/blog\/[a-z0-9-]{1,32}\/posts$/;
const channelSelector = `${keyToCss('bar')} ~ *`;

const storageKey = 'show_originals.savedModes';
const includeFiltered = true;

Expand Down Expand Up @@ -63,21 +66,15 @@ const addControls = async (timelineElement, location) => {
const getLocation = timelineElement => {
const { timeline, which } = timelineElement.dataset;

const isInBlogView = timelineElement.matches(blogViewSelector);
const isSinglePostBlogView = timeline.includes('permalink');
const isBlog = blogTimelineRegex.test(timeline) && !timelineElement.matches(channelSelector);

const on = {
dashboard: timeline === '/v2/timeline/dashboard',
peepr: isInBlogView && !isSinglePostBlogView,
disabled: isBlog && disabledBlogs.some(name => timeline === `/v2/blog/${name}/posts`),
peepr: isBlog,
blogSubscriptions: timeline.includes('blog_subscriptions') || which === 'blog_subscriptions'

};
const location = Object.keys(on).find(location => on[location]);
const isDisabledBlog = disabledBlogs.some(name => timeline.startsWith(`/v2/blog/${name}/`));

if (!location || isSinglePostBlogView) return undefined;
if (isDisabledBlog) return 'disabled';
return location;
return Object.keys(on).find(location => on[location]);
};

const processTimelines = async () => {
Expand Down

0 comments on commit 9ab7dcc

Please sign in to comment.