fixes #2474: Make disabled blacklist entries persist across page loads and give option to disable / enable all

This commit is contained in:
r888888888
2015-08-10 16:01:38 -07:00
parent 86c2ae037b
commit d1b5d38521
3 changed files with 27 additions and 7 deletions

View File

@@ -38,9 +38,12 @@
})[0]; })[0];
if (match) { if (match) {
match.disabled = !match.disabled; match.disabled = !match.disabled;
var hash = tags.hash();
if (match.disabled) { if (match.disabled) {
Danbooru.Cookie.put("bl:" + hash, "1", "session");
$(e.target).addClass("blacklisted-active"); $(e.target).addClass("blacklisted-active");
} else { } else {
Danbooru.Cookie.remove("bl:" + hash);
$(e.target).removeClass("blacklisted-active"); $(e.target).removeClass("blacklisted-active");
} }
} }
@@ -56,9 +59,13 @@
var item = $("<li/>"); var item = $("<li/>");
var link = $("<a/>"); var link = $("<a/>");
var count = $("<span/>"); var count = $("<span/>");
var hash = entry.tags.hash();
link.text(entry.tags); link.text(entry.tags);
link.click(Danbooru.Blacklist.toggle_entry); link.click(Danbooru.Blacklist.toggle_entry);
if (Danbooru.Cookie.get("bl:" + hash)) {
link.click();
}
count.html(entry.hits); count.html(entry.hits);
item.append(link); item.append(link);
item.append(" "); item.append(" ");
@@ -162,6 +169,6 @@ $(document).ready(function() {
if ($("#c-moderator-post-queues").length) { if ($("#c-moderator-post-queues").length) {
return; return;
} }
Danbooru.Blacklist.initialize_all(); Danbooru.Blacklist.initialize_all();
}); });

View File

@@ -2,14 +2,18 @@
Danbooru.Cookie = {}; Danbooru.Cookie = {};
Danbooru.Cookie.put = function(name, value, days) { Danbooru.Cookie.put = function(name, value, days) {
if (days == null) { var expires = "";
days = 365; 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(); document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires + "path=/";
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
} }
Danbooru.Cookie.raw_get = function(name) { Danbooru.Cookie.raw_get = function(name) {

View File

@@ -99,6 +99,15 @@
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); 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) { $.fn.selectRange = function(start, end) {
return this.each(function() { return this.each(function() {
if (this.setSelectionRange) { if (this.setSelectionRange) {