-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
99 lines (88 loc) · 2.65 KB
/
popup.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var ReportCard = {
modifiedDate: '',
getToday: function() {
var d = new Date();
var yyyy = d.getFullYear().toString();
var mm = (d.getMonth()+1).toString();
var dd = d.getDate().toString();
var date = (yyyy + '-' + (mm[1]?mm:'0'+mm[0]) + '-' + (dd[1]?dd:'0'+dd[0]));
return date;
},
weekFromNow: function() {
var d = new Date();
var yyyy = d.getFullYear().toString();
var mm = (d.getMonth()+1).toString();
var dd = (d.getDate()+7).toString();
var date = (yyyy + '-' + (mm[1]?mm:'0'+mm[0]) + '-' + (dd[1]?dd:'0'+dd[0]));
return date;
},
fortnightFromNow: function() {
var d = new Date();
var yyyy = d.getFullYear().toString();
var mm = (d.getMonth()+1).toString();
var dd = (d.getDate()+14).toString();
var date = (yyyy + '-' + (mm[1]?mm:'0'+mm[0]) + '-' + (dd[1]?dd:'0'+dd[0]));
return date;
},
monthFromNow: function() {
var d = new Date();
var yyyy = d.getFullYear().toString();
var mm = (d.getMonth()+2).toString();
var dd = (d.getDate()).toString();
var date = (yyyy + '-' + (mm[1]?mm:'0'+mm[0]) + '-' + (dd[1]?dd:'0'+dd[0]));
return date;
},
getBookmarks: function() {
var self = this;
chrome.bookmarks.getTree(function(bookmarks) {
self.printBookmarks(bookmarks[0].id);
});
},
printBookmarks: function(id) {
var self = this;
chrome.bookmarks.getChildren(id, function(children) {
var bookmarkBar = children[0];
self.createBookmark(bookmarkBar);
});
},
createBookmark: function(bookmarkBar) {
var repoUrl = this.url + '/issues?utf8=✓&q=is%3Aissue+closed%3A';
var today = this.getToday();
var bookmarkBarId = bookmarkBar.id;
var reportCardUrl = repoUrl + today + '..' + this.modifiedDate;
var reportCardName = 'ReportCard: ' + this.repoName;
chrome.bookmarks.create({
parentId: bookmarkBarId,
title: reportCardName,
url: reportCardUrl
},
function newReportCard() {
console.log('Added report card bookmark: ', reportCardUrl);
});
},
initialize: function(url) {
this.url = url;
this.repoName = this.url.split('/')[4];
$('#repo-name').append(this.repoName);
var self = this;
$('#one-week').click(function() {
self.modifiedDate = self.weekFromNow();
self.getBookmarks();
});
$('#two-week').click(function() {
console.debug('u click two week', url);
self.modifiedDate = self.fortnightFromNow();
self.getBookmarks();
});
$('#month').click(function() {
console.debug('u click month', url);
self.modifiedDate = self.monthFromNow();
self.getBookmarks();
});
},
};
document.addEventListener('DOMContentLoaded', function(event) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
ReportCard.initialize(tabs[0].url);
});
});