1
Fork 0

Add the Voted On Topic matcher.

This commit is contained in:
Bauke 2023-10-18 13:44:23 +02:00
parent 3008bdc9ab
commit 1222ec4f13
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
4 changed files with 36 additions and 1 deletions

View File

@ -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<void> {
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

View File

@ -144,14 +144,21 @@ export class HideTopicsSetting extends Component<SettingProps, State> {
? "unsaved-changes"
: "";
const disableValueInput = [HideTopicMatcher.VotedOnTopic].includes(
predicate.matcher,
);
return (
<div class={`has-save-status hide-topics-editor ${hasUnsavedChanges}`}>
<select class="styled-select" onChange={matcherHandler}>
{matcherOptions}
</select>
<input
disabled={disableValueInput}
type="text"
placeholder="Value to match"
placeholder={
disableValueInput ? "No value needed" : "Value to match"
}
value={predicate.value}
onInput={valueHandler}
/>
@ -214,6 +221,11 @@ export class HideTopicsSetting extends Component<SettingProps, State> {
Topics" user labels matcher and then add a user label to someone
with "Hide Topics" as the text, their topics will be hidden.
</li>
<li>
<b>Voted On Topic</b> will match any topic that you have voted on
and hide it. You do not have to put in a value for this matcher.
</li>
</ul>
</details>

View File

@ -54,6 +54,10 @@
border: 1px solid var(--save-status-color);
color: var(--foreground);
padding: 8px;
&[disabled] {
filter: grayscale(100%);
}
}
select {

View File

@ -10,6 +10,7 @@ export enum HideTopicMatcher {
TildesUsernameEquals = "tildes-username-equals",
TitleIncludes = "title-includes",
UserLabelEquals = "user-label-equals",
VotedOnTopic = "voted-on-topic",
}
/**