Challenge accepted, welcome to the forum @epoxzk !
# popclip
name: SearchNreplacePRO
icon: Search filled X!
macos version: '10.15' # for String.replaceAll
description: Searches and replaces multiple terms
options:
- { identifier: Search, label: Search terms, type: string, description: Comma separated. }
- { identifier: Replace, label: Replacements, type: string, description: Comma separated. }
javascript: |
const search = popclip.options.Search.split(',')
const replace = popclip.options.Replace.split(',')
if (search.length !== replace.length) throw new Error('Unequal number of terms')
const zipped = search.map((k, i) => [k, replace[i]])
let text = popclip.input.text
for (const [s, r] of zipped) {
text = text.replaceAll(s, r)
}
popclip.pasteText(text)