Merge pull request #4329 from BrokenEagle/update-blacklist-controls
Update blacklist controls
This commit is contained in:
@@ -15,8 +15,7 @@ Blacklist.parse_entry = function(string) {
|
|||||||
"hits": 0,
|
"hits": 0,
|
||||||
"min_score": null
|
"min_score": null
|
||||||
};
|
};
|
||||||
var matches = string.match(/\S+/g) || [];
|
Utility.regexp_split(string).forEach(function(tag) {
|
||||||
$.each(matches, function(i, tag) {
|
|
||||||
if (tag.charAt(0) === '-') {
|
if (tag.charAt(0) === '-') {
|
||||||
entry.exclude.push(tag.slice(1));
|
entry.exclude.push(tag.slice(1));
|
||||||
} else if (tag.charAt(0) === '~') {
|
} else if (tag.charAt(0) === '~') {
|
||||||
@@ -35,23 +34,24 @@ Blacklist.parse_entries = function() {
|
|||||||
var entries = (Utility.meta("blacklisted-tags") || "nozomiisthebestlovelive").replace(/(rating:[qes])\w+/ig, "$1").toLowerCase().split(/,/);
|
var entries = (Utility.meta("blacklisted-tags") || "nozomiisthebestlovelive").replace(/(rating:[qes])\w+/ig, "$1").toLowerCase().split(/,/);
|
||||||
entries = entries.filter(e => e.trim() !== "");
|
entries = entries.filter(e => e.trim() !== "");
|
||||||
|
|
||||||
$.each(entries, function(i, tags) {
|
entries.forEach(function(tags) {
|
||||||
var entry = Blacklist.parse_entry(tags);
|
var entry = Blacklist.parse_entry(tags);
|
||||||
Blacklist.entries.push(entry);
|
Blacklist.entries.push(entry);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Blacklist.toggle_entry = function(e) {
|
Blacklist.toggle_entry = function(e) {
|
||||||
var tags = $(e.target).text();
|
var $link = $(e.target);
|
||||||
|
var tags = $link.text();
|
||||||
var match = $.grep(Blacklist.entries, function(entry, i) {
|
var match = $.grep(Blacklist.entries, function(entry, i) {
|
||||||
return entry.tags === tags;
|
return entry.tags === tags;
|
||||||
})[0];
|
})[0];
|
||||||
if (match) {
|
if (match) {
|
||||||
match.disabled = !match.disabled;
|
match.disabled = !match.disabled;
|
||||||
if (match.disabled) {
|
if (match.disabled) {
|
||||||
Blacklist.post_hide(e.target);
|
$link.addClass("blacklisted-inactive");
|
||||||
} else {
|
} else {
|
||||||
Blacklist.post_unhide(e.target);
|
$link.removeClass("blacklisted-inactive");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Blacklist.apply();
|
Blacklist.apply();
|
||||||
@@ -59,7 +59,7 @@ Blacklist.toggle_entry = function(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Blacklist.update_sidebar = function() {
|
Blacklist.update_sidebar = function() {
|
||||||
$.each(this.entries, function(i, entry) {
|
Blacklist.entries.forEach(function(entry) {
|
||||||
if (entry.hits === 0) {
|
if (entry.hits === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -84,58 +84,78 @@ Blacklist.update_sidebar = function() {
|
|||||||
$("#blacklist-box").show();
|
$("#blacklist-box").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Blacklist.disable_all = function() {
|
||||||
|
Blacklist.entries.forEach(function(entry) {
|
||||||
|
entry.disabled = true;
|
||||||
|
});
|
||||||
|
// There is no need to process the blacklist when disabling
|
||||||
|
Blacklist.posts().removeClass("blacklisted-active");
|
||||||
|
$("#disable-all-blacklists").hide();
|
||||||
|
$("#re-enable-all-blacklists").show();
|
||||||
|
$("#blacklist-list a").addClass("blacklisted-inactive");
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.enable_all = function() {
|
||||||
|
Blacklist.entries.forEach(function(entry) {
|
||||||
|
entry.disabled = false;
|
||||||
|
});
|
||||||
|
Blacklist.apply();
|
||||||
|
$("#disable-all-blacklists").show();
|
||||||
|
$("#re-enable-all-blacklists").hide();
|
||||||
|
$("#blacklist-list a").removeClass("blacklisted-inactive");
|
||||||
|
}
|
||||||
|
|
||||||
Blacklist.initialize_disable_all_blacklists = function() {
|
Blacklist.initialize_disable_all_blacklists = function() {
|
||||||
if (Cookie.get("dab") === "1") {
|
if (Cookie.get("dab") === "1") {
|
||||||
$("#re-enable-all-blacklists").show();
|
Blacklist.disable_all();
|
||||||
$("#blacklist-list a:not(.blacklisted-active)").click();
|
|
||||||
Blacklist.apply();
|
|
||||||
} else {
|
} else {
|
||||||
|
// The blacklist has already been processed by this point
|
||||||
$("#disable-all-blacklists").show()
|
$("#disable-all-blacklists").show()
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#disable-all-blacklists").on("click.danbooru", function(e) {
|
$("#disable-all-blacklists").on("click.danbooru", function(e) {
|
||||||
$("#disable-all-blacklists").hide();
|
|
||||||
$("#re-enable-all-blacklists").show();
|
|
||||||
Cookie.put("dab", "1");
|
Cookie.put("dab", "1");
|
||||||
$("#blacklist-list a:not(.blacklisted-active)").click();
|
Blacklist.disable_all();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#re-enable-all-blacklists").on("click.danbooru", function(e) {
|
$("#re-enable-all-blacklists").on("click.danbooru", function(e) {
|
||||||
$("#disable-all-blacklists").show();
|
|
||||||
$("#re-enable-all-blacklists").hide();
|
|
||||||
Cookie.put("dab", "0");
|
Cookie.put("dab", "0");
|
||||||
$("#blacklist-list a.blacklisted-active").click();
|
Blacklist.enable_all();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Blacklist.apply = function() {
|
Blacklist.apply = function() {
|
||||||
$.each(this.entries, function(i, entry) {
|
Blacklist.entries.forEach(function(entry) {
|
||||||
entry.hits = 0;
|
entry.hits = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
|
|
||||||
$.each(this.posts(), function(i, post) {
|
Blacklist.posts().each(function(i, post) {
|
||||||
var post_count = 0;
|
count += Blacklist.apply_post(post);
|
||||||
$.each(Blacklist.entries, function(j, entry) {
|
|
||||||
if (Blacklist.post_match(post, entry)) {
|
|
||||||
entry.hits += 1;
|
|
||||||
count += 1;
|
|
||||||
post_count += 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (post_count > 0) {
|
|
||||||
Blacklist.post_hide(post);
|
|
||||||
} else {
|
|
||||||
Blacklist.post_unhide(post);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Blacklist.apply_post = function(post) {
|
||||||
|
var post_count = 0;
|
||||||
|
Blacklist.entries.forEach(function(entry) {
|
||||||
|
if (Blacklist.post_match(post, entry)) {
|
||||||
|
entry.hits += 1;
|
||||||
|
post_count += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (post_count > 0) {
|
||||||
|
Blacklist.post_hide(post);
|
||||||
|
} else {
|
||||||
|
Blacklist.post_unhide(post);
|
||||||
|
}
|
||||||
|
return post_count;
|
||||||
|
};
|
||||||
|
|
||||||
Blacklist.posts = function() {
|
Blacklist.posts = function() {
|
||||||
return $(".post-preview, #image-container, #c-comments .post, .mod-queue-preview.post-preview");
|
return $(".post-preview, #image-container, #c-comments .post, .mod-queue-preview.post-preview");
|
||||||
}
|
}
|
||||||
@@ -149,11 +169,11 @@ Blacklist.post_match = function(post, entry) {
|
|||||||
var score = parseInt($post.attr("data-score"));
|
var score = parseInt($post.attr("data-score"));
|
||||||
var score_test = entry.min_score === null || score < entry.min_score;
|
var score_test = entry.min_score === null || score < entry.min_score;
|
||||||
|
|
||||||
var tags = String($post.attr("data-tags")).match(/\S+/g) || [];
|
var tags = Utility.regexp_split($post.attr("data-tags"));
|
||||||
tags = tags.concat(String($post.attr("data-pools")).match(/\S+/g) || []);
|
tags.push(...Utility.regexp_split($post.attr("data-pools")));
|
||||||
tags.push("rating:" + $post.data("rating"));
|
tags.push("rating:" + $post.data("rating"));
|
||||||
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
|
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
|
||||||
$.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) {
|
Utility.regexp_split($post.data("flags")).forEach(function(v) {
|
||||||
tags.push("status:" + v);
|
tags.push("status:" + v);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -164,7 +184,7 @@ Blacklist.post_match = function(post, entry) {
|
|||||||
|
|
||||||
Blacklist.post_hide = function(post) {
|
Blacklist.post_hide = function(post) {
|
||||||
var $post = $(post);
|
var $post = $(post);
|
||||||
$post.addClass("blacklisted").addClass("blacklisted-active");
|
$post.addClass("blacklisted blacklisted-active");
|
||||||
|
|
||||||
var $video = $post.find("video").get(0);
|
var $video = $post.find("video").get(0);
|
||||||
if ($video) {
|
if ($video) {
|
||||||
|
|||||||
@@ -550,8 +550,8 @@ Post.update_tag_count = function(event) {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
let tags = [...new Set($(event.target).val().match(/\S+/g))];
|
let tags = Utility.regexp_split($(event.target).val());
|
||||||
if (tags) {
|
if (tags.length) {
|
||||||
count = tags.length;
|
count = tags.length;
|
||||||
string = (count === 1) ? (count + " tag") : (count + " tags")
|
string = (count === 1) ? (count + " tag") : (count + " tags")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,27 +89,25 @@ RelatedTag.current_tag = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.update_selected = function(e) {
|
RelatedTag.update_selected = function(e) {
|
||||||
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
var current_tags = RelatedTag.current_tags();
|
||||||
var $all_tags = $(".related-tags a.search-tag");
|
var $all_tags = $(".related-tags a.search-tag");
|
||||||
$all_tags.removeClass("selected");
|
$all_tags.removeClass("selected");
|
||||||
|
|
||||||
$all_tags.each(function(i, tag) {
|
$all_tags.each(function(i, tag) {
|
||||||
if (current_tags.indexOf(tag.textContent.replace(/ /g, "_")) > -1) {
|
if (current_tags.includes(tag.textContent.replace(/ /g, "_"))) {
|
||||||
$(tag).addClass("selected");
|
$(tag).addClass("selected");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.tags_include = function(name) {
|
RelatedTag.current_tags = function() {
|
||||||
var current = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
return Utility.regexp_split($("#upload_tag_string,#post_tag_string").val().toLowerCase());
|
||||||
return $.inArray(name.toLowerCase(), current) > -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.toggle_tag = function(e) {
|
RelatedTag.toggle_tag = function(e) {
|
||||||
var $field = $("#upload_tag_string,#post_tag_string");
|
var $field = $("#upload_tag_string,#post_tag_string");
|
||||||
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
||||||
|
|
||||||
if (RelatedTag.tags_include(tag)) {
|
if (RelatedTag.current_tags().includes(tag)) {
|
||||||
var escaped_tag = Utility.regexp_escape(tag);
|
var escaped_tag = Utility.regexp_escape(tag);
|
||||||
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
|
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -108,6 +108,10 @@ Utility.regexp_escape = function(string) {
|
|||||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utility.regexp_split = function(string) {
|
||||||
|
return [...new Set(String(string === null || string === undefined ? "" : string).match(/\S+/g))];
|
||||||
|
}
|
||||||
|
|
||||||
$.fn.selectEnd = function() {
|
$.fn.selectEnd = function() {
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
this.focus();
|
this.focus();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
a.blacklisted-active {
|
a.blacklisted-inactive {
|
||||||
text-decoration: line-through;
|
text-decoration: line-through;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
var post_id = <%= @post.id %>;
|
|
||||||
var $post = $(`#post_${post_id}`);
|
|
||||||
|
|
||||||
<% if @post.valid? %>
|
<% if @post.valid? %>
|
||||||
$post.replaceWith("<%= j PostPresenter.preview(@post, show_deleted: true) %>");
|
var $post = $("#post_<%= @post.id %>");
|
||||||
|
<% if !CurrentUser.disable_post_tooltips %>
|
||||||
|
$post.find("img").qtip("destroy", true);
|
||||||
|
<% end %>
|
||||||
|
var $new_post = $("<%= j PostPresenter.preview(@post, show_deleted: true) %>");
|
||||||
|
Danbooru.Blacklist.apply_post($new_post.get(0));
|
||||||
|
$("#post_<%= @post.id %>").replaceWith($new_post);
|
||||||
|
<% if params[:mode] == "quick-edit" %>
|
||||||
|
Danbooru.PostModeMenu.close_edit_form();
|
||||||
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
Danbooru.error(`Post #${post_id}: <%= j @post.errors.full_messages.join("; ") %>`);
|
Danbooru.error(`Post #<%= @post.id %>: <%= j @post.errors.full_messages.join("; ") %>`);
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if @post.valid? && params[:mode] == "quick-edit" %>
|
|
||||||
Danbooru.PostModeMenu.close_edit_form();
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
$(document).trigger("danbooru:post-preview-updated", <%= raw @post.to_json %>);
|
$(document).trigger("danbooru:post-preview-updated", <%= raw @post.to_json %>);
|
||||||
|
|||||||
Reference in New Issue
Block a user