Make automatically uncheck the import of duplicate items

Execute the following code using the browser console

// 获取所有行
document.querySelectorAll('tr').forEach(row => {
  // 检查单元格文本内容并取消复选框勾选
  if (row.textContent.includes("具有此标题的条目已存在。")) {
    // 获取复选框并取消勾选
    row.querySelector('input[type="checkbox"]').checked = false;
    // 移除复选框的选中样式
    row.querySelector('label.tc-checkbox').classList.remove('tc-checkbox-checked');
  }
});

But when I click the Import button and import, all the items that were batch unchecked with the javascript program are also imported. Is there anything I can improve

Any reply would be greatly appreciated

The problem is that your javascript code is changing the checkbox DOM elements, but not the underlying checkbox settings which are stored as fields named selection-tiddlertitle in the auto-generated $:/Import tiddler.

To deselect all existing tiddlers, try the following wikitext $button:

<$button> unselect existing
<$list filter="[{$:/Import}jsonindexes[tiddlers]is[tiddler]]" variable="tid">
   <$action-setfield $tiddler="$:/Import" $field={{{ [[selection-]addsuffix<tid>] }}} $value="unchecked"/>
</$list>
</$button>
  • Place the above into a separate tiddler
  • Invoke the “import” action (via drag-and-drop or the “Tools>Import” button in the sidebar to create the $:/Import tiddler.
  • Press the “unselect existing” button so that existing tiddlers in the $:/Import list will be deselected.
  • Continue with the import process

enjoy,
-e

4 Likes

Thanks a million, perfect operation, my technical god!!!

Eric beat me too it but it reminds me that the excluded titles get fields so I can exclude all and make search tools to filter before import. This can include test for existing, by prefix etc…

:nerd_face:

1 Like