Skip to content

Commit 2057236

Browse files
authored
Add removeDuplicates Option to Copy Selected Links (#94)
* Add removeDuplicates Option to Copy Selected Links * Update JSDoc
1 parent 2f8e913 commit 2057236

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/js/service-worker.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ async function onClicked(ctx, tab) {
116116
target: { tabId: tab.id },
117117
files: ['/js/extract.js'],
118118
})
119-
await injectFunction(copySelectionLinks, [])
119+
const { options } = await chrome.storage.sync.get(['options'])
120+
await injectFunction(copySelectionLinks, [options.removeDuplicates])
120121
} else {
121122
console.error(`Unknown ctx.menuItemId: ${ctx.menuItemId}`)
122123
}
@@ -319,15 +320,19 @@ function copyActiveElementText(ctx) {
319320
/**
320321
* Copy All Selected Links
321322
* @function copySelectionLinks
323+
* @param {Boolean} removeDuplicates
322324
*/
323-
function copySelectionLinks() {
324-
// console.debug('copySelectionLinks')
325+
function copySelectionLinks(removeDuplicates) {
326+
// console.debug('copySelectionLinks:', removeDuplicates)
325327
const links = extractSelection()
326328
// console.debug('links:', links)
327-
const results = []
329+
let results = []
328330
for (const link of links) {
329331
results.push(link.href)
330332
}
333+
if (removeDuplicates) {
334+
results = [...new Set(results)]
335+
}
331336
// console.debug('results:', results)
332337
const text = results.join('\n')
333338
console.debug('text:', text)

0 commit comments

Comments
 (0)