Skip to content

Instantly share code, notes, and snippets.

@sarkrui
Created October 24, 2023 13:58
Show Gist options
  • Save sarkrui/912dbce7ddccb412ceea85c9253560f9 to your computer and use it in GitHub Desktop.
Save sarkrui/912dbce7ddccb412ceea85c9253560f9 to your computer and use it in GitHub Desktop.
Remove Duplicates and Collections
(async () => {
var dupPane = Zotero.getZoteroPanes()[0];
var duplicatesCollection = dupPane.getSelectedCollection();
for (var i = 0; i < 8000; i++) {
await new Promise(r => setTimeout(r, 200));
let selectedItems = dupPane.getSelectedItems();
// Filter selected items by their type (assuming first selected item is representative)
let filteredItems = selectedItems.filter(item => item.itemTypeID === selectedItems[0].itemTypeID);
// Set the filtered items as the selected items in the pane
dupPane.selectItems(filteredItems.map(item => item.id));
// Merge duplicates
if (filteredItems.length > 1) {
dupPane.mergeSelectedItems();
await Zotero.Duplicates_Pane.merge();
}
// Remove item from collection
if (duplicatesCollection) {
let selectedItem = dupPane.getSelectedItems()[0];
if (selectedItem) {
await duplicatesCollection.removeItem(selectedItem.id);
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment