|
7 | 7 |
|
8 | 8 | // helper function to get the innerText of all elements matching a selector |
9 | 9 | const getAllInnerText = (selector) => Array.from(document.querySelectorAll(selector)) |
10 | | - .map((el) => el.innerText) |
11 | | - .filter((text) => text.trim() !== ""); |
| 10 | + .map((el) => el.innerText.trim()) |
| 11 | + .filter((text) => text !== ""); |
12 | 12 |
|
13 | 13 | // On image page, get data about gallery (image's position within gallery, next/prev image IDs), |
14 | 14 | // add arrow buttons to page, and register arrow keypress handlers, |
|
80 | 80 | async function handlePasteClick(objID, objType) { |
81 | 81 | // Parse tag list from comma delimited string. |
82 | 82 | const tagInput = await navigator.clipboard.readText(); |
83 | | - var inputTagList = tagInput.split(",") // do de-duplication later |
| 83 | + var inputTagList = tagInput.split(/\r?\n|\r|,/).map(s => s.trim()).filter((text) => text !== "") // do de-duplication later |
84 | 84 |
|
85 | 85 | // Get tags from input box and also add to tag list. |
86 | | - const existingTagList = getAllInnerText("label[for='tag_ids'] + div .react-select__multi-value__label") |
| 86 | + const existingTagList = getAllInnerText("label[for='tag_ids'] + div .react-select__multi-value__label"); |
87 | 87 |
|
88 | 88 | inputTagList = [...new Set([...inputTagList, ...existingTagList])].sort(); |
89 | 89 |
|
|
93 | 93 |
|
94 | 94 | // Search for tag ID for each tag. If exists, add to tag ID list. If not exists, create new tag and add to tag ID list. |
95 | 95 | for (const inputTag of inputTagList) { |
96 | | - const tagID = await getTagByName(inputTag.trim()); |
| 96 | + const tagID = await getTagByName(inputTag); |
97 | 97 | if (tagID && tagID.length) { |
98 | 98 | existingTags.push(inputTag); |
99 | 99 | tagUpdateList.push(tagID[0]); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 |
|
105 | | - |
106 | 105 | if (pluginSettings.requireConfirmation) { |
107 | | - |
108 | 106 | const missingTagsStr = missingTags.join(", "); |
109 | 107 | const existingTagsStr = existingTags.join(", "); |
110 | 108 | const msg = pluginSettings.createIfNotExists |
|
134 | 132 | window.location.reload(); |
135 | 133 | } |
136 | 134 |
|
137 | | - // *** Utility Functions *** |
138 | | - |
139 | 135 | // *** GQL Calls *** |
140 | 136 |
|
141 | 137 | // Update Object by ID, new tags list, and GQL mutation name. |
|
0 commit comments