Merge pull request #577 from kotarou3/blacklists
Use OR instead of AND when excluding tags for blacklist.
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
(function() {
|
(function() {
|
||||||
Danbooru.Blacklist = {};
|
Danbooru.Blacklist = {};
|
||||||
|
|
||||||
Danbooru.Blacklist.blacklists = [];
|
Danbooru.Blacklist.blacklists = [];
|
||||||
|
|
||||||
Danbooru.Blacklist.parse_entry = function(string) {
|
Danbooru.Blacklist.parse_entry = function(string) {
|
||||||
var blacklist = {
|
var blacklist = {
|
||||||
"tags": string,
|
"tags": string,
|
||||||
"require": [],
|
"require": [],
|
||||||
"exclude": [],
|
"exclude": [],
|
||||||
"disabled": false,
|
"disabled": false,
|
||||||
"hits": 0
|
"hits": 0
|
||||||
};
|
};
|
||||||
var matches = string.match(/\S+/g) || [];
|
var matches = string.match(/\S+/g) || [];
|
||||||
@@ -21,23 +21,23 @@
|
|||||||
});
|
});
|
||||||
return blacklist;
|
return blacklist;
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.parse_entries = function() {
|
Danbooru.Blacklist.parse_entries = function() {
|
||||||
var entries = (Danbooru.meta("blacklisted-tags") || "[]").replace(/(rating:[qes])\w+/, "$1").split(/,/);
|
var entries = (Danbooru.meta("blacklisted-tags") || "[]").replace(/(rating:[qes])\w+/, "$1").split(/,/);
|
||||||
|
|
||||||
$.each(entries, function(i, tags) {
|
$.each(entries, function(i, tags) {
|
||||||
var blacklist = Danbooru.Blacklist.parse_entry(tags);
|
var blacklist = Danbooru.Blacklist.parse_entry(tags);
|
||||||
Danbooru.Blacklist.blacklists.push(blacklist);
|
Danbooru.Blacklist.blacklists.push(blacklist);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.toggle = function(e) {
|
Danbooru.Blacklist.toggle = function(e) {
|
||||||
$(".blacklisted").each(function(i, element) {
|
$(".blacklisted").each(function(i, element) {
|
||||||
var $element = $(element);
|
var $element = $(element);
|
||||||
if ($element.hasClass("blacklisted-active")) {
|
if ($element.hasClass("blacklisted-active")) {
|
||||||
var tag = $(e.target).html();
|
var tag = $(e.target).html();
|
||||||
var blacklist = Danbooru.Blacklist.parse_entry(tag);
|
var blacklist = Danbooru.Blacklist.parse_entry(tag);
|
||||||
|
|
||||||
if (Danbooru.Blacklist.post_match($element, blacklist)) {
|
if (Danbooru.Blacklist.post_match($element, blacklist)) {
|
||||||
$element.removeClass("blacklisted-active");
|
$element.removeClass("blacklisted-active");
|
||||||
}
|
}
|
||||||
@@ -46,13 +46,13 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.update_sidebar = function() {
|
Danbooru.Blacklist.update_sidebar = function() {
|
||||||
$.each(this.blacklists, function(i, blacklist) {
|
$.each(this.blacklists, function(i, blacklist) {
|
||||||
if (blacklist.hits === 0) {
|
if (blacklist.hits === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = $("<li/>");
|
var item = $("<li/>");
|
||||||
var link = $("<a/>");
|
var link = $("<a/>");
|
||||||
var count = $("<span/>");
|
var count = $("<span/>");
|
||||||
@@ -64,17 +64,17 @@
|
|||||||
item.append(count);
|
item.append(count);
|
||||||
$("#blacklist-list").append(item);
|
$("#blacklist-list").append(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#blacklist-box").show();
|
$("#blacklist-box").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.apply = function() {
|
Danbooru.Blacklist.apply = function() {
|
||||||
$.each(this.blacklists, function(i, blacklist) {
|
$.each(this.blacklists, function(i, blacklist) {
|
||||||
blacklist.hits = 0;
|
blacklist.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.blacklists, function(i, blacklist) {
|
||||||
if (Danbooru.Blacklist.post_match(post, blacklist)) {
|
if (Danbooru.Blacklist.post_match(post, blacklist)) {
|
||||||
@@ -84,39 +84,31 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.posts = function() {
|
Danbooru.Blacklist.posts = function() {
|
||||||
return $(".post-preview");
|
return $(".post-preview");
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.post_match = function(post, blacklist) {
|
Danbooru.Blacklist.post_match = function(post, blacklist) {
|
||||||
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"));
|
||||||
tags.push("user:" + $post.data("user"));
|
tags.push("user:" + $post.data("user"));
|
||||||
|
|
||||||
if (blacklist.require.length > 0 || blacklist.exclude.length > 0) {
|
return Danbooru.is_subset(tags, blacklist.require) && !Danbooru.intersect(tags, blacklist.exclude).length;
|
||||||
if (blacklist.require.length === 0 || Danbooru.is_subset(tags, blacklist.require)) {
|
|
||||||
if (blacklist.exclude.length === 0 || (!Danbooru.is_subset(tags, blacklist.exclude))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.post_hide = function(post) {
|
Danbooru.Blacklist.post_hide = function(post) {
|
||||||
var $post = $(post);
|
var $post = $(post);
|
||||||
$post.addClass("blacklisted").addClass("blacklisted-active");
|
$post.addClass("blacklisted").addClass("blacklisted-active");
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Blacklist.initialize_all = function() {
|
Danbooru.Blacklist.initialize_all = function() {
|
||||||
Danbooru.Blacklist.parse_entries();
|
Danbooru.Blacklist.parse_entries();
|
||||||
|
|
||||||
if (Danbooru.Blacklist.apply() > 0) {
|
if (Danbooru.Blacklist.apply() > 0) {
|
||||||
Danbooru.Blacklist.update_sidebar();
|
Danbooru.Blacklist.update_sidebar();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,27 +2,45 @@
|
|||||||
Danbooru.meta = function(key) {
|
Danbooru.meta = function(key) {
|
||||||
return $("meta[name=" + key + "]").attr("content");
|
return $("meta[name=" + key + "]").attr("content");
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.notice = function(msg) {
|
Danbooru.notice = function(msg) {
|
||||||
$('#notice').html(msg).addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast");
|
$('#notice').html(msg).addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast");
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.error = function(msg) {
|
Danbooru.error = function(msg) {
|
||||||
$('#notice').html(msg).removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast");
|
$('#notice').html(msg).removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast");
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.is_subset = function(array, subarray) {
|
Danbooru.is_subset = function(array, subarray) {
|
||||||
var all = true;
|
var all = true;
|
||||||
|
|
||||||
$.each(subarray, function(i, val) {
|
$.each(subarray, function(i, val) {
|
||||||
if ($.inArray(val, array) === -1) {
|
if ($.inArray(val, array) === -1) {
|
||||||
all = false;
|
all = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Danbooru.intersect = function(a, b) {
|
||||||
|
a = a.slice(0).sort();
|
||||||
|
b = b.slice(0).sort();
|
||||||
|
var result = [];
|
||||||
|
while (a.length > 0 && b.length > 0)
|
||||||
|
{
|
||||||
|
if (a[0] < b[0]) {
|
||||||
|
a.shift();
|
||||||
|
} else if (a[0] > b[0]) {
|
||||||
|
b.shift();
|
||||||
|
} else {
|
||||||
|
result.push(a.shift());
|
||||||
|
b.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
Danbooru.without = function(array, element) {
|
Danbooru.without = function(array, element) {
|
||||||
var temp = [];
|
var temp = [];
|
||||||
$.each(array, function(i, v) {
|
$.each(array, function(i, v) {
|
||||||
@@ -32,7 +50,7 @@
|
|||||||
});
|
});
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.reject = function(array, f) {
|
Danbooru.reject = function(array, f) {
|
||||||
var filtered = [];
|
var filtered = [];
|
||||||
$.each(array, function(i, x) {
|
$.each(array, function(i, x) {
|
||||||
|
|||||||
Reference in New Issue
Block a user