NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name eZ Service Desk UserScript // @version 1.0 // @namespace https://jira.ez.no/servicedesk // @description eZ Service Desk UserScript // @include https://jira.ez.no/servicedesk/agent/CS/* // @include https://jira.ez.no/browse/CS* // @require https://code.jquery.com/jquery-2.1.4.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant none // ==/UserScript== // This is needed to prevent conflicts between webpage and GM's jquery this.$ = this.jQuery = jQuery.noConflict(true); var signature = { name: "Eduardo Fernandes", position: "Product Support Engineer", extra: "\neZ Enterprise v1.4 is now available, Easier to Build a Solid Content Business\n[ezstudio.com|http://ezstudio.com]" } // extend with setCursorPosition() func, (allows moving carrot to top) $.fn.setCursorPosition = function(pos) { this.each(function(index, elem) { if (elem.setSelectionRange) { elem.setSelectionRange(pos, pos); } else if (elem.createTextRange) { var range = elem.createTextRange(); range.collapse(true); range.moveEnd('character', pos); range.moveStart('character', pos); range.select(); } }); return this; }; // pre-fill signature when clicking to add a new comment. function prefillSignature(){ var input = $('.sd-comment-textarea'); if ( input.val() == "" ) { var sigText = "\n\n--\n" + signature.name + "\n" + signature.position + signature.extra; input.html( sigText ); input.setCursorPosition(0); } }; // format date to relative "nn minutes/hours/days ago" function relativeDateFormat(datetime, fallback) { var msPerMinute = 60 * 1000; var msPerHour = msPerMinute * 60; var msPerDay = msPerHour * 24; var msPerWeek = msPerDay * 7; var msPerMonth = msPerDay * 30; var msPerYear = msPerDay * 365; var current = new Date(); var elapsed = current - datetime; if (elapsed < msPerMinute) { return Math.round(elapsed/1000) + ' seconds ago'; } else if (elapsed < msPerHour) { return Math.round(elapsed/msPerMinute) + ' minutes ago'; } else if (elapsed < msPerDay ) { return Math.round(elapsed/msPerHour ) + ' hours ago'; } else if (elapsed < msPerMonth) { return Math.round(elapsed/msPerDay) + ' days ago'; } else { return fallback; } } $('#sd-comment-collapsed-textarea').focus( prefillSignature ); waitForKeyElements( '.sd-comment-textarea', prefillSignature ); waitForKeyElements( '#issuetable', function() { $('#issuetable .issuerow .updated').each( function() { var label = $('span', this); var time = $('time', this); // get readable datetime from tooltip var readable = label.attr('title'); // get date from time attribute var dtime = new Date( time.attr('datetime') ); time.html( relativeDateFormat( dtime, time.html() ) ); }); } );