addresses #2518: Rework disabled blacklist cookies

This commit is contained in:
r888888888
2015-10-06 15:20:50 -07:00
parent 721a8eda29
commit 49b8f6ca43
2 changed files with 16 additions and 9 deletions

View File

@@ -40,10 +40,10 @@
match.disabled = !match.disabled; match.disabled = !match.disabled;
var hash = tags.hash(); var hash = tags.hash();
if (match.disabled) { if (match.disabled) {
Danbooru.Cookie.put("bl:" + hash, "1", "session"); Danbooru.Cookie.put("b" + hash, "1", "session");
$(e.target).addClass("blacklisted-active"); $(e.target).addClass("blacklisted-active");
} else { } else {
Danbooru.Cookie.remove("bl:" + hash); Danbooru.Cookie.remove("b" + hash);
$(e.target).removeClass("blacklisted-active"); $(e.target).removeClass("blacklisted-active");
} }
} }
@@ -69,7 +69,7 @@
item.append(" "); item.append(" ");
item.append(count); item.append(count);
if (Danbooru.Cookie.get("bl:" + hash)) { if (Danbooru.Cookie.get("b" + hash)) {
link.click(); link.click();
} }
@@ -80,7 +80,7 @@
} }
Danbooru.Blacklist.initialize_disable_all_blacklists = function() { 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(); $("#re-enable-all-blacklists").show();
$("#blacklist-list a:not(.blacklisted-active)").click(); $("#blacklist-list a:not(.blacklisted-active)").click();
Danbooru.Blacklist.apply(); Danbooru.Blacklist.apply();
@@ -92,9 +92,9 @@
$("#disable-all-blacklists").hide(); $("#disable-all-blacklists").hide();
$("#re-enable-all-blacklists").show(); $("#re-enable-all-blacklists").show();
$("#blacklist-list a:not(.blacklisted-active)").click(); $("#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) { $.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(); e.preventDefault();
}); });
@@ -103,9 +103,9 @@
$("#disable-all-blacklists").show(); $("#disable-all-blacklists").show();
$("#re-enable-all-blacklists").hide(); $("#re-enable-all-blacklists").hide();
$("#blacklist-list a.blacklisted-active").click(); $("#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) { $.each(Danbooru.Blacklist.entries, function(i, entry) {
Danbooru.Cookie.remove("bl:" + entry.tags.hash()); Danbooru.Cookie.remove("b" + entry.tags.hash());
}); });
e.preventDefault(); e.preventDefault();
}); });

View File

@@ -13,7 +13,14 @@
expires = "expires=" + date.toGMTString() + "; "; 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) { Danbooru.Cookie.raw_get = function(name) {