Add the Voted On Topic matcher.
This commit is contained in:
parent
3008bdc9ab
commit
1222ec4f13
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -54,6 +54,10 @@
|
|||
border: 1px solid var(--save-status-color);
|
||||
color: var(--foreground);
|
||||
padding: 8px;
|
||||
|
||||
&[disabled] {
|
||||
filter: grayscale(100%);
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
|
|
|
@ -10,6 +10,7 @@ export enum HideTopicMatcher {
|
|||
TildesUsernameEquals = "tildes-username-equals",
|
||||
TitleIncludes = "title-includes",
|
||||
UserLabelEquals = "user-label-equals",
|
||||
VotedOnTopic = "voted-on-topic",
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue