-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_dom.js
42 lines (30 loc) · 1.18 KB
/
get_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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var strip = function(text) {
var stripped = String(text).replace(/(\r\n|\n|\r)/g, '').replace(/^\s+|\s+$/g, '').replace(/\s{2,}/g, '');
return stripped
}
var toDate = function(date_str) {
var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
var date = new Date(date_str)
return months[date.getMonth()] + " " + date. getDate();
}
var Meat = function(){
var url,
date = '',
comment = '',
title = document.getElementsByTagName('head')[0].getElementsByTagName('title')[0].innerHTML || "";
[].forEach.call(document.getElementsByTagName('meta'), function(element) {
if(element.getAttribute('property') == 'og:url') {
url = element.getAttribute('content');
} else if(element.getAttribute('property') == 'og:description') {
comment = element.getAttribute('content');
} else if(element.getAttribute('property') == 'article:published_time') {
date = toDate(element.getAttribute('content'));
}
});
if(!url) { url = location.href; }
return { title: strip(title), url: strip(url), comment: strip(comment), pubdate: date }
}
chrome.extension.sendMessage({
action: "getDOM",
source: Meat()
});