diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js index 7d46f058f..a8d45f9c2 100644 --- a/app/assets/javascripts/blacklists.js +++ b/app/assets/javascripts/blacklists.js @@ -38,9 +38,12 @@ })[0]; if (match) { match.disabled = !match.disabled; + var hash = tags.hash(); if (match.disabled) { + Danbooru.Cookie.put("bl:" + hash, "1", "session"); $(e.target).addClass("blacklisted-active"); } else { + Danbooru.Cookie.remove("bl:" + hash); $(e.target).removeClass("blacklisted-active"); } } @@ -56,9 +59,13 @@ var item = $("
  • "); var link = $(""); var count = $(""); + var hash = entry.tags.hash(); link.text(entry.tags); link.click(Danbooru.Blacklist.toggle_entry); + if (Danbooru.Cookie.get("bl:" + hash)) { + link.click(); + } count.html(entry.hits); item.append(link); item.append(" "); @@ -162,6 +169,6 @@ $(document).ready(function() { if ($("#c-moderator-post-queues").length) { return; } - + Danbooru.Blacklist.initialize_all(); }); diff --git a/app/assets/javascripts/cookie.js b/app/assets/javascripts/cookie.js index e1aa6aeca..d6565adb3 100644 --- a/app/assets/javascripts/cookie.js +++ b/app/assets/javascripts/cookie.js @@ -2,14 +2,18 @@ Danbooru.Cookie = {}; Danbooru.Cookie.put = function(name, value, days) { - if (days == null) { - days = 365; + var expires = ""; + if (days !== "session") { + if (!days) { + days = 365; + } + + var date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + expires = "expires=" + date.toGMTString() + "; "; } - var date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - var expires = "; expires=" + date.toGMTString(); - document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/"; + document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires + "path=/"; } Danbooru.Cookie.raw_get = function(name) { diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index b2c28353a..bc0a258d6 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -99,6 +99,15 @@ return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); } + String.prototype.hash = function() { + var hash = 5381, i = this.length; + + while(i) + hash = (hash * 33) ^ this.charCodeAt(--i) + + return hash >>> 0; + } + $.fn.selectRange = function(start, end) { return this.each(function() { if (this.setSelectionRange) {