1+ console . log ( ".~. begin .~." ) ;
2+
3+ function getTaskCards ( ) {
4+ return $ ( "div.task-card-actions-container" ) ;
5+ }
6+
7+ function copy ( message ) {
8+ var $temp = $ ( "<div>" ) ;
9+ $ ( "body" ) . append ( $temp ) ;
10+ $temp . attr ( "contenteditable" , true )
11+ . html ( message ) . select ( )
12+ . on ( "focus" , function ( ) {
13+ document . execCommand ( 'selectAll' , false , null )
14+ } )
15+ . focus ( ) ;
16+ document . execCommand ( "copy" ) ;
17+ $temp . remove ( ) ;
18+ }
19+
20+ function generateAndCopyMessage ( ) {
21+ var taskId = $ . trim ( $ ( "div.toolbar>h2" ) . text ( ) ) . replace ( "Task " , "" ) ;
22+ var taskDesc = $ ( "h1.title textarea" ) . text ( ) ;
23+
24+ var type ;
25+ if ( $ ( "div.main-panel-scroller a[rel^='Story']" ) . length > 0 ) {
26+ type = "Story" ;
27+ } else if ( $ ( "div.main-panel-scroller a[rel^='Defect']" ) . length > 0 ) {
28+ type = "Defect" ;
29+ }
30+ var storyInternalId = $ ( "div.main-panel-scroller a[rel^='" + type + "']" ) [ 0 ] . rel ;
31+ var storyId = $ . trim ( $ ( "tr[rowid='" + storyInternalId + "'] span.number" ) . text ( ) ) ;
32+ var storyDesc = $ ( "div.main-panel-scroller a[rel^='" + type + "']>span" ) . text ( ) ;
33+
34+ var message = storyId + " [" + taskId + "] " + storyDesc + " [" + taskDesc + "] ..." ;
35+ copy ( message ) ;
36+
37+ // add notification here
38+ }
39+
40+ function handleButtonClick ( event ) {
41+ var button = $ ( event . target ) ;
42+ var taskCard = button . parents ( "div.task-card:first" ) ;
43+ taskCard . find ( "a.open-by-name.asset-name-link:first" ) [ 0 ] . click ( ) ;
44+
45+ var nTimer = setInterval ( function ( ) {
46+ if ( $ ( "div.toolbar" ) . length > 0 ) {
47+ clearInterval ( nTimer ) ;
48+ generateAndCopyMessage ( ) ;
49+ }
50+ } , 300 ) ;
51+ }
52+
53+ function addCopyActionButton ( ) {
54+ $ ( "div.task-card" ) . css ( "min-height" , "5em" ) ;
55+ var taskActionsDivs = getTaskCards ( ) ;
56+ taskActionsDivs . each ( function ( idx ) {
57+ var button = $ ( "<a></a>" , {
58+ class : "task-card-actions version-ninja" ,
59+ text : "C" ,
60+ title : "Copy to clipboard as commit message"
61+ } ) ;
62+ button . click ( handleButtonClick ) ;
63+ button . appendTo ( $ ( this ) ) ;
64+ } ) ;
65+ }
66+
67+ function main ( ) {
68+ $ ( "a.version-ninja" ) . remove ( ) ;
69+ addCopyActionButton ( ) ;
70+ }
71+
72+
73+ $ ( function ( ) {
74+ var nTimer = setInterval ( function ( ) {
75+ if ( getTaskCards ( ) . length > 1 ) {
76+ clearInterval ( nTimer ) ;
77+ main ( ) ;
78+ }
79+ } , 500 ) ;
80+ } ) ;
81+
82+ console . log ( "+#+ end +#+" ) ;
0 commit comments