From f45bb60d78f75df89136ad6f25c799bc85be7cd7 Mon Sep 17 00:00:00 2001 From: WeedLordVegeta420 <81525421+WeedLordVegeta420@users.noreply.github.com> Date: Mon, 2 Jun 2025 13:40:08 -0400 Subject: [PATCH] [tagCopyPaste] Add newline as list delimiter. Trim all input. Update README. (#572) --- plugins/tagCopyPaste/README.md | 8 +++++--- plugins/tagCopyPaste/tagCopyPaste.js | 14 +++++--------- plugins/tagCopyPaste/tagCopyPaste.yml | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/tagCopyPaste/README.md b/plugins/tagCopyPaste/README.md index 596b53b..6a5189d 100644 --- a/plugins/tagCopyPaste/README.md +++ b/plugins/tagCopyPaste/README.md @@ -2,11 +2,13 @@ https://discourse.stashapp.cc/t/tagcopypaste/1858 -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. +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. -The Copy button will create a comma delimited list of all currently entered tags and put this on your clipboard. +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. -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. +Copying will create a comma delimited list of all currently entered tags and put this on your clipboard. + +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. **Note**: This plugin will prompt you to grant access to the clipboard. This must be granted in order for this plugin to work. diff --git a/plugins/tagCopyPaste/tagCopyPaste.js b/plugins/tagCopyPaste/tagCopyPaste.js index 33975ef..69a06a1 100644 --- a/plugins/tagCopyPaste/tagCopyPaste.js +++ b/plugins/tagCopyPaste/tagCopyPaste.js @@ -7,8 +7,8 @@ // helper function to get the innerText of all elements matching a selector const getAllInnerText = (selector) => Array.from(document.querySelectorAll(selector)) - .map((el) => el.innerText) - .filter((text) => text.trim() !== ""); + .map((el) => el.innerText.trim()) + .filter((text) => text !== ""); // On image page, get data about gallery (image's position within gallery, next/prev image IDs), // add arrow buttons to page, and register arrow keypress handlers, @@ -80,10 +80,10 @@ async function handlePasteClick(objID, objType) { // Parse tag list from comma delimited string. const tagInput = await navigator.clipboard.readText(); - var inputTagList = tagInput.split(",") // do de-duplication later + var inputTagList = tagInput.split(/\r?\n|\r|,/).map(s => s.trim()).filter((text) => text !== "") // do de-duplication later // Get tags from input box and also add to tag list. - const existingTagList = getAllInnerText("label[for='tag_ids'] + div .react-select__multi-value__label") + const existingTagList = getAllInnerText("label[for='tag_ids'] + div .react-select__multi-value__label"); inputTagList = [...new Set([...inputTagList, ...existingTagList])].sort(); @@ -93,7 +93,7 @@ // 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. for (const inputTag of inputTagList) { - const tagID = await getTagByName(inputTag.trim()); + const tagID = await getTagByName(inputTag); if (tagID && tagID.length) { existingTags.push(inputTag); tagUpdateList.push(tagID[0]); @@ -102,9 +102,7 @@ } } - if (pluginSettings.requireConfirmation) { - const missingTagsStr = missingTags.join(", "); const existingTagsStr = existingTags.join(", "); const msg = pluginSettings.createIfNotExists @@ -134,8 +132,6 @@ window.location.reload(); } - // *** Utility Functions *** - // *** GQL Calls *** // Update Object by ID, new tags list, and GQL mutation name. diff --git a/plugins/tagCopyPaste/tagCopyPaste.yml b/plugins/tagCopyPaste/tagCopyPaste.yml index 06ee8de..059c647 100644 --- a/plugins/tagCopyPaste/tagCopyPaste.yml +++ b/plugins/tagCopyPaste/tagCopyPaste.yml @@ -1,7 +1,7 @@ name: tagCopyPaste # requires: CommunityScriptsUILibrary description: Adds Copy/Paste buttons to Tags field. -version: 0.2 +version: 0.3 settings: createIfNotExists: displayName: Create If Not Exists