-
Notifications
You must be signed in to change notification settings - Fork 1
/
console.js
57 lines (42 loc) · 1.57 KB
/
console.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var dump = function(input) {
output = "";
for (key in input) {
value = input[key];
if(value instanceof Array) {
output += " " + key + ":" + "\n - " + value[0] + "\n";
} else if (key == "title") {
output += " - " + key + ":" + " \"" + value + "\"\n";
} else {
output += " " + key + ":" + " \"" + value + "\"\n";
}
}
return output;
}
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(tag){
var url,
date = '',
comment = '',
tag = tag !== undefined ? tag : "rb",
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, tags: [tag] }
}
dump(Meat());