Jira-CopyTitle

Adds a "Copy Task Title" button to the right of the "Workflow" dropdown in Jira.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Jira-CopyTitle
// @namespace    https://github.com/Tharkis/Userscript-Jira-CopyTitle/blob/master/Userscript-Jira-CopyTitle.js
// @version      0.1.0
// @description  Adds a "Copy Task Title" button to the right of the "Workflow" dropdown in Jira.
// @author       Joe Etten
// @license      MIT
// @match        https://*.atlassian.net/secure/*
// @match        https://*.atlassian.net/browse/*
// @grant        none

// @require      https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.min.js

// ==/UserScript==

(function($, JIRA) {
    'use strict';

    function addCopyButton() {
      // console.info('addCopyButton');

      if(!$('#clipboardBtn').next().length) {
        $('#clipboardBtn').remove();
        var container = $("#THIRD_PARTY_TAB .call-to-actions, .toolbar-split-left");
        container.append("<a id='clipboardBtn' class='btn aui-button aui-button-primary aui-style'>Copy Task Title</a>");
      }
    }

    function getIssueFullTitle () {
      var issueKey = "";
      var issueTitle = $('#summary-val').text();
      if($('#issuekey-val').length){
        issueKey = $('#issuekey-val').text();
      }
      if($('#key-val').length){
        issueKey = $('#key-val').text();
      }

      return issueKey + ' - ' + issueTitle;
    }

    function handleCopyButton () {

      var clipboard = new Clipboard('#clipboardBtn', {
        text: function(trigger) {
          return getIssueFullTitle();
        }
      });

      clipboard.on('success', function(e) {
        $.notify("Copied to clipboard", "success");
        $.notify(getIssueFullTitle(), "success");
      });

      clipboard.on('error', function(e) {
        $.notify("Access granted", "error");
      });
    }

    function init() {
      // console.info("init");
      updateHandlers();
      handleCopyButton();
      addCopyButton();

      JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function() {
        updateHandlers();
      });
    }

    function updateHandlers() {
      addCopyButton();
    }

    // init when page ready
    document.onreadystatechange = function() {
      if (document.readyState == "complete") {
        init();
      }
    };


})(window.$, window.JIRA);