diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js new file mode 100644 index 000000000..1611a72a6 --- /dev/null +++ b/app/assets/javascripts/blacklists.js @@ -0,0 +1,116 @@ +(function() { + Danbooru.Blacklist = {}; + + Danbooru.Blacklist.blacklists = []; + + Danbooru.Blacklist.parse_entries = function() { + var entries = (Danbooru.meta("blacklisted-tags") || "").replace(/(rating:[qes])\w+/, "$1").split(/,/); + $.each(entries, function(i, tags) { + var blacklist = { + "tags": tags, + "require": [], + "exclude": [], + "disabled": false, + "hits": 0 + }; + var matches = tags.match(/\S+/g) || []; + $.each(matches, function(i, tag) { + if (tag.charAt(0) === '-') { + blacklist.exclude.push(tag.slice(1)); + } else { + blacklist.require.push(tag); + } + }) + Danbooru.Blacklist.blacklists.push(blacklist); + }); + } + + Danbooru.Blacklist.toggle = function(e) { + $(".blacklisted").each(function(i, element) { + var $element = $(element); + if ($element.hasClass("blacklisted-active")) { + $element.removeClass("blacklisted-active"); + } else { + $element.addClass("blacklisted-active"); + } + }); + } + + Danbooru.Blacklist.update_sidebar = function() { + $.each(this.blacklists, function(i, blacklist) { + if (blacklist.hits === 0) { + return; + } + + var item = $("
"); + var link = $(""); + var count = $(""); + link.html(blacklist.tags); + link.click(Danbooru.Blacklist.toggle); + count.html(blacklist.hits); + item.append(link); + item.append(" "); + 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)) { + Danbooru.Blacklist.post_hide(post); + blacklist.hits += 1; + count += 1; + } + }); + }); + + return count; + } + + Danbooru.Blacklist.posts = function() { + return $("article.post-preview"); + } + + Danbooru.Blacklist.post_match = function(post, blacklist) { + var $post = $(post); + var tags = $post.data("tags").match(/\S+/g) || []; + tags.push("rating:" + $post.data("rating")); + tags.push("uploader:" + $post.data("uploader")); + + if (Danbooru.is_subset(tags, blacklist.require)) { + if (blacklist.exclude.length == 0 || (!Danbooru.is_subset(tags, blacklist.exclude))) { + return true; + } + } + + return false; + } + + Danbooru.Blacklist.post_hide = function(post) { + var $post = $(post); + $post.addClass("blacklisted").addClass("blacklisted-active"); + } + + Danbooru.Blacklist.initialize = function() { + Danbooru.Blacklist.parse_entries(); + if (Danbooru.Blacklist.apply() > 0) { + Danbooru.Blacklist.update_sidebar(); + } else { + $("#blacklist-box").hide(); + } + } +})(); + +$(document).ready(function() { + Danbooru.Blacklist.initialize(); +}); diff --git a/app/assets/javascripts/cookie.js b/app/assets/javascripts/cookie.js index 31ee60a08..8613c1f85 100644 --- a/app/assets/javascripts/cookie.js +++ b/app/assets/javascripts/cookie.js @@ -54,9 +54,9 @@ if (this.get("hide-news-ticker") == "1") { $("#news-ticker").hide(); } else { - $("#close-news-ticker-link").observe("click", function(e) { + $("#close-news-ticker-link").click(function(e) { $("#news-ticker").hide(); - this.put("hide-news-ticker", "1", 1); + Danbooru.Cookie.put("hide-news-ticker", "1", 1); return false; }); } @@ -67,7 +67,7 @@ } })(); -$(document).ready(function() { +$(function() { Danbooru.Cookie.initialize(); }); diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index 78f6de496..bae2db7cf 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -18,4 +18,16 @@ Danbooru.ajax_stop = function(target) { $(target).next("img.wait").remove(); } + + Danbooru.is_subset = function(array, subarray) { + var all = true; + + $.each(subarray, function(i, val) { + if ($.inArray(val, array) === -1) { + all = false; + } + }); + + return all; + } })(); diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 129da4351..3d7b07633 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -626,6 +626,10 @@ article.post-preview { float: left; } +article.post-preview.blacklisted-active { + display: none; +} + div#c-posts { div.notice { font-size: 0.8em; @@ -650,6 +654,23 @@ div#c-posts { aside#sidebar > section > ul ul li { margin-left: 1em; } + + aside#sidebar > section#blacklist-box ul { + margin-left: 1em; + + li { + list-style-type: disc; + } + + a { + color: $link_color; + cursor: pointer; + } + + span { + color: #AAA; + } + } h1 { font-size: $h3_size; @@ -1048,6 +1069,14 @@ div#moderator-dashboard { } +/*** page footer ***/ +footer#page-footer { + clear: both; + margin: 1em; + text-align: center; + padding-top: 1em; + border-top: 2px solid #CCC; +} /*** news ticker ***/ @@ -1074,4 +1103,4 @@ div#news-ticker { a#close-news-ticker-link { float: right; } -} \ No newline at end of file +} diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 49f683caa..edc54c776 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -66,5 +66,7 @@ + + <%= render "static/footer" %>