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