Skip to content

Commit

Permalink
合并条目下所有PDF文件和注释
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlb0224 committed Jul 22, 2024
1 parent 49bfb7c commit 82ad3d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 40 deletions.
15 changes: 6 additions & 9 deletions src/action/action-annotation-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,18 @@ export function init() {
async function getHtml() {
const selectedItems = ZoteroPane.getSelectedItems();
const item = selectedItems[0];
//if (!item) return null; // 提前退出,如果没有选中的项
//@ts-ignore isEPUBAttachment
//if (!item) return null; // 提前退出,如果没有选中的项
const attachments = Zotero.Items.get(item.getAttachments()).filter(
(i) =>
i.isPDFAttachment() ||
i.isSnapshotAttachment() ||
// @ts-ignore isEPUBAttachment
i.isEPUBAttachment() ||
i.isWebAttachment(),
);
let res = `<h1>${item.getField("title")}</h1>`;
const allAnnotations = []; // 在函数作用域内声明数组来收集所有注释
for (const attachment of attachments) {
//@ts-ignore getFilename

res += `<h2>@@@${attachment.getFilename()}</h2>`;
const annotations = attachment.getAnnotations();
allAnnotations.push(...annotations); // 使用扩展运算符将annotations数组的每个元素添加到allAnnotations数组中
Expand All @@ -203,13 +201,12 @@ export function init() {
annotationObj.attachmentItemID = annotationItem.parentItem?.id; // @ts-ignore 111
delete annotationObj.key;
for (const key in annotationObj) {
// @ts-ignore 111

annotationObj[key] = annotationObj[key] || "";
} // @ts-ignore 111
}
annotationObj.tags = annotationObj.tags || [];
return annotationObj;
} catch (e2) {
// @ts-ignore 111
Zotero.logError(e2);
return null;
}
Expand All @@ -226,9 +223,9 @@ export function init() {
const annotationJSONList = [] as _ZoteroTypes.Annotations.AnnotationJson[];
for (const ann of annotations) {
const annJson = await parseAnnotationJSON(ann);
//@ts-ignore11111

if (options.ignoreComment && annJson?.comment) {
//@ts-ignore11111

annJson.comment = "";
}
if (annJson) annotationJSONList.push(annJson);
Expand Down
38 changes: 19 additions & 19 deletions src/modules/annotationsToNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function buildMenu(collectionOrItem: "collection" | "item") {
{
//粘贴pdf注释
tag: "menuitem",
label: "粘贴条目下pdf注释",
label: "粘贴条目下pdf注释-用作者年份标题识别不同的条目",
icon: iconBaseUrl + "favicon.png",
commandListener: async (ev: Event) => {
const items = await getSelectedItems(collectionOrItem);
Expand Down Expand Up @@ -217,7 +217,7 @@ function buildMenu(collectionOrItem: "collection" | "item") {
{
//相同PDF合并,注释合并
tag: "menuitem",
label: "相同PDF合并,注释合并",
label: "合并条目下所有PDF文件和注释",
icon: iconBaseUrl + "favicon.png",
commandListener: async (ev: Event) => {
const items = await getSelectedItems(collectionOrItem);
Expand Down Expand Up @@ -1836,24 +1836,24 @@ function createActionTag(div: HTMLElement | undefined, action: () => void | unde
// },
action
? {
tag: "button",
namespace: "html",
properties: { textContent: "确定生成" },
// styles: {
// padding: "6px",
// background: "#f99",
// margin: "1px",
// },
listeners: [
{
type: "click",
listener: (ev: any) => {
stopPropagation(ev);
action();
},
tag: "button",
namespace: "html",
properties: { textContent: "确定生成" },
// styles: {
// padding: "6px",
// background: "#f99",
// margin: "1px",
// },
listeners: [
{
type: "click",
listener: (ev: any) => {
stopPropagation(ev);
action();
},
],
}
},
],
}
: { tag: "span" },
...others,
];
Expand Down
24 changes: 12 additions & 12 deletions src/utils/zzlb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ const memAllTagsInLibraryAsync = memoize(async () => {
);
const itemTags = getPref("item-tags")
? items.flatMap((f) =>
f.getTags().map((a) => ({
tag: a.tag,
type: a.type,
dateModified: f.dateModified,
})),
)
f.getTags().map((a) => ({
tag: a.tag,
type: a.type,
dateModified: f.dateModified,
})),
)
: [];
return groupBy([...tags, ...itemTags], (t14) => t14.tag);
});
Expand Down Expand Up @@ -409,7 +409,7 @@ export async function openAnnotation(itemOrKeyOrId: Zotero.Item | string | numbe
}
}

export async function injectCSSToReader() {}
export async function injectCSSToReader() { }

export const memSVG = memoize(
async (href) => await getFileContent(href),
Expand Down Expand Up @@ -445,11 +445,11 @@ export async function injectCSS(doc: Document | HTMLDivElement, filename: string
ignoreIfExists: true,
},
doc.querySelector("linkset") ||
doc.querySelector("head") ||
doc.querySelector("body") ||
doc.querySelector("div") ||
doc.children[0] ||
doc,
doc.querySelector("head") ||
doc.querySelector("body") ||
doc.querySelector("div") ||
doc.children[0] ||
doc,
);
// ztoolkit.log("加载css", d);
}
Expand Down

0 comments on commit 82ad3d5

Please sign in to comment.