From 1222ec4f13a033fb1749b731b9148186999ba91f Mon Sep 17 00:00:00 2001 From: Bauke Date: Wed, 18 Oct 2023 13:44:23 +0200 Subject: [PATCH] Add the Voted On Topic matcher. --- .../content-scripts/features/hide-topics.tsx | 18 ++++++++++++++++++ source/options/components/hide-topics.tsx | 14 +++++++++++++- source/scss/settings/_hide-topics.scss | 4 ++++ source/storage/hide-topics.ts | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/source/content-scripts/features/hide-topics.tsx b/source/content-scripts/features/hide-topics.tsx index 89041a4..1b52880 100644 --- a/source/content-scripts/features/hide-topics.tsx +++ b/source/content-scripts/features/hide-topics.tsx @@ -11,6 +11,7 @@ import { pluralize, querySelector, querySelectorAll, + userIsLoggedIn, } from "../../utilities/exports.js"; /** @@ -58,6 +59,7 @@ function hideTopic(topic: HTMLElement) { export async function runHideTopicsFeature( userLabels: UserLabelsData, ): Promise { + const isLoggedIn = userIsLoggedIn(); const predicates = await fromStorage(Feature.HideTopics); // Select all topics not already handled by TRX. @@ -70,6 +72,7 @@ export async function runHideTopicsFeature( const domainPredicates = []; const titlePredicates = []; const userPredicates = new Set(); + let votedOnTopicEnabled = false; for (const predicate of predicates) { const {matcher, value} = predicate.value; @@ -99,6 +102,11 @@ export async function runHideTopicsFeature( break; } + case Matcher.VotedOnTopic: { + votedOnTopicEnabled = true; + break; + } + default: { console.warn(`Unknown HideTopicMatcher: ${matcher as string}`); } @@ -139,6 +147,16 @@ export async function runHideTopicsFeature( hide(topic); continue; } + + // Fourth check whether the topic has been voted on. + if ( + isLoggedIn && + votedOnTopicEnabled && + topic.querySelector(".btn-used.topic-voting") !== null + ) { + hide(topic); + continue; + } } // Only add the Hide Topics button if any topics have been hidden and if the diff --git a/source/options/components/hide-topics.tsx b/source/options/components/hide-topics.tsx index 76c5667..6c5277b 100644 --- a/source/options/components/hide-topics.tsx +++ b/source/options/components/hide-topics.tsx @@ -144,14 +144,21 @@ export class HideTopicsSetting extends Component { ? "unsaved-changes" : ""; + const disableValueInput = [HideTopicMatcher.VotedOnTopic].includes( + predicate.matcher, + ); + return (
@@ -214,6 +221,11 @@ export class HideTopicsSetting extends Component { Topics" user labels matcher and then add a user label to someone with "Hide Topics" as the text, their topics will be hidden. + +
  • + Voted On Topic will match any topic that you have voted on + and hide it. You do not have to put in a value for this matcher. +
  • diff --git a/source/scss/settings/_hide-topics.scss b/source/scss/settings/_hide-topics.scss index 8781dae..c4723ff 100644 --- a/source/scss/settings/_hide-topics.scss +++ b/source/scss/settings/_hide-topics.scss @@ -54,6 +54,10 @@ border: 1px solid var(--save-status-color); color: var(--foreground); padding: 8px; + + &[disabled] { + filter: grayscale(100%); + } } select { diff --git a/source/storage/hide-topics.ts b/source/storage/hide-topics.ts index 267eb14..2bb93db 100644 --- a/source/storage/hide-topics.ts +++ b/source/storage/hide-topics.ts @@ -10,6 +10,7 @@ export enum HideTopicMatcher { TildesUsernameEquals = "tildes-username-equals", TitleIncludes = "title-includes", UserLabelEquals = "user-label-equals", + VotedOnTopic = "voted-on-topic", } /**