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

插件多个actions行的脚本数据会相互覆盖 #141

Closed
yuzixieshouhuajiaqi opened this issue Sep 23, 2023 · 10 comments
Closed

插件多个actions行的脚本数据会相互覆盖 #141

yuzixieshouhuajiaqi opened this issue Sep 23, 2023 · 10 comments

Comments

@yuzixieshouhuajiaqi
Copy link

没摸清具体规律,有时候一个动作运行后,就把临近动作行的脚本数据覆盖了

@yuzixieshouhuajiaqi
Copy link
Author

摸清了一种发生情况,只要某个动作行启用被关闭后,其脚本数据就会自动被临近动作行的脚本数据覆盖

@windingwind
Copy link
Owner

请提供可复现的操作步骤

@yuzixieshouhuajiaqi
Copy link
Author

步骤:
1.添加两行带有不同脚本数据的不同动作
2.将上面一行的动作启用按钮关闭
3.上面一行动作的脚本数据将会自动变成和下面一行动作的脚本数据一模一样

@yuzixieshouhuajiaqi
Copy link
Author

步骤: 1.添加两行带有不同脚本数据的不同动作 2.将上面一行的动作启用按钮关闭 3.上面一行动作的脚本数据将会自动变成和下面一行动作的脚本数据一模一样

比如动作1
// PDF深度查询
// @author Polygon
// @link #124
// @Usage Menu Label=PDF深度查询
const ZoteroPane = require("ZoteroPane")
const Zotero = require("Zotero")
let DOI = ""
if (!item.isRegularItem()) {
return "不支持该类型"
} else if ((DOI = item.getField("DOI")).length == 0) {
return "无DOI不支持查询"
}
// scihub start
let parser = new DOMParser()
let scihubUrl = "https://sci-hub.se"
let url = ${scihubUrl}/${DOI}
let resp = await Zotero.HTTP.request("GET", url)
let htmlDoc = parser.parseFromString(resp.responseText, "text/html")
let pdfTag = htmlDoc.querySelector("#pdf")
if (pdfTag) {
let pdfUrl = pdfTag.getAttribute("src")
if (pdfUrl.startsWith("//")) {
pdfUrl = "https:" + pdfUrl
} else if (pdfUrl.startsWith("/")) {
pdfUrl = scihubUrl + pdfUrl
}
let importOptions = {
libraryID: item.libraryID,
url: pdfUrl,
parentItemID: item.id,
title: "PDF_From_Scihub",
fileBaseName: "Full_Text_by_Action",
contentType: 'application/pdf',
referrer: url,
}
// result is an attachment item
let result = await Zotero.Attachments.importFromURL(importOptions)
if (result.key) {
return "SciHub 下载成功"
}
}

// open-access start if pdf can not found in scihub
Zotero.launchURL(
https://www.open-access.xyz/?doi=${DOI}
)
return "查询中..."

动作2
const window = require("window");
let path = await item.getFilePathAsync();
let exePath = Zotero.Prefs.get("extensions.actionsTags.mypdfapp", true);
if (!exePath) {
exePath = window.prompt("输入打开PDF的exe程序路径");
Zotero.Prefs.set("extensions.actionsTags.mypdfapp", exePath, true);
}
// Example: exe path string in windows, C:\Program Files\Mozilla Firefox\firefox.exe
Zotero.launchFileWithApplication(path, exePath);
return "打开成功";

@yuzixieshouhuajiaqi
Copy link
Author

步骤: 1.添加两行带有不同脚本数据的不同动作 2.将上面一行的动作启用按钮关闭 3.上面一行动作的脚本数据将会自动变成和下面一行动作的脚本数据一模一样

比如动作1 // PDF深度查询 // @author Polygon // @link #124 // @Usage Menu Label=PDF深度查询 const ZoteroPane = require("ZoteroPane") const Zotero = require("Zotero") let DOI = "" if (!item.isRegularItem()) { return "不支持该类型" } else if ((DOI = item.getField("DOI")).length == 0) { return "无DOI不支持查询" } // scihub start let parser = new DOMParser() let scihubUrl = "https://sci-hub.se" let url = ${scihubUrl}/${DOI} let resp = await Zotero.HTTP.request("GET", url) let htmlDoc = parser.parseFromString(resp.responseText, "text/html") let pdfTag = htmlDoc.querySelector("#pdf") if (pdfTag) { let pdfUrl = pdfTag.getAttribute("src") if (pdfUrl.startsWith("//")) { pdfUrl = "https:" + pdfUrl } else if (pdfUrl.startsWith("/")) { pdfUrl = scihubUrl + pdfUrl } let importOptions = { libraryID: item.libraryID, url: pdfUrl, parentItemID: item.id, title: "PDF_From_Scihub", fileBaseName: "Full_Text_by_Action", contentType: 'application/pdf', referrer: url, } // result is an attachment item let result = await Zotero.Attachments.importFromURL(importOptions) if (result.key) { return "SciHub 下载成功" } }

// open-access start if pdf can not found in scihub Zotero.launchURL( https://www.open-access.xyz/?doi=${DOI} ) return "查询中..."

动作2 const window = require("window"); let path = await item.getFilePathAsync(); let exePath = Zotero.Prefs.get("extensions.actionsTags.mypdfapp", true); if (!exePath) { exePath = window.prompt("输入打开PDF的exe程序路径"); Zotero.Prefs.set("extensions.actionsTags.mypdfapp", exePath, true); } // Example: exe path string in windows, C:\Program Files\Mozilla Firefox\firefox.exe Zotero.launchFileWithApplication(path, exePath); return "打开成功";

image

@yuzixieshouhuajiaqi
Copy link
Author

大佬,还有这个标题关键词检测的脚本,总是时好时坏,成功添加标签的概率很低,不知道咋回事
// Auto-tag when keywords detected in title
// @author windingwind
// @link #119
// @Usage Replace the KEYWORDS and TAG_NAMES.
// @see #77
// @see #85

if (!item) {
return "[Conditional Tag] item is empty";
}

const KEYWORDS1 = ["meta", "Meta"];
const TAG_NAMES1 = ["♏"];

if (KEYWORDS1.some(kwd => item.getField("title").includes(kwd))) {
TAG_NAMES1.forEach(tag => item.addTag(tag));
return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS1} is tagged ${TAG_NAMES1};
}

const KEYWORDS2 = ["review", "Review"];
const TAG_NAMES2 = ["®"];

if (KEYWORDS2.some(kwd => item.getField("title").includes(kwd))) {
TAG_NAMES2.forEach(tag => item.addTag(tag));
return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS2} is tagged ${TAG_NAMES2};
}

const KEYWORDS3 = ["现状", "进展"];
const TAG_NAMES3 = ["®"];

if (KEYWORDS3.some(kwd => item.getField("title").includes(kwd))) {
TAG_NAMES3.forEach(tag => item.addTag(tag));
return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS3} is tagged ${TAG_NAMES3};
}

const KEYWORDS3 = ["case", "Case"];
const TAG_NAMES3 = ["©"];

if (KEYWORDS4.some(kwd => item.getField("title").includes(kwd))) {
TAG_NAMES4.forEach(tag => item.addTag(tag));
return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS4} is tagged ${TAG_NAMES4};
}

@yuzixieshouhuajiaqi
Copy link
Author

大佬,还有这个标题关键词检测的脚本,总是时好时坏,成功添加标签的概率很低,不知道咋回事 // Auto-tag when keywords detected in title // @author windingwind // @link #119 // @Usage Replace the KEYWORDS and TAG_NAMES. // @see #77 // @see #85

if (!item) { return "[Conditional Tag] item is empty"; }

const KEYWORDS1 = ["meta", "Meta"]; const TAG_NAMES1 = ["♏"];

if (KEYWORDS1.some(kwd => item.getField("title").includes(kwd))) { TAG_NAMES1.forEach(tag => item.addTag(tag)); return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS1} is tagged ${TAG_NAMES1}; }

const KEYWORDS2 = ["review", "Review"]; const TAG_NAMES2 = ["®"];

if (KEYWORDS2.some(kwd => item.getField("title").includes(kwd))) { TAG_NAMES2.forEach(tag => item.addTag(tag)); return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS2} is tagged ${TAG_NAMES2}; }

const KEYWORDS3 = ["现状", "进展"]; const TAG_NAMES3 = ["®"];

if (KEYWORDS3.some(kwd => item.getField("title").includes(kwd))) { TAG_NAMES3.forEach(tag => item.addTag(tag)); return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS3} is tagged ${TAG_NAMES3}; }

const KEYWORDS3 = ["case", "Case"]; const TAG_NAMES3 = ["©"];

if (KEYWORDS4.some(kwd => item.getField("title").includes(kwd))) { TAG_NAMES4.forEach(tag => item.addTag(tag)); return [Conditional Tag] item ${item.getField("title")} with keyword ${KEYWORDS4} is tagged ${TAG_NAMES4}; }

"review", "Review", "现状", "进展" 这几个关键词其实我想放到一起,后来发现放到一起,百分百失败,分开中英文关键词后,成功率30%左右

@yuzixieshouhuajiaqi
Copy link
Author

大佬,你这个插件的新功能潜力很大呀,有很多小功能可以扩展,就比如上面的根据标题关键词自动判断文献类型并加标签

@xjtusjtu
Copy link

步骤: 1.添加两行带有不同脚本数据的不同动作 2.将上面一行的动作启用按钮关闭 3.上面一行动作的脚本数据将会自动变成和下面一行动作的脚本数据一模一样

我也遇到了这个问题

@windingwind
Copy link
Owner

我无法复现。可否提供操作录屏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants