This commit is contained in:
albert
2013-03-31 17:05:45 -04:00
parent b751aaf7cf
commit 6e1257353c

View File

@@ -1,10 +1,10 @@
(function() { (function() {
Danbooru.Blacklist = {}; Danbooru.Blacklist = {};
Danbooru.Blacklist.blacklists = []; Danbooru.Blacklist.entries = [];
Danbooru.Blacklist.parse_entry = function(string) { Danbooru.Blacklist.parse_entry = function(string) {
var blacklist = { var entry = {
"tags": string, "tags": string,
"require": [], "require": [],
"exclude": [], "exclude": [],
@@ -14,57 +14,52 @@
var matches = string.match(/\S+/g) || []; var matches = string.match(/\S+/g) || [];
$.each(matches, function(i, tag) { $.each(matches, function(i, tag) {
if (tag.charAt(0) === '-') { if (tag.charAt(0) === '-') {
blacklist.exclude.push(tag.slice(1)); entry.exclude.push(tag.slice(1));
} else { } else {
blacklist.require.push(tag); entry.require.push(tag);
} }
}); });
return blacklist; return entry;
} }
Danbooru.Blacklist.parse_entries = function() { Danbooru.Blacklist.parse_entries = function() {
var entries = (Danbooru.meta("blacklisted-tags") || "nozomiisthebestlovelive").replace(/(rating:[qes])\w+/ig, "$1").toLowerCase().split(/,/); var entries = (Danbooru.meta("blacklisted-tags") || "nozomiisthebestlovelive").replace(/(rating:[qes])\w+/ig, "$1").toLowerCase().split(/,/);
$.each(entries, function(i, tags) { $.each(entries, function(i, tags) {
var blacklist = Danbooru.Blacklist.parse_entry(tags); var entry = Danbooru.Blacklist.parse_entry(tags);
Danbooru.Blacklist.blacklists.push(blacklist); Danbooru.Blacklist.entries.push(entry);
}); });
} }
Danbooru.Blacklist.toggle = function(e) { Danbooru.Blacklist.show_entry = function(e) {
$(".blacklisted").each(function(i, element) { $(".blacklisted").addClass("blacklisted-active");
var $element = $(element);
if ($element.hasClass("blacklisted-active")) {
var tag = $(e.target).html();
var blacklist = Danbooru.Blacklist.parse_entry(tag);
if (Danbooru.Blacklist.post_match($element, blacklist)) { Danbooru.Blacklist.posts().each(function(i, post) {
$element.removeClass("blacklisted-active"); var $post = $(post);
} var tag = $(e.target).html();
} else { var entry = Danbooru.Blacklist.parse_entry(tag);
$element.addClass("blacklisted-active");
if (Danbooru.Blacklist.post_match($post, entry)) {
$post.removeClass("blacklisted-active");
} }
}); });
} }
Danbooru.Blacklist.toggle_all = function(e) { Danbooru.Blacklist.toggle_all = function(e) {
$(".blacklisted").each(function(i, element) { if ($(".blacklisted-active").length) {
var $element = $(element); $(".blacklisted").removeClass("blacklisted-active");
if ($element.hasClass("blacklisted-active")) { } else {
$element.removeClass("blacklisted-active"); $(".blacklisted").addClass("blacklisted-active");
} else { }
$element.addClass("blacklisted-active");
}
});
} }
Danbooru.Blacklist.update_sidebar = function() { Danbooru.Blacklist.update_sidebar = function() {
if (this.blacklists.length > 0) { if (this.entries.length > 0) {
this.blacklists.unshift({"tags": "~all~", "hits": -1}); this.entries.unshift({"tags": "~all~", "hits": -1});
} }
$.each(this.blacklists, function(i, blacklist) { $.each(this.entries, function(i, entry) {
if (blacklist.hits === 0) { if (entry.hits === 0) {
return; return;
} }
@@ -72,15 +67,15 @@
var link = $("<a/>"); var link = $("<a/>");
var count = $("<span/>"); var count = $("<span/>");
if (blacklist.tags === "~all~") { if (entry.tags === "~all~") {
link.html("All"); link.html("All");
link.click(Danbooru.Blacklist.toggle_all); link.click(Danbooru.Blacklist.toggle_all);
item.append(link); item.append(link);
item.append(" "); item.append(" ");
} else { } else {
link.html(blacklist.tags); link.html(entry.tags);
link.click(Danbooru.Blacklist.toggle); link.click(Danbooru.Blacklist.show_entry);
count.html(blacklist.hits); count.html(entry.hits);
item.append(link); item.append(link);
item.append(" "); item.append(" ");
item.append(count); item.append(count);
@@ -93,17 +88,17 @@
} }
Danbooru.Blacklist.apply = function() { Danbooru.Blacklist.apply = function() {
$.each(this.blacklists, function(i, blacklist) { $.each(this.entries, function(i, entry) {
blacklist.hits = 0; entry.hits = 0;
}); });
var count = 0 var count = 0
$.each(this.posts(), function(i, post) { $.each(this.posts(), function(i, post) {
$.each(Danbooru.Blacklist.blacklists, function(i, blacklist) { $.each(Danbooru.Blacklist.entries, function(i, entry) {
if (Danbooru.Blacklist.post_match(post, blacklist)) { if (Danbooru.Blacklist.post_match(post, entry)) {
Danbooru.Blacklist.post_hide(post); Danbooru.Blacklist.post_hide(post);
blacklist.hits += 1; entry.hits += 1;
count += 1; count += 1;
} }
}); });
@@ -116,7 +111,7 @@
return $(".post-preview"); return $(".post-preview");
} }
Danbooru.Blacklist.post_match = function(post, blacklist) { Danbooru.Blacklist.post_match = function(post, entry) {
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"));
@@ -125,7 +120,7 @@
tags.push("status:" + v); tags.push("status:" + v);
}); });
return (blacklist.require.length > 0 || blacklist.exclude.length > 0) && Danbooru.is_subset(tags, blacklist.require) && !Danbooru.intersect(tags, blacklist.exclude).length; return (entry.require.length > 0 || entry.exclude.length > 0) && Danbooru.is_subset(tags, entry.require) && !Danbooru.intersect(tags, entry.exclude).length;
} }
Danbooru.Blacklist.post_hide = function(post) { Danbooru.Blacklist.post_hide = function(post) {