Skip to content

Commit f45bb60

Browse files
[tagCopyPaste] Add newline as list delimiter. Trim all input. Update README. (#572)
1 parent 0f93008 commit f45bb60

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

plugins/tagCopyPaste/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
https://discourse.stashapp.cc/t/tagcopypaste/1858
44

5-
This plugin adds Copy and Paste buttons next to the Tags input field that allows for easier bulk adding and copying of tags, with the goal of making it easy to copy Tags between objects, bulk load manually created tag lists, or load tag lists copied from AI tagger output.
5+
This plugin adds Copy and Paste functionality to the Tags input field that allows for easier bulk adding and copying of tags, with the goal of making it easy to copy Tags between objects, bulk load manually created tag lists, or load tag lists copied from AI tagger output.
66

7-
The Copy button will create a comma delimited list of all currently entered tags and put this on your clipboard.
7+
Copy/Paste of Tags can be performed either with dedicated Copy/Paste buttons or by selecting the Tag input field and performing the typical CTRL+C/CTRL+V.
88

9-
The Paste button will check your current clipboard for a comma delimited string and add these as Tags, optionally creating any missing tags. Pasted tags will be checked against both primary Tag names and all aliases, comparisons are not case sensitive and allow "_" to be interpreted as a space.
9+
Copying will create a comma delimited list of all currently entered tags and put this on your clipboard.
10+
11+
Pasting will check your current clipboard for a comma and/or newline delimited string and add these as Tags, optionally creating any missing tags. Pasted tags will be checked against both primary Tag names and all aliases, comparisons are not case sensitive and allow "_" to be interpreted as a space.
1012

1113
**Note**: This plugin will prompt you to grant access to the clipboard. This must be granted in order for this plugin to work.
1214

plugins/tagCopyPaste/tagCopyPaste.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
// helper function to get the innerText of all elements matching a selector
99
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 !== "");
1212

1313
// On image page, get data about gallery (image's position within gallery, next/prev image IDs),
1414
// add arrow buttons to page, and register arrow keypress handlers,
@@ -80,10 +80,10 @@
8080
async function handlePasteClick(objID, objType) {
8181
// Parse tag list from comma delimited string.
8282
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
8484

8585
// 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");
8787

8888
inputTagList = [...new Set([...inputTagList, ...existingTagList])].sort();
8989

@@ -93,7 +93,7 @@
9393

9494
// 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.
9595
for (const inputTag of inputTagList) {
96-
const tagID = await getTagByName(inputTag.trim());
96+
const tagID = await getTagByName(inputTag);
9797
if (tagID && tagID.length) {
9898
existingTags.push(inputTag);
9999
tagUpdateList.push(tagID[0]);
@@ -102,9 +102,7 @@
102102
}
103103
}
104104

105-
106105
if (pluginSettings.requireConfirmation) {
107-
108106
const missingTagsStr = missingTags.join(", ");
109107
const existingTagsStr = existingTags.join(", ");
110108
const msg = pluginSettings.createIfNotExists
@@ -134,8 +132,6 @@
134132
window.location.reload();
135133
}
136134

137-
// *** Utility Functions ***
138-
139135
// *** GQL Calls ***
140136

141137
// Update Object by ID, new tags list, and GQL mutation name.

plugins/tagCopyPaste/tagCopyPaste.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: tagCopyPaste
22
# requires: CommunityScriptsUILibrary
33
description: Adds Copy/Paste buttons to Tags field.
4-
version: 0.2
4+
version: 0.3
55
settings:
66
createIfNotExists:
77
displayName: Create If Not Exists

0 commit comments

Comments
 (0)