-
Notifications
You must be signed in to change notification settings - Fork 1
/
a_bit_bad_rtm.user.js
253 lines (204 loc) · 7.6 KB
/
a_bit_bad_rtm.user.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// ==UserScript==
// @name A Bit Bad RTM
// @namespace http://www.rememberthemilk.com
// @include http://www.rememberthemilk.com/*
// @include https://www.rememberthemilk.com/*
// ==/UserScript==
/** simple version of $X
* $X(exp);
* $X(exp, context);
* @source http://gist.github.com/3242.txt
*/
var $X = function (exp, context) {
context || (context = document);
var expr = (context.ownerDocument || context).createExpression(exp, function (prefix) {
return document.createNSResolver(context.documentElement || context).lookupNamespaceURI(prefix) ||
context.namespaceURI || document.documentElement.namespaceURI || "";
});
var result = expr.evaluate(context, XPathResult.ANY_TYPE, null);
switch (result.resultType) {
case XPathResult.STRING_TYPE : return result.stringValue;
case XPathResult.NUMBER_TYPE : return result.numberValue;
case XPathResult.BOOLEAN_TYPE: return result.booleanValue;
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
// not ensure the order.
var ret = [], i = null;
while (i = result.iterateNext()) ret.push(i);
return ret;
}
return null;
}
//refresh 対策
var overrideListTabsBlitDiv = function()
{
if (window.listTabs)
{
var oldBlitDiv = window.listTabs.blitDiv;
window.listTabs.blitDiv = function()
{
oldBlitDiv.call(window.listTabs);
refreshListTabsStyles();
showTasksCount();
hideLists();
}
window.listTabs.blitDiv();
}
}
var refreshListTabsStyles = function()
{
var divListTabs = document.getElementById("listtabs");
divListTabs.firstChild.style.listStyle = "none";
divListTabs.firstChild.style.padding = "0px 5px 0px 5px";
divListTabs.firstChild.style.whiteSpace = "nowrap";
}
var hideLists = function()
{
if (window.listTabs)
{
var listItems = window.listTabs.div.getElementsByTagName("li");
for (var i = 0; i < window.listTabs.data.length; ++i)
{
if (window.listTabs.data[i] && isListHidden(window.listTabs.data[i][1]))
listItems[i].style.display = "none";
}
}
}
var overrideTaskCloudUpdate = function()
{
var oldTaskCloudUpdate = window.taskCloud.update;
window.taskCloud.update = function()
{
oldTaskCloudUpdate.call(window.taskCloud);
window.listTabs.blitDiv();
}
}
//Column
var createLeftColumn = function()
{
var leftColumn = document.createElement('div');
var appView = document.getElementById("appview");
var listBox = document.getElementById("listbox");
leftColumn.setAttribute('id','leftColumn');
leftColumn.style.cssFloat = "left";
leftColumn.style.paddingLeft = "5px";
leftColumn.style.paddingRight = "8px";
leftColumn.style.display = "none";
if (appView && listBox){
appView.insertBefore(leftColumn, listBox);
}
}
var createListTabsContainer = function()
{
var listTabsBox = document.createElement('div');
var leftColumn = document.getElementById("leftColumn");
listTabsBox.innerHTML = '<div class="white_rbroundbox"> <div class="white_rbtop"> <div> <div></div> </div> </div> <div class="white_rbcontentwrap"> <div class="white_rbcontent"> <table><tr><td><div class="taskcloudcontent" style="padding: 0px 5px 0px 5px;" id="listtabscontainer"> </div></td></tr></table> </div> </div> <div class="white_rbbot"> <div><div></div> </div> </div> </div> ';
leftColumn.appendChild(listTabsBox);
}
var moveListTabs = function()
{
var listTabs = document.getElementById("listtabs");
listTabs.className = "";
listTabs.style.width = "100%";
listTabs.firstChild.style.listStyle = "none";
listTabs.firstChild.style.padding = "0px 5px 0px 5px";
listTabs.firstChild.style.whiteSpace = "nowrap";
var listTabsContainer = document.getElementById("listtabscontainer");
if (listTabsContainer){
listTabsContainer.appendChild(listTabs);
}
}
var showTasksCount = function()
{
var listItems = $X("//*[@id=\"listtabs\"]/ul/li");
for (var i = 0; window.listTabs.data && window.listTabs.data[i]; ++i)
{
var tasksCount = 0;
if (window.listTabs.data[i][2])
{
var filter = window.listTabs.data[i][2];
if (filter && filter.indexOf("status:") < 0){
filter = "(" + filter + ") and (status:incomplete)";
}
if (window.overviewList && filter){
tasksCount = window.overviewList.getFilteredList(filter).length
}
}
else
{
if (window.format){
tasksCount = window.format.getListStatistics(window.listTabs.data[i][1])[5];
listItems[i].firstChild.style.color = "black";
}
if (tasksCount > 0){
listItems[i].firstChild.innerHTML += " (" + tasksCount + ")";
}
}
}
}
var moveTabsToTheLeft = function()
{
createLeftColumn();
createListTabsContainer();
moveListTabs();
var tools_spacer = document.getElementById("tools_spacer");
tools_spacer.style.paddingTop = "1px";
tools_spacer.style.borderTop = "1px solid #CACACA";
document.getElementById("sorting").style.marginTop = "0px";
document.getElementById("tools").style.paddingTop = "5px";
var content = document.getElementById("content");
var leftColumn = document.getElementById("leftColumn");
var listTabsContainer = document.getElementById("listtabscontainer");
leftColumn.style.display = "block";
leftColumn.style.width = Math.round(listTabsContainer.clientWidth * 1.14) + "px";
content.style.width = (973 + leftColumn.clientWidth) + "px";
}
//Keyboard
var handleKeyPressEvent = function(ev)
{
var keyList = "12qweJK";
var tabs = window.view.getViewTabs();
var pressKey = ev.which;
pressKey = String.fromCharCode(pressKey);
if( keyList.indexOf(pressKey,0) > -1 ){
addKeyBind( "1", function(){ }, ev );
addKeyBind( "2", function(){ }, ev );
addKeyBind( "q", function(){ window.utility.stopEvent(ev); rateChage(1); }, ev );
addKeyBind( "w", function(){ window.utility.stopEvent(ev); rateChage(2); }, ev );
addKeyBind( "e", function(){ window.utility.stopEvent(ev); rateChage(3); }, ev );
addKeyBind( "J", function(){ window.utility.stopEvent(ev); tabs.selectRight(); }, ev );
addKeyBind( "K", function(){ window.utility.stopEvent(ev); tabs.selectLeft(); }, ev );
return false;
}
return true;
}
//いつもの
var addKeyBind = function( keyChar, func, eve ){
var t=eve.target;
var n=t.tagName.toLowerCase();
if( t.nodeType != 1 || n == "input" || n == "textarea" ){
return;
}
var pressKey = eve.which;
keyChar = keyChar.charCodeAt(keyChar);
if( pressKey == keyChar ){
func.apply();//preventDefaultは残しておいた。1/2で切り替えたいから
}
}
var rateChage = function(v){
eval("window.taskList.tasksSetPriority"+ v +"();");
}
var overrideBodyKeyPressHandler = function()
{
var oldBodyKeyPressHandler = window.eventMgr.bodyKeyPressHandler;
window.eventMgr.bodyKeyPressHandler = function(ev, ignoreCombo)
{
if (handleKeyPressEvent(ev)){
return oldBodyKeyPressHandler.call(window.eventMgr, ev, ignoreCombo);
}
return true;
}
}
window.addEventListener('load', overrideListTabsBlitDiv, false);
window.addEventListener('load', moveTabsToTheLeft, false);
window.addEventListener('load', overrideBodyKeyPressHandler, false);
window.addEventListener('load', overrideTaskCloudUpdate, false);