Skip to content

Commit b358812

Browse files
authored
fix(Trello): update reflecting the new UI (#2339)
* chore(trello): code formatting * fix(trello): make the side button work again * fix(trello): task list support * chore(Trello): remove console.log
1 parent 6932a72 commit b358812

File tree

1 file changed

+63
-47
lines changed

1 file changed

+63
-47
lines changed

src/content/trello.js

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,101 @@
33
* @urlAlias trello.com
44
* @urlRegex *://trello.com/*
55
*/
6-
'use strict';
6+
'use strict'
77
/* global createTag */
88

99
const getProject = () => {
10-
const project = document.querySelector('.board-header [data-testid="board-name-display"]')
11-
return project ? project.textContent.trim() : '';
12-
};
10+
const project = document.querySelector(
11+
'.board-header [data-testid="board-name-display"]',
12+
)
13+
return project ? project.textContent.trim() : ''
14+
}
15+
16+
const cardContainerSelector = '.window-wrapper'
1317

14-
const cardContainerSelector = '.card-detail-window';
1518
togglbutton.render(
16-
'.window-header:not(.toggl)',
17-
{ observe: true, debounceInterval: 300 },
19+
'#card-back-name:not(.toggl)',
20+
{ observe: true, debounceInterval: 1000 },
1821
(elem) => {
19-
const actionButton =
20-
$('.js-move-card') ||
21-
$('.js-copy-card') ||
22-
$('.js-archive-card') ||
23-
$('.js-more-menu');
24-
25-
if (!actionButton) {
26-
return;
22+
const actionsWrapper = $(
23+
'#layer-manager-card-back section:nth-child(4) > ul',
24+
)
25+
26+
if (!actionsWrapper) {
27+
return
2728
}
2829

2930
const getDescription = () => {
30-
const description = $('.window-title h2', elem);
31-
return description ? description.textContent.trim() : '';
32-
};
31+
const description = $('#card-back-name')
32+
return description ? description.textContent.trim() : ''
33+
}
34+
35+
const container = createTag('div', 'button-link trello-tb-wrapper')
3336

34-
const container = createTag('div', 'button-link trello-tb-wrapper');
3537
const link = togglbutton.createTimerLink({
3638
className: 'trello',
3739
description: getDescription,
3840
projectName: getProject,
39-
container: cardContainerSelector
40-
});
41+
container: '[data-testid="card-back-name"]',
42+
})
4143

4244
// Pass through click on Trello button to the timer link
4345
container.addEventListener('click', (e) => {
44-
link.click();
45-
});
46+
link.click()
47+
})
48+
49+
container.appendChild(link)
4650

47-
container.appendChild(link);
48-
actionButton.parentNode.insertBefore(container, actionButton);
51+
actionsWrapper.prepend(container)
4952
},
50-
cardContainerSelector
51-
);
53+
cardContainerSelector,
54+
)
5255

5356
/* Checklist buttons */
5457
togglbutton.render(
55-
'.checklist-item-details:not(.toggl)',
56-
{ observe: true },
58+
'[data-testid="check-item-container"]:not(.toggl)',
59+
{ observe: true, debounceInterval: 1000 },
5760
(elem) => {
5861
const getTitleText = () => {
59-
const title = $('.window-title h2');
60-
return title ? title.textContent.trim() : '';
61-
};
62+
const description = $('#card-back-name')
63+
return description ? description.textContent.trim() : ''
64+
}
6265

6366
const getTaskText = () => {
64-
const task = $('.checklist-item-details-text', elem);
65-
return task ? task.textContent.trim() : '';
66-
};
67+
const task = $('.ak-renderer-wrapper', elem)
68+
return task ? task.textContent.trim() : ''
69+
}
6770

6871
const getDescription = () => {
69-
return `${getTitleText()} - ${getTaskText()}`;
70-
};
72+
return `${getTitleText()} - ${getTaskText()}`
73+
}
7174

7275
const link = togglbutton.createTimerLink({
7376
className: 'trello-list',
7477
buttonType: 'minimal',
7578
projectName: getProject,
7679
description: getDescription,
77-
container: cardContainerSelector
78-
});
79-
const wrapper = document.createElement('span');
80-
wrapper.classList.add('checklist-item-menu');
81-
wrapper.style.display = 'flex';
82-
wrapper.style.alignItems = 'center';
83-
wrapper.appendChild(link);
84-
elem.querySelector('.checklist-item-controls').appendChild(wrapper);
80+
container: '[data-testid="card-back-name"]',
81+
})
82+
const wrapper = document.createElement('span')
83+
wrapper.classList.add('checklist-item-menu')
84+
wrapper.style.display = 'flex'
85+
wrapper.style.alignItems = 'center'
86+
wrapper.style.marginLeft = '4px'
87+
wrapper.appendChild(link)
88+
89+
// Add StopPropagation to prevent the card from closing.
90+
wrapper.addEventListener('click', (e) => {
91+
e.preventDefault()
92+
e.stopPropagation()
93+
94+
// Click on the Toggl button
95+
link.querySelector('button').click()
96+
})
97+
98+
elem
99+
.querySelector('[data-testid="check-item-hover-buttons"]')
100+
.appendChild(wrapper)
85101
},
86-
`.checklist-items-list, ${cardContainerSelector}`
87-
);
102+
cardContainerSelector,
103+
)

0 commit comments

Comments
 (0)