@@ -442,6 +442,32 @@ export var ReportBrokenSite = new (class ReportBrokenSite {
442
442
this . #newReportEndpoint = this . newReportEndpointPref ;
443
443
}
444
444
445
+ #random( seed ) {
446
+ let x = Math . sin ( seed ) * 10000 ;
447
+ return x - Math . floor ( x ) ;
448
+ }
449
+
450
+ #shuffleArray( array ) {
451
+ const seed = Math . round ( new Date ( ) . getTime ( ) ) ;
452
+ for ( let i = array . length - 1 ; i > 0 ; i -- ) {
453
+ const j = Math . floor ( this . #random( seed ) * ( i + 1 ) ) ;
454
+ [ array [ i ] , array [ j ] ] = [ array [ j ] , array [ i ] ] ;
455
+ }
456
+ }
457
+
458
+ #randomizeDropdownItems( dropdown ) {
459
+ if ( ! dropdown ) {
460
+ return ;
461
+ }
462
+
463
+ // Leave the first option ("choose reason") at the start
464
+ const items = Array . from (
465
+ dropdown . querySelectorAll ( `menuitem:not(:first-of-type)` )
466
+ ) ;
467
+ this . #shuffleArray( items ) ;
468
+ items [ 0 ] . parentNode . append ( ...items ) ;
469
+ }
470
+
445
471
#initMainView( state ) {
446
472
state . sendButton . addEventListener ( "command" , async ( { target } ) => {
447
473
if ( state . checkAndShowInputValidity ( ) ) {
@@ -473,6 +499,8 @@ export var ReportBrokenSite = new (class ReportBrokenSite {
473
499
state . showOrHideReasonValidationMessage ( ) ;
474
500
} ) ;
475
501
502
+ this . #randomizeDropdownItems( reasonDropdown ) ;
503
+
476
504
const menupopup = reasonDropdown . querySelector ( "menupopup" ) ;
477
505
const onDropDownShowOrHide = ( { type } ) => {
478
506
// Hide "choose a reason" while the user has the reason dropdown open
0 commit comments