|
1 | | -'use strict'; |
| 1 | +/** |
| 2 | + * @name Gitea |
| 3 | + * @urlAlias gitea.com |
| 4 | + * @urlRegex *://gitea.com/* |
| 5 | + */ |
| 6 | +'use strict' |
2 | 7 | /* global togglbutton, $ */ |
3 | 8 |
|
4 | | -togglbutton.render('.time-desc:not(.toggl)', |
| 9 | +togglbutton.render( |
| 10 | + '.time-desc:not(.toggl)', |
5 | 11 | { observe: true }, |
6 | | - $container => { |
| 12 | + ($container) => { |
7 | 13 | const link = togglbutton.createTimerLink({ |
8 | 14 | className: 'gitea', |
9 | 15 | description: descriptionSelector, |
10 | 16 | tags: tagsSelector, |
11 | 17 | projectName: projectSelector, |
12 | | - }); |
13 | | - $container.appendChild(link); |
| 18 | + }) |
| 19 | + $container.appendChild(link) |
| 20 | + }, |
| 21 | +) |
| 22 | + |
| 23 | +function descriptionSelector() { |
| 24 | + const description = document.getElementById('issue-title-display') |
| 25 | + if (!description) { |
| 26 | + return '' |
| 27 | + } |
| 28 | + |
| 29 | + const h1 = description.querySelector('h1') |
| 30 | + if (!h1) { |
| 31 | + return description.textContent.trim() |
14 | 32 | } |
15 | | -); |
16 | 33 |
|
17 | | -function descriptionSelector () { |
18 | | - const description = document.getElementById('issue-title'); |
19 | | - const issueId = description.nextElementSibling; |
20 | | - return `${issueId.textContent.trim()} ${description.textContent.trim()}`; |
| 34 | + let textContent = '' |
| 35 | + for (const node of h1.childNodes) { |
| 36 | + if (node.nodeType === Node.TEXT_NODE) { |
| 37 | + textContent += node.textContent |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + return textContent.trim() |
21 | 42 | } |
22 | 43 |
|
23 | | -function projectSelector () { |
24 | | - const $project = document.getElementsByClassName('repo-title')[0].children[3]; |
25 | | - return $project ? $project.textContent.trim() : ''; |
| 44 | +function projectSelector() { |
| 45 | + const issueContentRight = document.getElementsByClassName( |
| 46 | + 'issue-content-right', |
| 47 | + ) |
| 48 | + if (!issueContentRight || issueContentRight.length === 0) { |
| 49 | + return '' |
| 50 | + } |
| 51 | + |
| 52 | + const projectsSection = issueContentRight[0].querySelector( |
| 53 | + '[data-update-url*="projects"]', |
| 54 | + ) |
| 55 | + if (!projectsSection) { |
| 56 | + return '' |
| 57 | + } |
| 58 | + |
| 59 | + const selectedProject = projectsSection.querySelector('a.item.muted.checked') |
| 60 | + if (!selectedProject) { |
| 61 | + return '' |
| 62 | + } |
| 63 | + |
| 64 | + return selectedProject.textContent.trim() |
26 | 65 | } |
27 | 66 |
|
28 | | -function tagsSelector () { |
29 | | - const $tags = document.getElementsByClassName('labels-list')[0].children; |
30 | | - var $result = []; |
31 | | - for (var element of $tags) { |
32 | | - if (element.children.length > 0 && !element.children[0].classList.contains("hide")) { |
33 | | - $result.push(element.children[0].textContent.trim()); |
| 67 | +function tagsSelector() { |
| 68 | + const issueContentRight = document.getElementsByClassName( |
| 69 | + 'issue-content-right', |
| 70 | + )[0] |
| 71 | + if (!issueContentRight) { |
| 72 | + return [] |
| 73 | + } |
| 74 | + |
| 75 | + const labelsList = issueContentRight.getElementsByClassName('labels-list')[0] |
| 76 | + if (!labelsList) { |
| 77 | + return [] |
| 78 | + } |
| 79 | + |
| 80 | + const $result = [] |
| 81 | + const labelLinks = labelsList.querySelectorAll('a.item') |
| 82 | + |
| 83 | + for (const labelLink of labelLinks) { |
| 84 | + const labelSpan = labelLink.querySelector('span.ui.label') |
| 85 | + if (labelSpan) { |
| 86 | + const labelText = labelSpan.querySelector('span.gt-ellipsis') |
| 87 | + if (labelText) { |
| 88 | + const text = labelText.textContent.trim() |
| 89 | + $result.push(text) |
| 90 | + } |
34 | 91 | } |
35 | 92 | } |
36 | | - return $result; |
| 93 | + |
| 94 | + return $result |
37 | 95 | } |
0 commit comments