-
Notifications
You must be signed in to change notification settings - Fork 0
/
dom.js
25 lines (24 loc) · 857 Bytes
/
dom.js
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
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender);
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.askFor == "body")
parseBody(document.body, sendResponse);
});
function parseBody(bodyText, callback) {
var sumHtml = "";
var pTags = bodyText.getElementsByTagName('p');
for (var i = 0, length = pTags.length-1; i < length; i++) {
p = pTags[i];
if (p.innerText && p.innerText.indexOf('. ') && p.innerText.length > 15 ) {
// GET THE FIRST SENTENCE OF A PARAGRAPH
str = p.innerText.split(". ")[0]
// SHORTEN IF NECESSARY
if (str.length > 70) str = str.substring(0,70) + " ...";
sumHtml += "<li class='summarized'>" + str + ". </li>";
}
}
return callback({docBody: sumHtml});
}