1
Fork 0

Add the Topic Info Ignore miscellaneous feature.

This commit is contained in:
Bauke 2023-07-13 16:16:37 +02:00
parent b8ff891c31
commit 73f3977b62
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
7 changed files with 78 additions and 6 deletions

View File

@ -2,10 +2,11 @@ export * from "./anonymize-usernames.js";
export * from "./autocomplete.js";
export * from "./back-to-top.js";
export * from "./comment-anchor-fix.js";
export * from "./hide-topics.js";
export * from "./hide-votes.js";
export * from "./jump-to-new-comment.js";
export * from "./markdown-toolbar.js";
export * from "./themed-logo.js";
export * from "./topic-info-ignore.js";
export * from "./user-labels.js";
export * from "./username-colors.js";
export * from "./hide-topics.js";

View File

@ -0,0 +1,35 @@
import {log, pluralize, querySelectorAll} from "../../utilities/exports.js";
export function runTopicInfoIgnore(): void {
const count = moveIgnoreButtons();
if (count > 0) {
const pluralized = `${count} ${pluralize(count, "ignore button")}`;
log(`Moved ${pluralized}`);
}
}
function moveIgnoreButtons(): number {
let count = 0;
for (const topic of querySelectorAll(
"article.topic:not(.trx-topic-info-ignore)",
)) {
const topicInfo = topic.querySelector(".topic-info") ?? undefined;
if (topicInfo === undefined) {
continue;
}
const button =
topic.querySelector<HTMLButtonElement>('[name="topic-actions-ignore"]') ??
undefined;
if (button === undefined) {
continue;
}
topic.classList.add("trx-topic-info-ignore");
topicInfo.append(button);
count++;
}
return count;
}

View File

@ -17,6 +17,7 @@ import {
runHideVotesFeature,
runMarkdownToolbarFeature,
runThemedLogoFeature,
runTopicInfoIgnore,
runUsernameColorsFeature,
} from "./features/exports.js";
@ -112,11 +113,6 @@ async function initialize() {
});
}
const miscEnabled = await fromStorage(Data.MiscellaneousEnabledFeatures);
if (miscEnabled.value.has(MiscellaneousFeature.CommentAnchorFix)) {
runCommentAnchorFixFeature();
}
// Initialize all the observer-dependent features first.
await Promise.all(observerFeatures.map(async (feature) => feature()));
@ -150,6 +146,15 @@ async function initialize() {
);
}
const miscEnabled = await fromStorage(Data.MiscellaneousEnabledFeatures);
if (miscEnabled.value.has(MiscellaneousFeature.CommentAnchorFix)) {
runCommentAnchorFixFeature();
}
if (miscEnabled.value.has(MiscellaneousFeature.TopicInfoIgnore)) {
runTopicInfoIgnore();
}
// Insert a placeholder at the end of the body first, then render the rest
// and use that as the replacement element. Otherwise render() would put it
// at the beginning of the body which causes a bunch of different issues.

View File

@ -25,6 +25,15 @@ function FeatureDescription({
);
}
if (feature === MiscellaneousFeature.TopicInfoIgnore) {
return (
<p class="description">
Moves the topic ignore button to be in the info section next to the
posted date.
</p>
);
}
return <></>;
}

View File

@ -4,6 +4,7 @@
@import "scripts/hide-topics";
@import "scripts/jump-to-new-comment";
@import "scripts/markdown-toolbar";
@import "scripts/topic-info-ignore";
@import "scripts/user-labels";
@import "scripts/username-colors";

View File

@ -0,0 +1,20 @@
.trx-topic-info-ignore {
.topic-info {
// The first three values are copied from Tildes, the last one we set to add
// the Ignore button into.
grid-template-columns: 1fr 1.5fr 0.7fr 1fr;
// Override some of the styles of the button so it doesn't look out of
// place as much.
.btn-post-action {
align-self: center;
color: var(--link-color);
padding: 0;
&:hover {
color: var(--link-hover-color);
text-decoration: underline;
}
}
}
}

View File

@ -21,6 +21,7 @@ export enum Feature {
*/
export enum MiscellaneousFeature {
CommentAnchorFix = "comment-anchor-fix",
TopicInfoIgnore = "topic-info-ignore",
}
/**