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"
This commit is contained in:
小太
2013-02-23 14:38:34 +11:00
parent 97a5579d0d
commit e975664f48
2 changed files with 21 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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) {