js work
This commit is contained in:
@@ -69,11 +69,9 @@
|
||||
Danbooru.Post.update(post_id, {"post[is_rating_locked]": "1"});
|
||||
} else if (s === 'lock-note') {
|
||||
Danbooru.Post.update(post_id, {"post[is_note_locked]": "1"});
|
||||
} else if (s === 'add-to-pool') {
|
||||
Pool.add_post(post_id, 0);
|
||||
} else if (s === "apply-tag-script") {
|
||||
var tag_script = Cookie.get("tag-script");
|
||||
TagScript.run(post_id, tag_script);
|
||||
var tag_script = Danbooru.Cookie.get("tag-script");
|
||||
Danbooru.TagScript.run(post_id, tag_script);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
TagScript = {
|
||||
parse: function(script) {
|
||||
return script.match(/\[.+?\]|\S+/g);
|
||||
},
|
||||
(function() {
|
||||
Danbooru.TagScript = {};
|
||||
|
||||
test: function(tags, predicate) {
|
||||
Danbooru.TagScript.parse = function(script) {
|
||||
return script.match(/\[.+?\]|\S+/g);
|
||||
}
|
||||
|
||||
Danbooru.TagScript.test = function(tags, predicate) {
|
||||
var split_pred = predicate.match(/\S+/g);
|
||||
var is_true = true;
|
||||
|
||||
split_pred.each(function(x) {
|
||||
if (x[0] == "-") {
|
||||
$.each(split_pred, function(i, x) {
|
||||
if (x[0] === "-") {
|
||||
if (tags.include(x.substr(1, 100))) {
|
||||
is_true = false;
|
||||
throw $break;
|
||||
}
|
||||
} else {
|
||||
if (!tags.include(x)) {
|
||||
is_true = false;
|
||||
throw $break;
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return is_true
|
||||
},
|
||||
return is_true;
|
||||
}
|
||||
|
||||
process: function(tags, command) {
|
||||
Danbooru.TagScript.process = function(tags, command) {
|
||||
if (command.match(/^\[if/)) {
|
||||
var match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/)
|
||||
if (TagScript.test(tags, match[1])) {
|
||||
return TagScript.process(tags, match[2]);
|
||||
if (this.test(tags, match[1])) {
|
||||
return this.process(tags, match[2]);
|
||||
} else {
|
||||
return tags;
|
||||
}
|
||||
} else if (command == "[reset]") {
|
||||
} else if (command === "[reset]") {
|
||||
return [];
|
||||
} else if (command[0] == "-") {
|
||||
} else if (command[0] === "-") {
|
||||
return tags.reject(function(x) {return x == command.substr(1, 100)})
|
||||
} else {
|
||||
tags.push(command)
|
||||
return tags;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
run: function(post_id, tag_script) {
|
||||
var commands = TagScript.parse(tag_script);
|
||||
Danbooru.TagScript.run = function(post_id, tag_script) {
|
||||
var commands = this.parse(tag_script);
|
||||
var post = Post.posts.get(post_id);
|
||||
var old_tags = post.tags.join(" ");
|
||||
|
||||
commands.each(function(x) {
|
||||
post.tags = TagScript.process(post.tags, x);
|
||||
$.each(commands, function(i, x) {
|
||||
post.tags = Danbooru.TagScript.process(post.tags, x);
|
||||
})
|
||||
|
||||
Post.update(post_id, {"post[old_tags]": old_tags, "post[tags]": post.tags.join(" ")});
|
||||
Danbooru.Post.update(post_id, {"post[old_tags]": old_tags, "post[tags]": post.tags.join(" ")});
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user