-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinject.js
106 lines (85 loc) · 2.9 KB
/
inject.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
100
101
102
103
104
105
106
/**
* content scripts
*
* @author : snow@firebloom.cc
* @license : GPLv3
*/
(function() {
// show page action
// ------------------
chrome.runtime.sendMessage({});
})();
(function($){
$('.wrapper > .header > *').wrapAll('<div class="inner" />');
var pageId = '';
function generateSidebar() {
var $todolists = $('.section-todos .todolists .todolist');
if ($todolists.length == 0) {
$('.wtwr-sidebar').remove();
return
}
var items = $todolists.map(function() {
var $todolist = $(this);
var name = $todolist.find('h4 .name').text();
var guid = $todolist.data('guid');
return '<li><a href="javascript:;" data-guid="' + guid + '">' + name + '</a></li>'
}).get();
var $sidebar = $('<div class="wtwr-sidebar"><ul>' + items.join('') + '</ul></div>');
$('.wrapper').prepend($sidebar);
}
// FIXME should try to listen to pjaxload instead of interval
setInterval(function() {
var currentId = $('.wrapper > .container > .page > .page-inner').attr('id');
if (pageId != currentId) {
generateSidebar();
pageId = currentId;
}
if('page-members' == currentId) {
addBusyPanel();
}
}, 2000);
$(document).on('click', '.wtwr-sidebar a', function(e) {
e.preventDefault();
var guid = $(e.currentTarget).data('guid');
var target = $('.todolist[data-guid="' + guid + '"]');
if (!target.length) return
$('body, html').scrollTop(target.offset().top - 70) ;
});
// name jQuery objects as $xxx instead of jXxx
function addBusyPanel() {
if($('#page-members .switch-to-busy').length > 0) { return; }
var jSwitch = $('<a class="switch-to-busy" href="javascript:;">Busy Panel</a>');
var jMemberPanel = $('#page-members');
var jBusyPanel = $('<div id="page-busy" class="page-inner" data-page-name="Busy">'+
'<section class="today">' +
'<h5 class="box-title"><i class="twr twr-crosshairs"></i>今天</h5>' +
'<div class="todolist">' +
'<ul class="todos"></ul>'+
'</div>' +
'</section>' +
'<section class="next">' +
'<h5 class="box-title"><i class="twr twr-tasks"></i>接下来</h5>' +
'<div class="todolist">' +
'<ul class="todos"></ul>'+
'</div>' +
'</section>' +
'</div>')
$('#page-members .group-default').prepend(jSwitch);
jSwitch.on('click', function(evt){
jBusyPanel.insertBefore(jMemberPanel);
jMemberPanel.detach();
});
var connGuid = $('#conn-guid').val();
jMemberPanel.find('.member-link').each(function(idx, el){
var memberUrl = el.href + "?conn_guid="+connGuid+"&pjax=1";
$.ajax({
url: memberUrl,
success: function(data) {
var jPage = $(data)
jBusyPanel.find('.today ul').append(jPage.find('.box-today .todos .todo'));
jBusyPanel.find('.next ul').append(jPage.find('.box-next .todos .todo'));
}
});
});
}
})(jQuery);