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];
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 = $("<li/>");
var link = $("<a/>");
var count = $("<span/>");
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();
});

View File

@@ -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) {

View File

@@ -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) {