|
1 | 1 | /**
|
2 | 2 | * @name Asana
|
3 |
| - * @urlAlias app.asana.com |
| 3 | + * @urlAlias app.asana.com |
4 | 4 | * @urlRegex *://app.asana.com/*
|
5 | 5 | */
|
6 |
| -'use strict'; |
| 6 | +'use strict' |
7 | 7 |
|
8 | 8 | const projectHeaderSelector = () => {
|
9 | 9 | // Try to look for for page project title instead.
|
10 | 10 | const projectHeader = document.querySelector(
|
11 | 11 | '.ProjectPageHeaderProjectTitle-container',
|
12 |
| - ); |
| 12 | + ) |
13 | 13 |
|
14 | 14 | if (!projectHeader) {
|
15 |
| - return ''; |
| 15 | + return '' |
16 | 16 | }
|
17 | 17 | return projectHeader.textContent
|
18 | 18 | .replace(/\u00a0/g, ' ') // There can be in Asana header content
|
19 |
| - .trim(); |
20 |
| -}; |
| 19 | + .trim() |
| 20 | +} |
21 | 21 |
|
22 | 22 | // Board view. Inserts button next to assignee/due date.
|
23 |
| -togglbutton.render('.BoardCardLayout:not(.toggl)', { observe: true }, |
24 |
| - boadCardElem => { |
| 23 | +togglbutton.render( |
| 24 | + '.BoardCardLayout:not(.toggl)', |
| 25 | + { observe: true }, |
| 26 | + (boadCardElem) => { |
25 | 27 | if (boadCardElem.querySelector('.toggl-button')) {
|
26 | 28 | // Due to the way this UI is rendered, we must check for existence of old buttons manually.
|
27 |
| - return; |
| 29 | + return |
28 | 30 | }
|
29 | 31 |
|
30 |
| - const descriptionSelector = () => boadCardElem.querySelector('.BoardCard-taskName').textContent.trim(); |
31 |
| - |
| 32 | + const descriptionSelector = () => |
| 33 | + boadCardElem.querySelector('.BoardCard-taskName').textContent.trim() |
32 | 34 |
|
33 | 35 | const link = togglbutton.createTimerLink({
|
34 | 36 | className: 'asana-board-view',
|
35 | 37 | description: descriptionSelector,
|
36 | 38 | buttonType: 'minimal',
|
37 | 39 | projectName: projectHeaderSelector,
|
38 | 40 | // N.B. Tags cannot be supported on board view as the information is not available.
|
39 |
| - }); |
| 41 | + }) |
40 | 42 |
|
41 |
| - const injectContainer = boadCardElem.querySelector('.BoardCardLayout-actionButtons'); |
| 43 | + const injectContainer = boadCardElem.querySelector( |
| 44 | + '.BoardCardLayout-actionButtons', |
| 45 | + ) |
42 | 46 | if (injectContainer) {
|
43 |
| - injectContainer.insertAdjacentElement('afterbegin', link); |
| 47 | + injectContainer.insertAdjacentElement('afterbegin', link) |
44 | 48 | }
|
45 |
| - } |
46 |
| -); |
| 49 | + }, |
| 50 | +) |
47 | 51 |
|
48 | 52 | // Spreadsheet view. Inserts button next to to the task name.
|
49 |
| -togglbutton.render('.SpreadsheetRow .SpreadsheetTaskName:not(.toggl)', { observe: true }, |
| 53 | +togglbutton.render( |
| 54 | + '.SpreadsheetRow .SpreadsheetTaskName:not(.toggl)', |
| 55 | + { observe: true }, |
50 | 56 | function (taskNameCell) {
|
51 |
| - const container = taskNameCell.closest('.SpreadsheetRow'); |
| 57 | + const container = taskNameCell.closest('.SpreadsheetRow') |
52 | 58 |
|
53 | 59 | if (container.querySelector('.toggl-button')) {
|
54 | 60 | // Due to the way this UI is rendered, we must check for existence of old buttons manually.
|
55 |
| - return; |
| 61 | + return |
56 | 62 | }
|
57 | 63 |
|
58 |
| - const descriptionSelector = () => taskNameCell.querySelector('textarea').textContent.trim(); |
| 64 | + const descriptionSelector = () => |
| 65 | + taskNameCell.querySelector('textarea').textContent.trim() |
59 | 66 |
|
60 | 67 | const projectSelector = () => {
|
61 |
| - const projectCell = container.querySelector('.SpreadsheetTaskRow-projectsCell'); |
| 68 | + const projectCell = container.querySelector( |
| 69 | + '.SpreadsheetTaskRow-projectsCell', |
| 70 | + ) |
62 | 71 | if (!projectCell) {
|
63 | 72 | // Try to look for for page project title instead.
|
64 |
| - return projectHeaderSelector(); |
| 73 | + return projectHeaderSelector() |
65 | 74 | }
|
66 | 75 |
|
67 | 76 | // There can be multiple projects, but we can't support trying to match multiple yet.
|
68 |
| - const firstProject = projectCell.querySelector('.Pill'); |
69 |
| - return firstProject ? firstProject.textContent.trim() : projectHeaderSelector(); |
70 |
| - }; |
| 77 | + const firstProject = projectCell.querySelector( |
| 78 | + '.SpreadsheetPotsCell-potPill', |
| 79 | + ) |
| 80 | + return firstProject |
| 81 | + ? firstProject.textContent.trim() |
| 82 | + : projectHeaderSelector() |
| 83 | + } |
71 | 84 |
|
72 | 85 | const tagsSelector = () => {
|
73 |
| - const tags = container.querySelectorAll('.SpreadsheetTaskRow-tagsCell .Pill'); |
74 |
| - return [...tags].map(tag => tag.textContent.trim()); |
75 |
| - }; |
| 86 | + const tags = container.querySelectorAll( |
| 87 | + '.SpreadsheetTaskRow-tagsCell .SpreadsheetPotsCell-potPill', |
| 88 | + ) |
| 89 | + return [...tags].map((tag) => tag.textContent.trim()) |
| 90 | + } |
76 | 91 |
|
77 | 92 | const link = togglbutton.createTimerLink({
|
78 | 93 | className: 'asana-spreadsheet',
|
79 | 94 | description: descriptionSelector,
|
80 | 95 | projectName: projectSelector,
|
81 | 96 | tags: tagsSelector,
|
82 |
| - buttonType: 'minimal' |
83 |
| - }); |
| 97 | + buttonType: 'minimal', |
| 98 | + }) |
84 | 99 |
|
85 |
| - taskNameCell.insertAdjacentElement('afterend', link); |
86 |
| - } |
87 |
| -); |
| 100 | + taskNameCell.insertAdjacentElement('afterend', link) |
| 101 | + }, |
| 102 | +) |
88 | 103 |
|
89 | 104 | // 2020 My Tasks view, possibly other similar views.
|
90 |
| -togglbutton.render('.MyTasksTaskRow:not(.toggl)', { observe: true }, |
| 105 | +togglbutton.render( |
| 106 | + '.MyTasksTaskRow:not(.toggl)', |
| 107 | + { observe: true }, |
91 | 108 | function (elem) {
|
92 | 109 | if (elem.querySelector('.toggl-button')) {
|
93 | 110 | // Due to the way this UI is rendered, we must check for existence of old buttons manually.
|
94 |
| - return; |
| 111 | + return |
95 | 112 | }
|
96 |
| - const descriptionSelector = () => elem.querySelector('.TaskName textarea').textContent; |
| 113 | + const descriptionSelector = () => |
| 114 | + elem.querySelector('.TaskName textarea').textContent |
97 | 115 |
|
98 | 116 | // attempt at separating projects and tags, which are not differentiated in the dom
|
99 | 117 | // assume first pill is a project and any others are tags
|
100 | 118 | // misses tags which are in the "..." overflow, and if there is a tag without a project
|
101 | 119 | const pillSelector = (type) => {
|
102 |
| - const pills = [...elem.querySelectorAll('.Pill')] |
103 |
| - .map(pill => pill.textContent.trim()); |
| 120 | + const pills = [...elem.querySelectorAll('.Pill')].map((pill) => |
| 121 | + pill.textContent.trim(), |
| 122 | + ) |
104 | 123 | if (type === 'project') {
|
105 |
| - return pills.length ? pills : ''; |
| 124 | + return pills.length ? pills : '' |
106 | 125 | } else if (type === 'tags') {
|
107 |
| - return pills.length > 1 ? pills.slice(1) : []; |
| 126 | + return pills.length > 1 ? pills.slice(1) : [] |
108 | 127 | }
|
109 |
| - }; |
| 128 | + } |
110 | 129 |
|
111 | 130 | const projectSelector = () => {
|
112 |
| - return pillSelector('project'); |
113 |
| - }; |
| 131 | + return pillSelector('project') |
| 132 | + } |
114 | 133 |
|
115 | 134 | const tagsSelector = () => {
|
116 |
| - return pillSelector('tags'); |
117 |
| - }; |
| 135 | + return pillSelector('tags') |
| 136 | + } |
118 | 137 |
|
119 | 138 | const link = togglbutton.createTimerLink({
|
120 | 139 | className: 'asana-new-ui',
|
121 | 140 | description: descriptionSelector,
|
122 | 141 | projectName: projectSelector,
|
123 | 142 | tags: tagsSelector,
|
124 |
| - buttonType: 'minimal' |
125 |
| - }); |
| 143 | + buttonType: 'minimal', |
| 144 | + }) |
126 | 145 |
|
127 |
| - const wrapper = document.createElement('div'); |
128 |
| - wrapper.style.margin = '3px 0 0 4px'; |
129 |
| - wrapper.appendChild(link); |
| 146 | + const wrapper = document.createElement('div') |
| 147 | + wrapper.style.margin = '3px 0 0 4px' |
| 148 | + wrapper.appendChild(link) |
130 | 149 |
|
131 |
| - elem.appendChild(wrapper); |
132 |
| - } |
133 |
| -); |
| 150 | + elem.appendChild(wrapper) |
| 151 | + }, |
| 152 | +) |
134 | 153 |
|
135 | 154 | // Task detail. My Tasks, Spreadsheet, Board, ...
|
136 |
| -togglbutton.render('.TaskPane:not(.toggl)', { observe: true }, |
137 |
| - taskPaneEl => { |
138 |
| - if (taskPaneEl.querySelector('.toggl-button')) { |
139 |
| - // Due to the way this UI is rendered, we must check for existence of old buttons manually. |
140 |
| - return; |
141 |
| - } |
| 155 | +togglbutton.render('.TaskPane:not(.toggl)', { observe: true }, (taskPaneEl) => { |
| 156 | + if (taskPaneEl.querySelector('.toggl-button')) { |
| 157 | + // Due to the way this UI is rendered, we must check for existence of old buttons manually. |
| 158 | + return |
| 159 | + } |
142 | 160 |
|
143 |
| - const descriptionSelector = () => taskPaneEl.querySelector('.TaskPaneTitle textarea').textContent.trim(); |
| 161 | + const descriptionSelector = () => |
| 162 | + taskPaneEl.querySelector('.TaskPaneTitle textarea').textContent.trim() |
144 | 163 |
|
145 |
| - const projectSelector = () => { |
146 |
| - const projectElement = taskPaneEl.querySelector('.TokenizerPillBase-name'); |
147 |
| - if (!projectElement) return ''; |
| 164 | + const projectSelector = () => { |
| 165 | + const projectElement = taskPaneEl.querySelector( |
| 166 | + '.TaskProjectTokenPill-tokenPillWrapper .TaskProjects-projectTokenPill span', |
| 167 | + ) |
| 168 | + if (!projectElement) return '' |
148 | 169 |
|
149 |
| - return projectElement.textContent.trim(); |
150 |
| - }; |
| 170 | + return projectElement.textContent.trim() |
| 171 | + } |
151 | 172 |
|
152 |
| - const tagsSelector = () => { |
153 |
| - const tags = taskPaneEl.querySelectorAll('.TokenizerPillBase-name'); |
154 |
| - return [...tags].map(tag => tag.textContent.trim()); |
155 |
| - } |
| 173 | + const tagsSelector = () => { |
| 174 | + const tags = taskPaneEl.querySelectorAll('.TaskTagTokenPills-potPill span') |
| 175 | + return [...tags].map((tag) => tag.textContent.trim()) |
| 176 | + } |
156 | 177 |
|
157 |
| - const link = togglbutton.createTimerLink({ |
158 |
| - className: 'TaskPaneToolbar-button', |
159 |
| - description: descriptionSelector, |
160 |
| - projectName: projectSelector, |
161 |
| - buttonType: 'minimal', |
162 |
| - tags: tagsSelector |
163 |
| - }); |
| 178 | + const link = togglbutton.createTimerLink({ |
| 179 | + className: 'TaskPaneToolbar-button', |
| 180 | + description: descriptionSelector, |
| 181 | + projectName: projectSelector, |
| 182 | + buttonType: 'minimal', |
| 183 | + tags: tagsSelector, |
| 184 | + }) |
164 | 185 |
|
165 |
| - const injectContainer = taskPaneEl.querySelector('.TaskPaneExtraActionsButton'); |
| 186 | + const injectContainer = taskPaneEl.querySelector( |
| 187 | + '.TaskPaneExtraActionsButton', |
| 188 | + ) |
166 | 189 |
|
167 |
| - if (injectContainer) { |
168 |
| - injectContainer.parentNode.insertBefore(link, injectContainer.nextSibling); |
169 |
| - } |
| 190 | + if (injectContainer) { |
| 191 | + injectContainer.parentNode.insertBefore(link, injectContainer.nextSibling) |
170 | 192 | }
|
171 |
| -); |
| 193 | +}) |
0 commit comments