diff --git a/src/background.js b/src/background.js index 45acdcd..800751a 100644 --- a/src/background.js +++ b/src/background.js @@ -76,6 +76,34 @@ function timeConverter(a){ return time; } +// Link copy formats +const URLS_WITH_TITLES = 0 +const URLS_ONLY = 1 +const URLS_ONLY_SPACE_SEPARATED = 2 +const TITLES_ONLY = 3 +const AS_LINK_HTML = 4 +const AS_LIST_LINK_HTML = 5 +const AS_MARKDOWN = 6 + +function formatLink({url, title}, copyFormat) { + switch(parseInt(copyFormat)) { + case URLS_WITH_TITLES: + return title+"\t"+url+"\n"; + case URLS_ONLY: + return url+"\n"; + case URLS_ONLY_SPACE_SEPARATED: + return url+" "; + case TITLES_ONLY: + return title+"\n"; + case AS_LINK_HTML: + return ''+title+"\n"; + case AS_LIST_LINK_HTML: + return '
  • '+title+"
  • \n"; + case AS_MARKDOWN: + return "["+title+"]("+url+")\n"; + } +} + function handleRequests(request, sender, callback){ switch(request.message) { case "activate": @@ -95,29 +123,10 @@ function handleRequests(request, sender, callback){ case "copy": var text = ""; for (let i = 0; i < request.urls.length; i++) { - switch(request.setting.options.copy) { - case "0": - text += request.urls[i].title+"\t"+request.urls[i].url+"\n"; - break; - case "1": - text += request.urls[i].url+"\n"; - break; - case "2": - text += request.urls[i].title+"\n"; - break; - case "3": - text += ''+request.urls[i].title+"\n"; - break; - case "4": - text += '
  • '+request.urls[i].title+"
  • \n"; - break; - case "5": - text += "["+request.urls[i].title+"]("+request.urls[i].url+")\n"; - break; - } + text += formatLink(request.urls[i], request.setting.options.copy); } - if(request.setting.options.copy == 4) { + if(request.setting.options.copy == AS_LIST_LINK_HTML) { text = "\n" } diff --git a/src/manifest.json b/src/manifest.json index a2b0fea..8897ea4 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Linkclump", - "version": "2.9.4", + "version": "2.9.5", "description": "Lets you open, copy or bookmark multiple links at the same time.", "background": { "scripts": ["settings_manager.js", "background.js"], diff --git a/src/pages/options.js b/src/pages/options.js index d92ed4f..4e9ba11 100644 --- a/src/pages/options.js +++ b/src/pages/options.js @@ -23,7 +23,7 @@ var config = { "copy": { "name": "copy format", "type": "selection", - "data": ["URLS with titles", "URLS only", "titles only", "as link HTML", "as list link HTML", "as Markdown"], + "data": ["URLS with titles", "URLS only", "URLS only space separated", "titles only", "as link HTML", "as list link HTML", "as Markdown"], "extra": "format of the links saved to the clipboard" }, "delay": {