Skip to content

Commit

Permalink
Define a function to create a link for a tab
Browse files Browse the repository at this point in the history
  • Loading branch information
satoryu committed Nov 12, 2022
1 parent 250e778 commit 8cfceb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writeTextToClipboard } from './src/clipboard.js'
import { createLinkForTab } from './src/link.js'

chrome.runtime.onInstalled.addListener(function () {
chrome.contextMenus.create({
Expand All @@ -8,7 +9,7 @@ chrome.runtime.onInstalled.addListener(function () {
})

chrome.contextMenus.onClicked.addListener(function (_, tab) {
const text = `[${tab.title} ${tab.url}]`
const text = createLinkForTab(tab)

chrome.scripting.executeScript({
target: { tabId: tab.id },
Expand Down
14 changes: 8 additions & 6 deletions src/link.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
function createLinksForTabs(tabs) {
return tabs.map(tab => {
let title = tab.title.replaceAll(/[\[\]]/g, '').replaceAll(/`(.*)`/g, '$1')
function createLinkForTab(tab) {
const title = tab.title.replaceAll(/[\[\]]/g, '').replaceAll(/`(.*)`/g, '$1')

return ` [${tab.url} ${title}]`
}

return ` [${tab.url} ${title}]`
}).join("\n")
function createLinksForTabs(tabs) {
return tabs.map(createLinkForTab).join("\n")
}

export { createLinksForTabs }
export { createLinksForTabs, createLinkForTab }

0 comments on commit 8cfceb8

Please sign in to comment.