[Blacklist] Mark posts that match any filters (#733)

Even if the filter is disabled, the post still gets a class that makes the info bar red.
This commit is contained in:
Cinder 2024-08-23 06:35:57 -07:00 committed by GitHub
parent 0a7efad27b
commit 4fb8944b29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 0 deletions

View File

@ -7,7 +7,10 @@ let Blacklist = {};
Blacklist.isAnonymous = false;
Blacklist.filters = {};
Blacklist.hiddenPosts = new Set();
Blacklist.matchedPosts = new Set();
Blacklist.ui = [];
/** Import the anonymous blacklist from the LocalStorage */
@ -198,6 +201,24 @@ Blacklist.update_visibility = function () {
});
};
/**
* Adds a `filter-matches` class to any thumbnails that match any of the filters,
* including disabled ones. Only needs to run after new posts get added to the page.
*/
Blacklist.update_styles = function () {
let allPosts = [];
for (const filter of Object.values(Blacklist.filters))
allPosts = allPosts.concat(Array.from(filter.matchIDs));
Blacklist.matchedPosts = new Set(allPosts);
console.log("matched", Blacklist.matchedPosts);
$(".filter-matches").removeClass("filter-matches");
for (const postID of Blacklist.matchedPosts)
PostCache.apply(postID, ($element) => {
$element.addClass("filter-matches");
});
};
$(() => {
Blacklist.init_anonymous_blacklist();
Blacklist.init_blacklist_editor();
@ -205,6 +226,7 @@ $(() => {
Blacklist.regenerate_filters();
Blacklist.add_posts($(".blacklistable"));
Blacklist.update_styles();
Blacklist.update_visibility();
$("#blacklisted-hider").remove();

View File

@ -61,6 +61,7 @@ Thumbnails.initialize = function () {
if (replacedPosts.length > 0) {
Blacklist.add_posts(replacedPosts);
Blacklist.update_styles();
Blacklist.update_visibility();
}

View File

@ -23,6 +23,9 @@ article.post-preview {
font-size: 80%;
margin-bottom: 0;
}
&.filter-matches .desc {
background-color: var(--palette-background-red);
}
.post-score>span {
font-size: 0.8rem;