Skip to content

Commit

Permalink
Merge pull request #236 from sullyj3/master
Browse files Browse the repository at this point in the history
Add new copy format: URLs only space separated
  • Loading branch information
benblack86 authored Apr 9, 2024
2 parents 331baa6 + 739e48c commit d10a43d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
51 changes: 30 additions & 21 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<a href="'+url+'">'+title+"</a>\n";
case AS_LIST_LINK_HTML:
return '<li><a href="'+url+'">'+title+"</a></li>\n";
case AS_MARKDOWN:
return "["+title+"]("+url+")\n";
}
}

function handleRequests(request, sender, callback){
switch(request.message) {
case "activate":
Expand All @@ -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 += '<a href="'+request.urls[i].url+'">'+request.urls[i].title+"</a>\n";
break;
case "4":
text += '<li><a href="'+request.urls[i].url+'">'+request.urls[i].title+"</a></li>\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 = "<ul>\n"+text+"</ul>\n"
}

Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion src/pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit d10a43d

Please sign in to comment.