From 97a5579d0d7d5db9e4599d50df69934e4fd21bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 23 Feb 2013 14:50:01 +1100 Subject: [PATCH 1/4] Remove trailing whitespace in files I'm about to edit --- app/assets/javascripts/blacklists.js | 46 ++++++++++++++-------------- app/assets/javascripts/utility.js | 14 ++++----- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js index 66e6b09c0..fa44618f7 100644 --- a/app/assets/javascripts/blacklists.js +++ b/app/assets/javascripts/blacklists.js @@ -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 = $("
  • "); var link = $(""); var count = $(""); @@ -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,20 +84,20 @@ } }); }); - + 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))) { @@ -105,18 +105,18 @@ } } } - + return false; } - + 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 { diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index 3bc64f84f..a32b48a89 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -2,27 +2,27 @@ 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.without = function(array, element) { var temp = []; $.each(array, function(i, v) { @@ -32,7 +32,7 @@ }); return temp; } - + Danbooru.reject = function(array, f) { var filtered = []; $.each(array, function(i, x) { 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 2/4] 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) { From 8f3f997a57138e5dde29ed66711376b28e547fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 23 Feb 2013 14:46:55 +1100 Subject: [PATCH 3/4] Remove useless code --- app/assets/javascripts/blacklists.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js index 1b919bb33..506b55fd6 100644 --- a/app/assets/javascripts/blacklists.js +++ b/app/assets/javascripts/blacklists.js @@ -98,15 +98,7 @@ 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.intersect(tags, blacklist.exclude).length)) { - return true; - } - } - } - - return false; + return Danbooru.is_subset(tags, blacklist.require) && !Danbooru.intersect(tags, blacklist.exclude).length; } Danbooru.Blacklist.post_hide = function(post) { From bb521794e9f76c58eb325b2ad6b6854e665b2042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Sat, 23 Feb 2013 15:13:39 +1100 Subject: [PATCH 4/4] Fix coding style --- app/assets/javascripts/utility.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index 873cd8fd2..c34c2ba64 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -31,11 +31,9 @@ { if (a[0] < b[0]) { a.shift(); - } - else if (a[0] > b[0]) { + } else if (a[0] > b[0]) { b.shift(); - } - else { + } else { result.push(a.shift()); b.shift(); }