From 49b8f6ca43a2cac51f34851f6b56da8b0de624bf Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 6 Oct 2015 15:20:50 -0700 Subject: [PATCH] addresses #2518: Rework disabled blacklist cookies --- app/assets/javascripts/blacklists.js | 16 ++++++++-------- app/assets/javascripts/cookie.js | 9 ++++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js index 0751d76cd..c72fb2c1d 100644 --- a/app/assets/javascripts/blacklists.js +++ b/app/assets/javascripts/blacklists.js @@ -40,10 +40,10 @@ match.disabled = !match.disabled; var hash = tags.hash(); if (match.disabled) { - Danbooru.Cookie.put("bl:" + hash, "1", "session"); + Danbooru.Cookie.put("b" + hash, "1", "session"); $(e.target).addClass("blacklisted-active"); } else { - Danbooru.Cookie.remove("bl:" + hash); + Danbooru.Cookie.remove("b" + hash); $(e.target).removeClass("blacklisted-active"); } } @@ -69,7 +69,7 @@ item.append(" "); item.append(count); - if (Danbooru.Cookie.get("bl:" + hash)) { + if (Danbooru.Cookie.get("b" + hash)) { link.click(); } @@ -80,7 +80,7 @@ } Danbooru.Blacklist.initialize_disable_all_blacklists = function() { - if (Danbooru.Cookie.get("disable-all-blacklists") === "1") { + if (Danbooru.Cookie.get("dab") === "1") { $("#re-enable-all-blacklists").show(); $("#blacklist-list a:not(.blacklisted-active)").click(); Danbooru.Blacklist.apply(); @@ -92,9 +92,9 @@ $("#disable-all-blacklists").hide(); $("#re-enable-all-blacklists").show(); $("#blacklist-list a:not(.blacklisted-active)").click(); - Danbooru.Cookie.put("disable-all-blacklists", "1"); + Danbooru.Cookie.put("dab", "1"); $.each(Danbooru.Blacklist.entries, function(i, entry) { - Danbooru.Cookie.put("bl:" + entry.tags.hash(), "1", "session"); + Danbooru.Cookie.put("b" + entry.tags.hash(), "1", "session"); }); e.preventDefault(); }); @@ -103,9 +103,9 @@ $("#disable-all-blacklists").show(); $("#re-enable-all-blacklists").hide(); $("#blacklist-list a.blacklisted-active").click(); - Danbooru.Cookie.put("disable-all-blacklists", "0"); + Danbooru.Cookie.put("dab", "0"); $.each(Danbooru.Blacklist.entries, function(i, entry) { - Danbooru.Cookie.remove("bl:" + entry.tags.hash()); + Danbooru.Cookie.remove("b" + entry.tags.hash()); }); e.preventDefault(); }); diff --git a/app/assets/javascripts/cookie.js b/app/assets/javascripts/cookie.js index d6565adb3..3ce42224d 100644 --- a/app/assets/javascripts/cookie.js +++ b/app/assets/javascripts/cookie.js @@ -13,7 +13,14 @@ expires = "expires=" + date.toGMTString() + "; "; } - document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires + "path=/"; + var new_val = name + "=" + encodeURIComponent(value) + "; " + expires + "path=/"; + if (document.cookie.length < (4090 - new_val.length)) { + document.cookie = new_val; + return true; + } else { + Danbooru.error("You have too many cookies on this site. Consider deleting them all.") + return false; + } } Danbooru.Cookie.raw_get = function(name) {