-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
104 lines (89 loc) · 2.65 KB
/
script.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
var observer;
function observe(node) {
if (observer) {
observer.disconnect();
}
observer = new MutationObserver(onChange);
observer.observe(node, {
childList: true,
subtree: true,
});
}
function onChange(changes) {
for (let change of changes) {
// onNodeAdd(change.target);
for (let node of change.addedNodes) {
onNodeAdd(node);
}
}
}
function onNodeAdd(node) {
if (node.nodeType != Node.ELEMENT_NODE) {
// do nothing
} else if (node.nodeName === "svg") {
// do nothing
} else if (node.classList?.contains("board-wrapper")) {
observe(node.parentNode);
onBoardAdd(node);
} else if (node.classList?.contains("badge")) {
onBadgeAdd(node);
} else if (node.classList?.contains("list-card-details")) {
addBadges(node);
} else if (node.nodeName === "SPAN") {
addBadges(node);
} else {
addBadges(node);
}
}
function onBoardAdd(board) {
let boardUrl = new URL(window.location.href);
let boardPath = boardUrl.pathname.split("/");
let boardId = boardPath[2];
for (let list of board.querySelectorAll(".js-list")) {
addCollapse(list, boardId);
}
}
function addCollapse(list, boardId) {
let listHeaderName = list.querySelector(".list-header-name");
let listId = boardId + ":" + encodeURI(listHeaderName.textContent);
chrome.storage.local.get([listId], (isCollapsed) => {
onCollapse(list, listId, isCollapsed[listId]);
});
let toggleButton = document.createElement("div");
toggleButton.className = "collapse-toggle";
toggleButton.addEventListener("click", () => {
let isCollapsed = list.classList?.contains("collapsed");
onCollapse(list, listId, isCollapsed ? null : true);
});
let listHeader = list.querySelector(".list-header");
listHeader.insertBefore(toggleButton, listHeaderName);
}
function onCollapse(list, listId, isCollapsed) {
chrome.storage.local.set({ [listId]: isCollapsed }, () => {
if (isCollapsed) {
list.classList.add("collapsed");
} else {
list.classList.remove("collapsed");
}
});
}
var iconBlacklist = [
/app\.screenful\.me\/integrations\/trello-scaled/,
/confluence\.trello\.services\/images\/confluence-logo/,
/github\.trello\.services\/images\/icon/,
/github\.trello\.services\/images\/pull-request/,
/static.kanbhala.com/, // Time Tracker
];
function onBadgeAdd(badge) {
let icon = badge.querySelector(".badge-icon[style]");
let iconImage = icon?.style?.backgroundImage;
if (iconImage && iconBlacklist.some((x) => x.test(iconImage))) {
badge.classList.add("hidden");
}
}
function addBadges(node) {
for (let badge of node.querySelectorAll(".badge")) {
onBadgeAdd(badge);
}
}
observe(document);