Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 事件不起作用 #441

Closed
2 tasks done
Sinoftj opened this issue Dec 21, 2024 · 1 comment
Closed
2 tasks done

[Bug] 事件不起作用 #441

Sinoftj opened this issue Dec 21, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Sinoftj
Copy link

Sinoftj commented Dec 21, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest Zotero and the latest plugin?

  • I have confirmed I'm using the latest Zotero and the latest plugin

Environment

  • OS: Mac
  • Zotero Version: 7.0.11
  • Plugin Version:2.0.6

Describe the bug

我使用的一些代码,为什么在一些事件下不能自动执行呢?比如下面的代码,我希望在新建条目的时候自动执行,但是不可以,只能自己手动:

// 确保 items 变量可用,并且包含条目
if (items?.length > 0) {
// 定义 publicationTitle 与缩写的映射(不区分大小写)
const titleToAbbreviation = {
"academy of management journal": "AMJ",
"journal of advertising": "JA",
"journal of marketing": "JMar",
"journal of consumer psychology": "JCP",
"information systems research": "ISR",
"journal of consumer research": "JCR",
"journal of management": "JMan",
"journal of marketing research": "JMR",
"journal of the academy of marketing science": "JAMS",
"management science": "ManS",
"marketing science": "MarS",
"annual review of psychology": "ARP",
"international journal of information management": "IJIM",
"academy of management review": "AMR",
"psychological bulletin": "PB",
"american economic review": "AER",
"journal of financial economics": "JFE",
"journal of product innovation management": "JPIM",
"annual review of sociology": "ARS",
"journal of service research": "JSR",
"annals of tourism research": "ATR",
"journal of retailing": "JR",
"journal of travel research": "JTR",
"tourism management": "TM",
"journal of political economy": "JPE",
"production and operations management": "POM",
"journal of economic perspectives": "JEP",
"journal of personality and social psychology": "JPSP",
"international journal of research in marketing": "IJRM",
"journal of management information systems": "JMIS",
"psychological review": "PR",
"organization science": "OS",
"psychological science": "PS",
"organizational behavior and human decision processes": "OBHFP",
"current directions in psychological science": "CDPS",
"mis quarterly": "MIS",

// 新添加的出版标题和缩写
"journal of the association for information systems": "JAIS",
"european journal of information systems": "EJIS",
"information systems journal": "ISJ",
"journal of information technology": "JIT",
"journal of strategic information systems": "JSIS",
"international journal of advertising": "IJA"

};

// 遍历所有选中的条目
items.forEach(item => {
// 获取条目的 "publicationTitle" 字段
const publicationTitle = item.getField('publicationTitle');

// 转换为小写,以便进行不区分大小写的比较
const lowerCaseTitle = publicationTitle ? publicationTitle.toLowerCase() : '';

// 检查 publicationTitle 是否有效
if (lowerCaseTitle) {
  // 以 ACM、Nature 或 Science 开头的标题
  if (lowerCaseTitle.startsWith("acm")) {
    item.addTag("ACM");
  } else if (lowerCaseTitle.startsWith("nature")) {
    item.addTag("Nature");
  } else if (lowerCaseTitle.startsWith("science")) {
    item.addTag("Science");
  } 
  // 检查是否在已知 publicationTitle 的映射中
  else if (titleToAbbreviation[lowerCaseTitle]) {
    // 获取缩写
    const tag = titleToAbbreviation[lowerCaseTitle];
    item.addTag(tag);
  }
  // 如果不包含在我们已知的 title 中,则不添加任何标签
}

});
}

Debug Output

report.txt

Anything else?

No response

@Sinoftj Sinoftj added the bug Something isn't working label Dec 21, 2024
@Sinoftj Sinoftj closed this as completed Dec 22, 2024
@Sinoftj Sinoftj reopened this Dec 22, 2024
@Sinoftj
Copy link
Author

Sinoftj commented Dec 22, 2024

已解决:
const Zotero = require("Zotero");

(async function() {
try {
// Log the trigger type for debugging purposes
Zotero.logError(Trigger type: ${triggerType});

    // 检查触发是否由单个条目创建
    if (!item) {
        Zotero.logError("No item was provided. Ensure the script is triggered by createItem event.");
        return;
    }

    // 定义 publicationTitle 与缩写的映射(不区分大小写)
    const titleToAbbreviation = {
        "academy of management journal": "AMJ",
        "journal of advertising": "JA",
        "journal of marketing": "JMar",
        "journal of consumer psychology": "JCP",
        "information systems research": "ISR",
        "journal of consumer research": "JCR",
        "journal of management": "JMan",
        "journal of marketing research": "JMR",
        "journal of the academy of marketing science": "JAMS",
        "management science": "ManS",
        "marketing science": "MarS",
        "annual review of psychology": "ARP",
        "international journal of information management": "IJIM",
        "academy of management review": "AMR",
        "psychological bulletin": "PB",
        "american economic review": "AER",
        "journal of financial economics": "JFE",
        "journal of product innovation management": "JPIM",
        "annual review of sociology": "ARS",
        "journal of service research": "JSR",
        "annals of tourism research": "ATR",
        "journal of retailing": "JR",
        "journal of travel research": "JTR",
        "tourism management": "TM",
        "journal of political economy": "JPE",
        "production and operations management": "POM",
        "journal of economic perspectives": "JEP",
        "journal of personality and social psychology": "JPSP",
        "international journal of research in marketing": "IJRM",
        "journal of management information systems": "JMIS",
        "psychological review": "PR",
        "organization science": "OS",
        "psychological science": "PS",
        "organizational behavior and human decision processes": "OBHFP",
        "current directions in psychological science": "CDPS",
        "mis quarterly": "MIS",
        "journal of the association for information systems": "JAIS",
        "european journal of information systems": "EJIS",
        "information systems journal": "ISJ",
        "journal of information technology": "JIT",
        "journal of strategic information systems": "JSIS",
        "international journal of advertising": "IJA"
    };

    // 获取条目的 "publicationTitle" 字段
    const publicationTitle = item.getField('publicationTitle');
    
    // 转换为小写,以便进行不区分大小写的比较
    const lowerCaseTitle = publicationTitle ? publicationTitle.toLowerCase() : '';

    // 检查 publicationTitle 是否有效
    if (lowerCaseTitle) {
        // 以 ACM、Nature 或 Science 开头的标题
        if (lowerCaseTitle.startsWith("acm")) {
            item.addTag("ACM");
        } else if (lowerCaseTitle.startsWith("nature")) {
            item.addTag("Nature");
        } else if (lowerCaseTitle.startsWith("science")) {
            item.addTag("Science");
        } 
        // 检查是否在已知 publicationTitle 的映射中
        else if (titleToAbbreviation[lowerCaseTitle]) {
            // 获取缩写
            const tag = titleToAbbreviation[lowerCaseTitle];
            item.addTag(tag);
        } else {
            // 未匹配到已知的 publicationTitle
            Zotero.logError(`Unrecognized publication title: "${publicationTitle}"`);
        }
    } else {
        Zotero.logError("No publication title found for the item.");
    }

} catch (error) {
    // 记录脚本运行中可能的错误
    Zotero.logError(`Error in createItem script: ${error.message}`);
}

})();

// // 确保 items 变量可用,并且包含条目
// if (items?.length > 0) {
// // 定义 publicationTitle 与缩写的映射(不区分大小写)
// const titleToAbbreviation = {
// "academy of management journal": "AMJ",
// "journal of advertising": "JA",
// "journal of marketing": "JMar",
// "journal of consumer psychology": "JCP",
// "information systems research": "ISR",
// "journal of consumer research": "JCR",
// "journal of management": "JMan",
// "journal of marketing research": "JMR",
// "journal of the academy of marketing science": "JAMS",
// "management science": "ManS",
// "marketing science": "MarS",
// "annual review of psychology": "ARP",
// "international journal of information management": "IJIM",
// "academy of management review": "AMR",
// "psychological bulletin": "PB",
// "american economic review": "AER",
// "journal of financial economics": "JFE",
// "journal of product innovation management": "JPIM",
// "annual review of sociology": "ARS",
// "journal of service research": "JSR",
// "annals of tourism research": "ATR",
// "journal of retailing": "JR",
// "journal of travel research": "JTR",
// "tourism management": "TM",
// "journal of political economy": "JPE",
// "production and operations management": "POM",
// "journal of economic perspectives": "JEP",
// "journal of personality and social psychology": "JPSP",
// "international journal of research in marketing": "IJRM",
// "journal of management information systems": "JMIS",
// "psychological review": "PR",
// "organization science": "OS",
// "psychological science": "PS",
// "organizational behavior and human decision processes": "OBHFP",
// "current directions in psychological science": "CDPS",
// "mis quarterly": "MIS",
// "journal of the association for information systems": "JAIS",
// "european journal of information systems": "EJIS",
// "information systems journal": "ISJ",
// "journal of information technology": "JIT",
// "journal of strategic information systems": "JSIS",
// "international journal of advertising": "IJA"
// };

// // 遍历所有选中的条目
// items.forEach(item => {
// // 获取条目的 "publicationTitle" 字段
// const publicationTitle = item.getField('publicationTitle');

// // 转换为小写,以便进行不区分大小写的比较
// const lowerCaseTitle = publicationTitle ? publicationTitle.toLowerCase() : '';

// // 检查 publicationTitle 是否有效
// if (lowerCaseTitle) {
// // 以 ACM、Nature 或 Science 开头的标题
// if (lowerCaseTitle.startsWith("acm")) {
// item.addTag("ACM");
// } else if (lowerCaseTitle.startsWith("nature")) {
// item.addTag("Nature");
// } else if (lowerCaseTitle.startsWith("science")) {
// item.addTag("Science");
// }
// // 检查是否在已知 publicationTitle 的映射中
// else if (titleToAbbreviation[lowerCaseTitle]) {
// // 获取缩写
// const tag = titleToAbbreviation[lowerCaseTitle];
// item.addTag(tag);
// }
// // 如果不包含在我们已知的 title 中,则不添加任何标签
// }
// });
// }

@Sinoftj Sinoftj closed this as completed Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants