diff --git a/src/items.js b/src/items.js index 8d03e6c..a3ee9d7 100644 --- a/src/items.js +++ b/src/items.js @@ -33,13 +33,24 @@ export default { Zotero.debug(operation, tags); let updateCount = 0; for (let i = 0; i < tags.length; ++i) { - if (operation === "add" && !item.hasTag(tags[i])) { + const expTagRegex = /^('|"|`)(.+)\[(.+)\]\1$/; + let isCondition = true; + if (expTagRegex.test(tags[i])) { + let [tag, condition_tag] = tags[i].match(expTagRegex).slice(2); + tags[i] = tag; + if (condition_tag.startsWith("!")) { + isCondition = !item.hasTag(condition_tag.slice(1)); + } else { + isCondition = item.hasTag(condition_tag); + } + } + if (operation === "add" && !item.hasTag(tags[i]) && isCondition) { item.addTag(tags[i], userTag ? 0 : 1); updateCount += 1; - } else if (operation === "remove" && item.hasTag(tags[i])) { + } else if (operation === "remove" && item.hasTag(tags[i]) && isCondition) { item.removeTag(tags[i]); updateCount += 1; - } else if (operation === "change") { + } else if (operation === "change" && isCondition) { if (item.hasTag(tags[i])) { item.removeTag(tags[i]); } else {