11// ==UserScript==
22// @name GitHub Commit Labels
33// @namespace https://github.com/nazdridoy
4- // @version 1.2.2
4+ // @version 1.3.0
55// @description Enhances GitHub commits with beautiful labels for conventional commit types (feat, fix, docs, etc.)
66// @author nazdridoy
77// @license MIT
@@ -157,6 +157,7 @@ SOFTWARE.
157157 removePrefix : true ,
158158 enableTooltips : true ,
159159 labelsVisible : true ,
160+ showScope : false ,
160161 labelStyle : {
161162 fontSize : '14px' ,
162163 fontWeight : '500' ,
@@ -603,6 +604,21 @@ SOFTWARE.
603604
604605 configWindow . insertBefore ( floatingBtnDiv , tooltipDiv . nextSibling ) ;
605606
607+ // After the tooltipDiv and before the floatingBtnDiv in the createConfigWindow function:
608+ const scopeDiv = document . createElement ( 'div' ) ;
609+ scopeDiv . style . marginBottom = '20px' ;
610+ const scopeCheckbox = document . createElement ( 'input' ) ;
611+ scopeCheckbox . type = 'checkbox' ;
612+ scopeCheckbox . checked = USER_CONFIG . showScope ;
613+ scopeCheckbox . id = 'show-scope' ;
614+ scopeCheckbox . style . marginRight = '5px' ;
615+ const scopeLabel = document . createElement ( 'label' ) ;
616+ scopeLabel . htmlFor = 'show-scope' ;
617+ scopeLabel . textContent = 'Show commit scope in labels (e.g., "feat(api): message" shows "api" in label)' ;
618+ scopeDiv . appendChild ( scopeCheckbox ) ;
619+ scopeDiv . appendChild ( scopeLabel ) ;
620+ configWindow . insertBefore ( scopeDiv , floatingBtnDiv . nextSibling ) ;
621+
606622 // Commit Types Configuration
607623 const typesContainer = document . createElement ( 'div' ) ;
608624 typesContainer . style . marginBottom = '20px' ;
@@ -938,6 +954,7 @@ SOFTWARE.
938954 newConfig . removePrefix = prefixCheckbox . checked ;
939955 newConfig . enableTooltips = tooltipCheckbox . checked ;
940956 newConfig . showFloatingButton = floatingBtnCheckbox . checked ;
957+ newConfig . showScope = scopeCheckbox . checked ;
941958 newConfig . commitTypes = { } ;
942959
943960 typesContainer . querySelectorAll ( 'input, select' ) . forEach ( input => {
@@ -1209,18 +1226,20 @@ SOFTWARE.
12091226 for ( let i = startIndex ; i < endIndex ; i ++ ) {
12101227 const message = commitMessagesArray [ i ] ;
12111228 const text = message . textContent . trim ( ) ;
1212- const match = text . match ( / ^ ( \w + ) (?: \( [ \w - ] + \) ) ? : \s * ( .* ) / ) ;
1229+ const match = text . match ( / ^ ( \w + ) (?: \( ( [ \w - ] + ) \) ) ? : \s * ( .* ) / ) ;
12131230
12141231 if ( match ) {
12151232 const type = match [ 1 ] . toLowerCase ( ) ;
1216- const restOfMessage = match [ 2 ] ;
1233+ const scope = match [ 2 ] || '' ;
1234+ const restOfMessage = match [ 3 ] ;
12171235
12181236 if ( USER_CONFIG . commitTypes [ type ] ) {
12191237 // Only add label if it hasn't been added yet
12201238 if ( ! message . parentElement . querySelector ( '.commit-label' ) ) {
12211239 const label = document . createElement ( 'span' ) ;
12221240 label . className = 'commit-label' ;
12231241 label . dataset . commitType = type ;
1242+ label . dataset . commitScope = scope ;
12241243
12251244 const color = COLORS [ USER_CONFIG . commitTypes [ type ] . color ] ;
12261245
@@ -1239,8 +1258,12 @@ SOFTWARE.
12391258 // Enhanced tooltip
12401259 if ( USER_CONFIG . enableTooltips && USER_CONFIG . commitTypes [ type ] . description ) {
12411260 // Store description in data attribute instead of title to avoid double tooltips
1242- label . dataset . description = USER_CONFIG . commitTypes [ type ] . description ;
1243- label . setAttribute ( 'aria-label' , USER_CONFIG . commitTypes [ type ] . description ) ;
1261+ const description = USER_CONFIG . commitTypes [ type ] . description ;
1262+ const tooltipText = scope ?
1263+ `${ description } (Scope: ${ scope } )` :
1264+ description ;
1265+ label . dataset . description = tooltipText ;
1266+ label . setAttribute ( 'aria-label' , tooltipText ) ;
12441267
12451268 // Add tooltip indicator
12461269 label . style . cursor = 'help' ;
@@ -1339,6 +1362,17 @@ SOFTWARE.
13391362 if ( USER_CONFIG . removePrefix ) {
13401363 message . textContent = restOfMessage ;
13411364 }
1365+
1366+ // Optionally display scope in the label
1367+ if ( scope && USER_CONFIG . showScope ) {
1368+ const scopeSpan = document . createElement ( 'span' ) ;
1369+ scopeSpan . className = 'commit-scope' ;
1370+ scopeSpan . textContent = `(${ scope } )` ;
1371+ scopeSpan . style . marginLeft = '2px' ;
1372+ scopeSpan . style . opacity = '0.8' ;
1373+ scopeSpan . style . fontSize = '12px' ;
1374+ labelText . appendChild ( scopeSpan ) ;
1375+ }
13421376 }
13431377 }
13441378 }
0 commit comments