NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name tracker pullrequest // @namespace systech/tracker // @version 0.5 // @description add task from tfs to tracker // @author MT // @match https://tfssrv.systtech.ru/tfs/* // @grant none // @require https://raw.githubusercontent.com/uzairfarooq/arrive/master/minified/arrive.min.js // @copyright 2020, semapv (https://openuserjs.org/users/semapv) // @license MIT // ==/UserScript== function getFormattedTodayDate() { const today = new Date().toLocaleDateString('ru'); return today.split('.').reverse().join('-'); } function getFormattedCurrentTime() { const currentTime = new Date().toLocaleTimeString('ru', { hour: '2-digit', minute: '2-digit' }); return encodeURIComponent(currentTime); } function postDataToTracker(url, taskId, comment) { const formattedTodayDate = getFormattedTodayDate(); const trackerUrl = `${url}?date=${formattedTodayDate}`; const formattedCurrentTime = getFormattedCurrentTime(); return fetch(trackerUrl, { "headers": { "accept": "*/*", "accept-language": "ru,en-US;q=0.9,en;q=0.8", "content-type": "application/x-www-form-urlencoded", "sec-fetch-mode": "cors" }, "referrer": trackerUrl, "referrerPolicy": "strict-origin-when-cross-origin", "body": `Id=0&Date=${formattedTodayDate}&Begin=${formattedCurrentTime}&End=00%3A00&TaskId=${taskId}&Comment=${comment}`, "method": "POST", "mode": "no-cors", "credentials": "include" }); } function processResponse(response) { if (response.status === 200) { alert('Задача добавлена'); } else { alert('Произошла ошибка, попробуйте позже'); } } function addTaskToTracker() { const title = document.querySelector('[aria-label="Название запроса на вытягивание"]').value; const taskId = /^(\d+)(.*)/.exec(title)[1]; const comment = taskId == 63448 ? /^(\d+)(.*)/.exec(title)[2] : ''; if (!taskId) { alert('Не удалось определить ID задачи'); return; } postDataToTracker('https://tfssrv.systtech.ru/tracker/Home/Edit', taskId, comment) .then((res) => processResponse(res)) .catch((err) => alert('Произошла ошибка, попробуйте позже')); } function createButton(text) { const button = document.createElement('button'); button.classList.add('tracker-btn'); button.textContent = text; button.style.marginRight = '5px'; button.style.height = '26px'; button.style.backgroundColor = '#008CBA'; button.style.color = '#fff'; button.onclick = addTaskToTracker; return button; } function addButton(containerTag, text) { if (!document.querySelector('.tracker-btn')) { const infoNode = document.querySelector(containerTag); const button = createButton(text); infoNode.append(button); } } (function() { 'use strict'; const callback = (mutationsList) => { const prNode = document.querySelector('.repos-pr-details-page'); if (prNode !== null) { const prButtonsContainer = '.repos-pr-title-row'; addButton(prButtonsContainer, 'Добавить в трекер') } }; const observer = new MutationObserver(callback); const config = { childList: true, subtree: true }; observer.observe(document.body, config); })();