|
3 | 3 | * @urlAlias trello.com
|
4 | 4 | * @urlRegex *://trello.com/*
|
5 | 5 | */
|
6 |
| -'use strict'; |
| 6 | +'use strict' |
7 | 7 | /* global createTag */
|
8 | 8 |
|
9 | 9 | 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' |
13 | 17 |
|
14 |
| -const cardContainerSelector = '.card-detail-window'; |
15 | 18 | togglbutton.render(
|
16 |
| - '.window-header:not(.toggl)', |
17 |
| - { observe: true, debounceInterval: 300 }, |
| 19 | + '#card-back-name:not(.toggl)', |
| 20 | + { observe: true, debounceInterval: 1000 }, |
18 | 21 | (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 |
27 | 28 | }
|
28 | 29 |
|
29 | 30 | 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') |
33 | 36 |
|
34 |
| - const container = createTag('div', 'button-link trello-tb-wrapper'); |
35 | 37 | const link = togglbutton.createTimerLink({
|
36 | 38 | className: 'trello',
|
37 | 39 | description: getDescription,
|
38 | 40 | projectName: getProject,
|
39 |
| - container: cardContainerSelector |
40 |
| - }); |
| 41 | + container: '[data-testid="card-back-name"]', |
| 42 | + }) |
41 | 43 |
|
42 | 44 | // Pass through click on Trello button to the timer link
|
43 | 45 | container.addEventListener('click', (e) => {
|
44 |
| - link.click(); |
45 |
| - }); |
| 46 | + link.click() |
| 47 | + }) |
| 48 | + |
| 49 | + container.appendChild(link) |
46 | 50 |
|
47 |
| - container.appendChild(link); |
48 |
| - actionButton.parentNode.insertBefore(container, actionButton); |
| 51 | + actionsWrapper.prepend(container) |
49 | 52 | },
|
50 |
| - cardContainerSelector |
51 |
| -); |
| 53 | + cardContainerSelector, |
| 54 | +) |
52 | 55 |
|
53 | 56 | /* Checklist buttons */
|
54 | 57 | togglbutton.render(
|
55 |
| - '.checklist-item-details:not(.toggl)', |
56 |
| - { observe: true }, |
| 58 | + '[data-testid="check-item-container"]:not(.toggl)', |
| 59 | + { observe: true, debounceInterval: 1000 }, |
57 | 60 | (elem) => {
|
58 | 61 | 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 | + } |
62 | 65 |
|
63 | 66 | 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 | + } |
67 | 70 |
|
68 | 71 | const getDescription = () => {
|
69 |
| - return `${getTitleText()} - ${getTaskText()}`; |
70 |
| - }; |
| 72 | + return `${getTitleText()} - ${getTaskText()}` |
| 73 | + } |
71 | 74 |
|
72 | 75 | const link = togglbutton.createTimerLink({
|
73 | 76 | className: 'trello-list',
|
74 | 77 | buttonType: 'minimal',
|
75 | 78 | projectName: getProject,
|
76 | 79 | 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) |
85 | 101 | },
|
86 |
| - `.checklist-items-list, ${cardContainerSelector}` |
87 |
| -); |
| 102 | + cardContainerSelector, |
| 103 | +) |
0 commit comments