Skip to content

Commit

Permalink
Merge pull request #58 from MuiseDestiny/master
Browse files Browse the repository at this point in the history
add: tag rule if/if not
  • Loading branch information
windingwind committed Nov 24, 2022
2 parents dfc3f10 + bec1053 commit 1d8d015
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1d8d015

Please sign in to comment.