-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontent.js
More file actions
31 lines (31 loc) · 1.15 KB
/
Copy pathcontent.js
File metadata and controls
31 lines (31 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
var data = '';
if(request == 'getAllLinks') {
var theLinks = document.links;
for(var i=0; i<theLinks.length; i++) {
if(theLinks[i].href.indexOf('javascript:') == -1) data += theLinks[i].href + '\n';
}
} else if(request == 'getTextLinks') {
var theText = document.body.textContent.toString();
var theMatch = theText.match(/(http[^\s]*)/g);
for(var i=0; i<theMatch.length; i++) {
data += theMatch[i] + '\n';
}
} else if (request == 'getSelectionLinks') {
var theLinks = document.links;
for (var i = 0; i < theLinks.length; i++) {
if (document.getSelection().containsNode(theLinks[i], true) && theLinks[i].href.indexOf('javascript:') == -1) {
data += theLinks[i].href + '\n';
}
}
} else if(request == 'getTextLinksSelection') {
var theText = window.getSelection().toString();
var theMatch = theText.match(/(http[^\s]*)/g);
if(theMatch)
for(var i=0; i<theMatch.length; i++) {
data += theMatch[i] + '\n';
}
}
//alert(data);
sendResponse(data);
});