-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
33 lines (31 loc) · 808 Bytes
/
content.js
File metadata and controls
33 lines (31 loc) · 808 Bytes
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
32
33
function getHTMLOfSelection () {
var range;
if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
return $(range.htmlText).text();
}
else if (window.getSelection) {
var selection = window.getSelection();
if (selection.rangeCount > 0) {
range = selection.getRangeAt(0);
var clonedSelection = range.cloneContents();
var div = document.createElement('div');
div.appendChild(clonedSelection);
return $(div).text();
}
else {
return '';
}
}
else {
return '';
}
}
chrome.extension.onMessage.addListener(function(message, extension, callback) {
$.get("http://localhost/hackathon/index.php", {
'insert': getHTMLOfSelection()
});
alert("Done!");
return true;
});
console.log(111);