Add utility regexp split function for non-whitespace words

This commit is contained in:
BrokenEagle
2020-03-07 06:10:50 +00:00
parent d1aed303fd
commit 161e776cf7
4 changed files with 15 additions and 14 deletions

View File

@@ -15,8 +15,7 @@ Blacklist.parse_entry = function(string) {
"hits": 0,
"min_score": null
};
var matches = string.match(/\S+/g) || [];
$.each(matches, function(i, tag) {
Utility.regexp_split(string).forEach(function(tag) {
if (tag.charAt(0) === '-') {
entry.exclude.push(tag.slice(1));
} else if (tag.charAt(0) === '~') {
@@ -169,11 +168,11 @@ Blacklist.post_match = function(post, entry) {
var score = parseInt($post.attr("data-score"));
var score_test = entry.min_score === null || score < entry.min_score;
var tags = String($post.attr("data-tags")).match(/\S+/g) || [];
tags = tags.concat(String($post.attr("data-pools")).match(/\S+/g) || []);
var tags = Utility.regexp_split($post.attr("data-tags"));
tags.push(...Utility.regexp_split($post.attr("data-pools")));
tags.push("rating:" + $post.data("rating"));
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
$.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) {
Utility.regexp_split($post.data("flags")).forEach(function(v) {
tags.push("status:" + v);
});

View File

@@ -550,8 +550,8 @@ Post.update_tag_count = function(event) {
let count = 0;
if (event) {
let tags = [...new Set($(event.target).val().match(/\S+/g))];
if (tags) {
let tags = Utility.regexp_split($(event.target).val());
if (tags.length) {
count = tags.length;
string = (count === 1) ? (count + " tag") : (count + " tags")
}

View File

@@ -89,27 +89,25 @@ RelatedTag.current_tag = function() {
}
RelatedTag.update_selected = function(e) {
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
var current_tags = RelatedTag.current_tags();
var $all_tags = $(".related-tags a.search-tag");
$all_tags.removeClass("selected");
$all_tags.each(function(i, tag) {
if (current_tags.indexOf(tag.textContent.replace(/ /g, "_")) > -1) {
if (current_tags.includes(tag.textContent.replace(/ /g, "_"))) {
$(tag).addClass("selected");
}
});
}
RelatedTag.tags_include = function(name) {
var current = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
return $.inArray(name.toLowerCase(), current) > -1;
RelatedTag.current_tags = function() {
return Utility.regexp_split($("#upload_tag_string,#post_tag_string").val().toLowerCase());
}
RelatedTag.toggle_tag = function(e) {
var $field = $("#upload_tag_string,#post_tag_string");
var tag = $(e.target).html().replace(/ /g, "_").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
if (RelatedTag.tags_include(tag)) {
if (RelatedTag.current_tags().includes(tag)) {
var escaped_tag = Utility.regexp_escape(tag);
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
} else {

View File

@@ -108,6 +108,10 @@ Utility.regexp_escape = function(string) {
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
Utility.regexp_split = function(string) {
return [...new Set(String(string === null || string === undefined ? "" : string).match(/\S+/g))];
}
$.fn.selectEnd = function() {
return this.each(function() {
this.focus();