This commit is contained in:
albert
2013-04-05 16:59:51 -04:00
parent 5a04bc30ba
commit f24d6a6e83
2 changed files with 33 additions and 37 deletions

View File

@@ -31,33 +31,23 @@
}); });
} }
Danbooru.Blacklist.show_entry = function(e) { Danbooru.Blacklist.toggle_entry = function(e) {
$(".blacklisted").addClass("blacklisted-active"); var tags = $(e.target).html();
var match = $.grep(Danbooru.Blacklist.entries, function(entry, i) {
Danbooru.Blacklist.posts().each(function(i, post) { return entry.tags === tags;
var $post = $(post); })[0];
var tag = $(e.target).html(); if (match) {
var entry = Danbooru.Blacklist.parse_entry(tag); match.disabled = !match.disabled;
if (match.disabled) {
if (Danbooru.Blacklist.post_match($post, entry)) { $(e.target).addClass("blacklisted-active");
$post.removeClass("blacklisted-active"); } else {
$(e.target).removeClass("blacklisted-active");
} }
});
}
Danbooru.Blacklist.toggle_all = function(e) {
if ($(".blacklisted-active").length) {
$(".blacklisted").removeClass("blacklisted-active");
} else {
$(".blacklisted").addClass("blacklisted-active");
} }
Danbooru.Blacklist.apply();
} }
Danbooru.Blacklist.update_sidebar = function() { Danbooru.Blacklist.update_sidebar = function() {
if (this.entries.length > 0) {
this.entries.unshift({"tags": "~all~", "hits": -1});
}
$.each(this.entries, function(i, entry) { $.each(this.entries, function(i, entry) {
if (entry.hits === 0) { if (entry.hits === 0) {
return; return;
@@ -67,19 +57,12 @@
var link = $("<a/>"); var link = $("<a/>");
var count = $("<span/>"); var count = $("<span/>");
if (entry.tags === "~all~") { link.html(entry.tags);
link.html("All"); link.click(Danbooru.Blacklist.toggle_entry);
link.click(Danbooru.Blacklist.toggle_all); count.html(entry.hits);
item.append(link); item.append(link);
item.append(" "); item.append(" ");
} else { item.append(count);
link.html(entry.tags);
link.click(Danbooru.Blacklist.show_entry);
count.html(entry.hits);
item.append(link);
item.append(" ");
item.append(count);
}
$("#blacklist-list").append(item); $("#blacklist-list").append(item);
}); });
@@ -95,13 +78,19 @@
var count = 0 var count = 0
$.each(this.posts(), function(i, post) { $.each(this.posts(), function(i, post) {
var post_count = 0;
$.each(Danbooru.Blacklist.entries, function(i, entry) { $.each(Danbooru.Blacklist.entries, function(i, entry) {
if (Danbooru.Blacklist.post_match(post, entry)) { if (Danbooru.Blacklist.post_match(post, entry)) {
Danbooru.Blacklist.post_hide(post);
entry.hits += 1; entry.hits += 1;
count += 1; count += 1;
post_count += 1;
} }
}); });
if (post_count > 0) {
Danbooru.Blacklist.post_hide(post);
} else {
$(post).removeClass("blacklisted-active");
}
}); });
return count; return count;
@@ -112,6 +101,10 @@
} }
Danbooru.Blacklist.post_match = function(post, entry) { Danbooru.Blacklist.post_match = function(post, entry) {
if (entry.disabled) {
return false;
}
var $post = $(post); var $post = $(post);
var tags = String($post.data("tags")).match(/\S+/g) || []; var tags = String($post.data("tags")).match(/\S+/g) || [];
tags.push("rating:" + $post.data("rating")); tags.push("rating:" + $post.data("rating"));
@@ -119,7 +112,6 @@
$.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) { $.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) {
tags.push("status:" + v); tags.push("status:" + v);
}); });
return (entry.require.length > 0 || entry.exclude.length > 0) && Danbooru.is_subset(tags, entry.require) && !Danbooru.intersect(tags, entry.exclude).length; return (entry.require.length > 0 || entry.exclude.length > 0) && Danbooru.is_subset(tags, entry.require) && !Danbooru.intersect(tags, entry.exclude).length;
} }

View File

@@ -14,6 +14,10 @@ article.post-preview {
} }
} }
a.blacklisted-active {
font-weight: bold;
}
.post-preview.blacklisted-active { .post-preview.blacklisted-active {
display: none; display: none;
} }