-
Notifications
You must be signed in to change notification settings - Fork 3
/
trello_better_aging.user.js
73 lines (60 loc) · 2.71 KB
/
trello_better_aging.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
// ==UserScript==
// @name Better Aging in Trello
// @namespace https://blog.ladslezak.cz/
// @version 0.2.1
// @description Display aging border in Trello
// @author Ladislav Slezák
// @match https://trello.com/*
// @grant GM_addStyle
// ==/UserScript==
// Applied only to the YaST board, to use it elsewhere
// edit the regexp and change which columns should be affected
// (or remove the "nth-child" selector to apply everywhere).
// var trello_board_regexp = /^https:\/\/trello.com\/b\/<your_board_id>\//;
// apply only in the matching board
var trello_board_regexp = new RegExp(window.atob("Xmh0dHBzOi8vdHJlbGxvLmNvbS9iL2pxNm5vbjE2Lw=="));
// display the aging style in these columns (index starts from 1!)
var trello_aging_columns = [ 1, 2, 3, 4];
(function() {
'use strict';
function inject_css() {
// apply the style only on the specified columns
trello_aging_columns.forEach(function (column) {
// style only the two highest aging levels (2 and 3)
GM_addStyle('.list-wrapper:nth-child(' + column + ') .aging-level-2.list-card { border-left: solid 6px #c1c1c1; }');
GM_addStyle('.list-wrapper:nth-child(' + column + ') .aging-level-3.list-card { border-left: solid 6px #939393; }');
});
// reset the original Trello styling for all aging levels
[ 0, 1, 2, 3, 4].forEach(function (age) {
GM_addStyle('.aging-level-' + age + '.aging-regular { opacity: 1; }');
});
console.log("Custom aging style injected");
};
// if this is the requested board inject the style directly
if (window.location.href.match(trello_board_regexp))
{
inject_css();
}
else
{
// The current URL might be a card from the requested board but might be from a different board,
// we do not know this yet so we cannot inject the CSS now. But we can watch the history stack
// and check the current URL whenever it is changed.
// remember the original function
var original_pushState = history.pushState;
// monkeypatch the history.pushState()
history.pushState = function() {
// call the original pushState() method implementation to handle the call
var ret = original_pushState.apply(this, arguments);
// if the changed URL is the requested board then inject the CSS
if (window.location.href.match(trello_board_regexp))
{
inject_css();
// restore the original function to call this only once
history.pushState = original_pushState;
}
// return the original result
return ret;
}
}
})();