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