Copy Redmine task title

Copy Redmine task title to clipboard

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name Copy Redmine task title
// @namespace Redmine
// @icon https://dev.sun-asterisk.com/favicon.ico?1528612569
// @description Copy Redmine task title to clipboard
// @run-at document-start
// @match *://dev.sun-asterisk.com/issues/*
// @match *://*redmine.sun-asterisk.vn/issues/*
// @grant GM_setClipboard
// @grant GM_notification
// @version 1.1.2
// ==/UserScript==

document.addEventListener("DOMContentLoaded", function(event) {
    var contentEl = $('#content'),
        ticketNumber = contentEl.children('.contextual').siblings('h2').text(),
        ticketTitle = contentEl.find('.subject h3').text(),
        ticketURL = location.protocol + '//' + location.host + location.pathname,
        progress = contentEl.find('.attributes .percent')[0]?.outerText || contentEl.find('.us-progr-text')[0]?.outerText;
    contentEl.find('.icon-copy').closest('.contextual').append('<a class="icon icon-copy update-resolve-auto" href="#">Resolved to me</a>');
    contentEl.find('.icon-copy').closest('.contextual').append('<a class="icon icon-copy ticket-url" href="#">Ticket URL</a>');
    contentEl.find('.icon-copy').closest('.contextual').append('<a class="icon icon-copy icon-copy-to-clipboard" href="#">Report</a>');
    $('.icon-copy-to-clipboard').on('click', function () {
        var textToCopy = '- ' + ticketNumber + ' - ' + ticketTitle + ' ' + '(' + ticketURL + ')';
        if (progress.split('%')[0] > 0) { textToCopy += ' => (' + progress  + ')'; }
        GM_setClipboard(textToCopy);
        GM_notification ( {title: 'Redmine report copied', text: textToCopy, image: 'https://dev.sun-asterisk.com/favicon.ico?1528612569'} );
        textToCopy = '';
    });
    $('.ticket-url').on('click', function () {
        GM_setClipboard(ticketURL);
        GM_notification ( {title: 'Redmine URL copied', text: ticketURL, image: 'https://dev.sun-asterisk.com/favicon.ico?1528612569'} );
    });
    $('.update-resolve-auto').on('click', function () {
        $('#issue_done_ratio').val(80);
        $('#issue_status_id').val(3);
        $('#issue_assigned_to_id').val(1579);
        $('#issue-form').submit();
    });
});