From 49a21bed3917dcc7c677090ed080ca5548488e89 Mon Sep 17 00:00:00 2001 From: Oleksiy Demchenko Date: Tue, 27 Feb 2024 10:48:26 +0100 Subject: [PATCH] fix: Integration GitLab WOB-2728 --- public/scripts/content-scripts/gitlab.js | 168 +++++++++++++---------- 1 file changed, 98 insertions(+), 70 deletions(-) diff --git a/public/scripts/content-scripts/gitlab.js b/public/scripts/content-scripts/gitlab.js index c2cd019..89adf05 100644 --- a/public/scripts/content-scripts/gitlab.js +++ b/public/scripts/content-scripts/gitlab.js @@ -1,86 +1,114 @@ function insertAfter(el, referenceNode) { - referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling); + referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling); } -wobblyButton.renderButton('.issue-details .detail-page-description', function(elem){ - const rootElement = searchElem(elem); - if (!rootElement) return; +wobblyButton.renderButton('.issue-details .detail-page-description', function (elem) { + const rootElement = searchElem(elem); + if (!rootElement) return; - const getNumTaskText = () => { - const numTask = searchElem('.breadcrumbs-links li:last-child a'); - return numTask ? numTask.textContent.split(' ').pop() : ''; - } + const getNumTaskText = () => { + const numTask = searchElem('.breadcrumbs-links li:last-child a'); + return numTask ? numTask.textContent.split(' ').pop() : ''; + }; - const getDetailTask = () => { - const detailTask = searchElem('.title', rootElement); - return detailTask ? detailTask.textContent : ''; - } + const getDetailTask = () => { + const detailTask = searchElem('.title', rootElement); + return detailTask ? detailTask.textContent : ''; + }; - wobblyButton.detail = getDetailTask(); - wobblyButton.task = getNumTaskText(); - wobblyButton.issue = `${wobblyButton.task} ${wobblyButton.detail}`; + wobblyButton.detail = getDetailTask(); + wobblyButton.task = getNumTaskText(); + wobblyButton.issue = `${wobblyButton.task} ${wobblyButton.detail}`; - let container = searchElem('.detail-page-header-body'); - let link = createTag('a', 'wobbly', 'Start timer') - link.style.cursor = 'pointer' - link.style = ` + let container = searchElem('.detail-page-header-body'); + let link = createTag('a', 'wobbly', 'Start timer'); + link.style.cursor = 'pointer'; + link.style = ` cursor: pointer; padding-left: 20px; - background: url(${chrome.extension.getURL("images/favicon.svg")}) no-repeat; - background-position: -13px 50%; + margin-left: auto; + margin-right: 5px; + font-weight: 600; + background: url(${chrome.extension.getURL('images/favicon.svg')}) no-repeat; + background-position: -14px 45%; background-size: 50% 50%; - ` - insertAfter(link,container); - container.appendChild(link); - - link.onclick = () => { - wobblyButton.currentTimer ? wobblyButton.timerStop() : wobblyButton.timerStart(`${getNumTaskText()} ${getDetailTask()}`); - } - - link.title = `${getNumTaskText()} ${getDetailTask()}`; - - wobblyButton.link = link; - if(link) { - const firstLink = container.getElementsByClassName('wobbly'); - firstLink[0].style = `display: none;`; - } -}) - -wobblyButton.renderButton('.merge-request-details .detail-page-description', function(elem){ - let rootElement = searchElem(elem) - if(!rootElement) return - - const getNumTaskText = () => { - const numTask = searchElem('.breadcrumbs-links li:last-child a'); - return numTask ? numTask.textContent.split(' ').pop() : ''; - } - - const getDetailTask = () => { - const detailTask = searchElem('h1.title'); - return detailTask ? detailTask.textContent : ''; - } - - wobblyButton.detail = getDetailTask(); - wobblyButton.task = getNumTaskText(); - wobblyButton.issue = `${wobblyButton.task} ${wobblyButton.detail}`; - - let container = searchElem('.detail-page-header-body'); - let link = createTag('a', 'wobbly', 'Start timer') - link.style.cursor = 'pointer' - link.style = ` + `; + + // Цвета для ссылки при наведении и при отведении курсора + link.addEventListener('mouseover', function () { + this.style.color = '#1f75cb'; + }); + + link.addEventListener('mouseout', function () { + this.style.color = '#333238'; + }); + + insertAfter(link, container); + container.appendChild(link); + + link.onclick = () => { + wobblyButton.currentTimer + ? wobblyButton.timerStop() + : wobblyButton.timerStart(`${getNumTaskText()} ${getDetailTask()}`); + }; + + link.title = `${getNumTaskText()} ${getDetailTask()}`; + + wobblyButton.link = link; + if (link) { + const firstLink = container.getElementsByClassName('wobbly'); + firstLink[0].style = `display: none;`; + } +}); + +wobblyButton.renderButton('.merge-request-details .detail-page-description', function (elem) { + let rootElement = searchElem(elem); + if (!rootElement) return; + + const getNumTaskText = () => { + const numTask = searchElem('.breadcrumbs-links li:last-child a'); + return numTask ? numTask.textContent.split(' ').pop() : ''; + }; + + const getDetailTask = () => { + const detailTask = searchElem('h1.title'); + return detailTask ? detailTask.textContent : ''; + }; + + wobblyButton.detail = getDetailTask(); + wobblyButton.task = getNumTaskText(); + wobblyButton.issue = `${wobblyButton.task} ${wobblyButton.detail}`; + + let container = searchElem('.detail-page-header-body'); + let link = createTag('a', 'wobbly', 'Start timer'); + link.style.cursor = 'pointer'; + link.style = ` cursor: pointer; + min-width: 100px; + margin-bottom: auto; + font-weight: 600; padding-left: 20px; - background: url(${chrome.extension.getURL("images/favicon.svg")}) no-repeat; - background-position: -13px 50%; + background: url(${chrome.extension.getURL('images/favicon.svg')}) no-repeat; + background-position: -16px 45%; background-size: 50% 50%; - ` - container.appendChild(link); + `; - link.onclick = () => { - wobblyButton.currentTimer ? wobblyButton.timerStop() : wobblyButton.timerStart(`${getNumTaskText()} ${getDetailTask()}`); - } + link.addEventListener('mouseover', function () { + this.style.color = '#1f75cb'; // Замените на нужный цвет + }); - link.title = `${getNumTaskText()} ${getDetailTask()}`; + link.addEventListener('mouseout', function () { + this.style.color = '#333238'; // Замените на исходный цвет текста + }); + container.appendChild(link); - wobblyButton.link = link; -}) + link.onclick = () => { + wobblyButton.currentTimer + ? wobblyButton.timerStop() + : wobblyButton.timerStart(`${getNumTaskText()} ${getDetailTask()}`); + }; + + link.title = `${getNumTaskText()} ${getDetailTask()}`; + + wobblyButton.link = link; +});