Closed JelmerEvers closed 3 months ago
You pasted the script content two times
Ah sorry, I'm very new to this. Do I need to do something to address this?
When you paste the script into the action editor, you pasted it twice by accident. You can manually remove the duplication part, or delete all and then paste again.
I've cleared the original Debug-Output. And copy-pasted the new log after I clicked 'create book section'
Oh, I mean you pasted twice when you add this script. Not related to the debug output here. You could clear the script in the settings of the plugin and paste from the original post again.
That did it... Sorry for the inconvenience and thanks for all the help!
Is there an existing issue for this?
Are you using the latest Zotero and the latest plugin?
Environment
Describe the bug
I get the following error using script in 'Create book section from annotation #204' after clicking the right click menu option 'Create book section' (description for script action) in annotation menu.
Error message: Scripterror redeclaration of const zoteropane'
Debug Output
(3)(+0028749): Running /usr/bin/sw_vers '-productVersion'
(3)(+0014382): [Actions and Tags for Zotero] Script Error {}
(4)(+0000001): Beginning DB transaction PHbOnnft
(4)(+0000001): Committed DB transaction PHbOnnft
(3)(+0000001): [Actions and Tags for Zotero] applyAction {"event":0,"operation":4,"data":"/*\n Create book section from annotation.\n @author windingwind\n @usage \n @link https://github.com/windingwind/zotero-actions-tags/discussions/204\n @see https://github.com/windingwind/zotero-actions-tags/discussions/181\n */\nif (!item) return;\n\nif (!item.isAnnotation()) return \"Not an annotation\";\n\nconst ZoteroPane = require(\"ZoteroPane\");\n\nconst topItem = Zotero.Items.getTopLevel([item])[0];\n\nZoteroPane.selectItem(topItem.id);\n\nlet section;\n\ntry {\n section = await ZoteroPane.duplicateAndConvertSelectedItem();\n if (!section) {\n return \"Failed to create book section\";\n }\n} catch (e) {\n return e;\n}\n\nsection.setField(\"title\", item.annotationComment || item.annotationText || \"\");\n\nconst link = getOpenPDFURL(item);\nlink && section.setField(\"url\", link);\nawait section.saveTx();\n\nreturn \"Successfully created book section\";\n\nfunction getOpenPDFURL(annotationItem) {\n const libraryID = annotationItem.libraryID;\n const library = Zotero.Libraries.get(libraryID);\n if (!library) {\n return;\n }\n let link =
zotero://open-pdf/
;\n if (library.libraryType === \"user\") {\n link +=library/items/${annotationItem.parentItem?.key}?
;\n } else if (library.libraryType === \"group\") {\n link +=groups/${library.id}/items/${annotationItem.parentItem?.key}?
;\n } else {\n return \"\";\n }\n let pageIndex = 1;\n try {\n pageIndex = JSON.parse(annotationItem.annotationPosition).pageIndex + 1;\n } catch (e) {\n Zotero.warn(e);\n }\n link +=page=${pageIndex}&annotation=${annotationItem.key}
;\n return link;","shortcut":"","enabled":true,"menu":"Create Book Section","name":"Create Book Section","showInMenu":{"item":false,"collection":false,"tools":false,"reader":false,"readerAnnotation":true}} {"itemIDs":[9141],"triggerType":"menu"}(3)(+0000004): [Actions and Tags for Zotero] Script Error {}
(4)(+0000000): Beginning DB transaction JGKzbpnW
(4)(+0000001): Item 9141 has not changed
(4)(+0000000): Committed DB transaction JGKzbpnW
(3)(+0000001): [Actions and Tags for Zotero] applyAction {"event":0,"operation":4,"data":"/*\n Create book section from annotation.\n @author windingwind\n @usage \n @link https://github.com/windingwind/zotero-actions-tags/discussions/204\n @see https://github.com/windingwind/zotero-actions-tags/discussions/181\n */\nif (!item) return;\n\nif (!item.isAnnotation()) return \"Not an annotation\";\n\nconst ZoteroPane = require(\"ZoteroPane\");\n\nconst topItem = Zotero.Items.getTopLevel([item])[0];\n\nZoteroPane.selectItem(topItem.id);\n\nlet section;\n\ntry {\n section = await ZoteroPane.duplicateAndConvertSelectedItem();\n if (!section) {\n return \"Failed to create book section\";\n }\n} catch (e) {\n return e;\n}\n\nsection.setField(\"title\", item.annotationComment || item.annotationText || \"\");\n\nconst link = getOpenPDFURL(item);\nlink && section.setField(\"url\", link);\nawait section.saveTx();\n\nreturn \"Successfully created book section\";\n\nfunction getOpenPDFURL(annotationItem) {\n const libraryID = annotationItem.libraryID;\n const library = Zotero.Libraries.get(libraryID);\n if (!library) {\n return;\n }\n let link =
zotero://open-pdf/
;\n if (library.libraryType === \"user\") {\n link +=library/items/${annotationItem.parentItem?.key}?
;\n } else if (library.libraryType === \"group\") {\n link +=groups/${library.id}/items/${annotationItem.parentItem?.key}?
;\n } else {\n return \"\";\n }\n let pageIndex = 1;\n try {\n pageIndex = JSON.parse(annotationItem.annotationPosition).pageIndex + 1;\n } catch (e) {\n Zotero.warn(e);\n }\n link +=page=${pageIndex}&annotation=${annotationItem.key}
;\n return link;","shortcut":"","enabled":true,"menu":"Create Book Section","name":"Create Book Section","showInMenu":{"item":false,"collection":false,"tools":false,"reader":false,"readerAnnotation":true}} {"itemID":9141,"triggerType":"menu"}Anything else?
No response