-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPagesSource.js
More file actions
36 lines (29 loc) · 1.03 KB
/
getPagesSource.js
File metadata and controls
36 lines (29 loc) · 1.03 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
32
33
34
35
36
function shitty_pluralize(str, size){
if(size > 1) return str + 's';
return str;
}
function scrapePage(document) {
text = '';
statusArr = document.querySelectorAll('.diffbar-item.toc-select .select-menu-item .octicon');
resultObj = {};
document.querySelectorAll('#files .file-info a[href^="#diff"]').forEach(function(i, index){
var status = statusArr[index].classList[1].split('-')[2]
if(!(status in resultObj))
resultObj[status] = []
resultObj[status].push(i.textContent.trim())
});
Object.keys(resultObj).forEach(function(key, index){
text += '**' + key.charAt(0).toUpperCase() + key.slice(1) + ' - ' + resultObj[key].length + ' ' + shitty_pluralize('file', resultObj[key].length) + '**';
text += '<br/>';
for(var k = 0; k < resultObj[key].length; k++)
text += '- ' + resultObj[key][k] + '<br>';
if(Object.keys(resultObj).length - 1 != index){
text += '<br/>';
}
});
return text;
}
chrome.runtime.sendMessage({
action: "getSource",
source: scrapePage(document)
});