Toggl-Button YouTrack

Toggle button for YouTrack

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Toggl-Button YouTrack
// @namespace   https://gitlab.paragon-es.de/toggl-button
// @version     1.4
// @include     http*://youtrack.*/*
// @include     http*://*/youtrack/*
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_info
// @grant       GM_registerMenuCommand
// @require     https://greatest.deepsurf.us/scripts/2670-toggllibrary/code/TogglLibrary.js
// @resource    togglStyle https://gitlab.paragon-es.de/toggl-button/core/raw/master/TogglLibrary.css
// @description Toggle button for YouTrack
// ==/UserScript==

new TogglButtonGM('.fsi-layout.container .content_fsi', function (elem) {
  var description, projectIds = [],
    numElem = elem.querySelector('.issueId', elem),
    titleElem = elem.querySelector('.issue-summary', elem),
    projectElem = document.querySelector('.fsi-properties .fsi-property .regCC a'),
    linkElem = document.querySelector('.issueContainer .links-panel .links .link'),
    stopCallback = null;

  description = titleElem.textContent.trim();
  if (numElem !== null) {
    description = numElem.textContent.trim() + " " + description;
    stopCallback = function(date, duration) {
      var parts = numElem.textContent.trim().split('-');
      GM_xmlhttpRequest({
        method: "GET",
        url: document.location.origin + "/rest/admin/project/" + parts[0] + "/timetracking",
        onload: function (result) {
          if (result.status === 200) {
            if (result.responseText.indexOf('<settings enabled="true">') > 0) {
              GM_xmlhttpRequest({
                method: "POST",
                url: document.location.origin + "/rest/issue/" + numElem.textContent.trim() + "/timetracking/workitem",
                headers: {
                  "Content-Type": "application/xml"
                },
                dataType: 'xml',
                data: '<workItem><date>'+date+'</date><duration>'+Math.floor(duration / 60)+'</duration><description>automatic</description></workItem>'
              });
            }
          }
        }
      });
    }
  }

  if (projectElem !== null) {
    projectIds.push(projectElem.textContent.trim());
  }
  if (linkElem !== null) {
    projectIds.push(linkElem.textContent.trim());
  }

  return {
    className: 'youtrack',
    description: description,
    projectIds: projectIds,
    stopCallback: stopCallback
  };
});