-
Notifications
You must be signed in to change notification settings - Fork 522
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
使用Pss-System.js(昨天添加的,感谢)保存报错 #340
Labels
bug
Something isn't working
Comments
@JHB-L 网站的 PDF 下载使用 POST 请求来获取文件,相关参数由网页自身维护(基本上,当你搜索出来的时候就在内部确定了),这些参数难以从外部获取。目前无法在 translator 中实现连同 PDF附件抓取,你只能手动下载PDF。 不过我注意到下载的PDF文件名有规律,基于此为你编写了实用的代码来导入这些手动下载的 PDF,使用步骤如下:
const debug = [];
// 设置下载目录
const downloadDir = "C:\\test\\";
debug.push(`use ${downloadDir} as root dir`);
const patents = ZoteroPane.getSelectedItems().filter(item => item.itemType == "patent");
let pdfs = [];
await Zotero.File.iterateDirectory(
downloadDir,
async (child) => {
if (!child.isDir && /\.pdf$/i.test(child.name)) {
pdfs.push(child);
}
}
);
for (const item of patents) {
const msg = [];
msg.push(`process item: ${item.getDisplayTitle()}`);
let patentNumber = item.getField("patentNumber");
if (!patentNumber || Zotero.Items.get(item.getAttachments()).some(attachment => attachment.isPDFAttachment())) {
msg.push(`skip.`);
continue;
};
for (pdf of pdfs) {
const basename = pdf.name.slice(0, -4);
const theSame = basename == patentNumber;
// 不要使用.includes(),否则文件名很短时可能导致意外的匹配
const include = new RegExp(`^${basename};\s?|;\s?${basename}$|;\s?${basename};\s?`).test(patentNumber);
msg.push(`patent number: ${patentNumber} = base name: ${basename}? ${theSame}`);
msg.push(`patent number: ${patentNumber} in base name: ${basename}? ${include}`);
if (theSame || include) {
await Zotero.Attachments.importFromFile({
file: pdf.path,
libraryID: item.libraryID,
parentItemID: item.id
});
pdfs = pdfs.filter(file => file != pdf);
msg.push( `add attachment: ${pdf.name}. `);
// 在下一行的前面输入两个“/”,即可避免匹配附件的同时删除本地的 PDF 文件
Zotero.File.pathToFile(pdf.path).remove(true);
msg.push( `remove file: ${pdf.path}. `);
break;
}
}
if (!Zotero.Items.get(item.getAttachments()).some(attachment => attachment.isPDFAttachment())) {
msg.push(`no attachment matched.`);
};
debug.push(msg.join("\n"));
};
return debug.join("\n\n"); |
@jiaojiaodubai 非常感谢 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你遇到了什么问题? [必填]
发生问题的链接 [必填]
国家知识产权局专利检索及分析系统
问题描述 [必填]
浏览器可识别条目,保存时报错
你的预期结果
可以保存相关条目及pdf附件
浏览器
自查清单
附件
Connector报错记录:
The text was updated successfully, but these errors were encountered: