diff --git a/src/scripts/show_originals.js b/src/scripts/show_originals.js index 7fff08cbe..9db17a610 100644 --- a/src/scripts/show_originals.js +++ b/src/scripts/show_originals.js @@ -1,4 +1,4 @@ -import { filterPostElements, blogViewSelector, getTimelineItemWrapper } from '../util/interface.js'; +import { filterPostElements, getTimelineItemWrapper } from '../util/interface.js'; import { isMyPost, timelineObject } from '../util/react_props.js'; import { getPreferences } from '../util/preferences.js'; import { onNewPosts } from '../util/mutations.js'; @@ -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; @@ -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 () => {