From e975664f482fe5e475b56b5124191aa1c4bf9932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 23 Feb 2013 14:38:34 +1100 Subject: [PATCH] Use OR instead of AND when excluding tags for blacklist. This is because there currently is no way to do this, and this commit doesn't remove the AND capability either. For example, take the original blacklist "a -b -c". Currently, that means "Don't show a unless both b and c are present", but now it means "Don't show a unless either b or c are present". For the original meaning, you now have to do this with two blacklists: "a -b" and "a -c" --- app/assets/javascripts/blacklists.js | 2 +- app/assets/javascripts/utility.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js index fa44618f7..1b919bb33 100644 --- a/app/assets/javascripts/blacklists.js +++ b/app/assets/javascripts/blacklists.js @@ -100,7 +100,7 @@ if (blacklist.require.length > 0 || blacklist.exclude.length > 0) { if (blacklist.require.length === 0 || Danbooru.is_subset(tags, blacklist.require)) { - if (blacklist.exclude.length === 0 || (!Danbooru.is_subset(tags, blacklist.exclude))) { + if (blacklist.exclude.length === 0 || (!Danbooru.intersect(tags, blacklist.exclude).length)) { return true; } } diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index a32b48a89..873cd8fd2 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -23,6 +23,26 @@ 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) { var temp = []; $.each(array, function(i, v) {