@@ -92,21 +92,6 @@ function hideMenu() {
9292 menu . hidePopover ( ) ;
9393}
9494
95- // Since chromes implementation of the popup is dumb, we can't position
96- // it correctly without javascript.
97- if ( ! navigator . userAgent . toLowerCase ( ) . includes ( "firefox" ) ) {
98- const menu_button = document . getElementById ( "menu-button" ) ;
99- menu . addEventListener ( "toggle" , ( event ) => {
100- if ( event . newState === "open" ) {
101- const bounds = menu_button . getBoundingClientRect ( ) ;
102- // Technically this won't correctly handle the scrolling
103- // position, but we'll cope for now.
104- menu . style . top = bounds . bottom + "px" ;
105- menu . style . left = bounds . left + "px" ;
106- }
107- } ) ;
108- }
109-
11095function showDialog ( id , title , contentNode , buttonBar ) {
11196 hideMenu ( ) ;
11297
@@ -999,21 +984,23 @@ const handleEvent = (parsed) => {
999984
1000985 // We don't do this in applyWordHints because that's called in all kinds of places
1001986 if ( parsed . data . some ( ( hint ) => hint . character ) ) {
1002- var hints = parsed . data . map ( ( hint ) => {
1003- if ( hint . character ) {
1004- var char = String . fromCharCode ( hint . character ) ;
1005- if ( char === " " || hint . revealed ) {
1006- return char ;
1007- }
1008- }
1009- return "_" ;
1010- } ) . join ( " " ) ;
1011- appendMessage (
1012- [ "system-message" , "hint-chat-message" ] ,
1013- '{{.Translation.Get "system"}}' ,
1014- '{{.Translation.Get "word-hint-revealed"}}\n' + hints ,
1015- { "dir" : wordContainer . getAttribute ( "dir" ) } ,
1016- ) ;
987+ var hints = parsed . data
988+ . map ( ( hint ) => {
989+ if ( hint . character ) {
990+ var char = String . fromCharCode ( hint . character ) ;
991+ if ( char === " " || hint . revealed ) {
992+ return char ;
993+ }
994+ }
995+ return "_" ;
996+ } )
997+ . join ( " " ) ;
998+ appendMessage (
999+ [ "system-message" , "hint-chat-message" ] ,
1000+ '{{.Translation.Get "system"}}' ,
1001+ '{{.Translation.Get "word-hint-revealed"}}\n' + hints ,
1002+ { dir : wordContainer . getAttribute ( "dir" ) } ,
1003+ ) ;
10171004 }
10181005 } else if ( parsed . type === "message" ) {
10191006 appendMessage ( null , parsed . data . author , parsed . data . content ) ;
@@ -1409,11 +1396,11 @@ function appendMessage(styleClass, author, message, attrs) {
14091396 const newMessageDiv = document . createElement ( "div" ) ;
14101397 newMessageDiv . classList . add ( "message" ) ;
14111398 if ( isString ( styleClass ) ) {
1412- styleClass = [ styleClass ] ;
1399+ styleClass = [ styleClass ] ;
14131400 }
14141401
1415- for ( const cls of styleClass ) {
1416- newMessageDiv . classList . add ( cls ) ;
1402+ for ( const cls of styleClass ) {
1403+ newMessageDiv . classList . add ( cls ) ;
14171404 }
14181405
14191406 if ( author !== null && author !== "" ) {
@@ -1429,11 +1416,11 @@ function appendMessage(styleClass, author, message, attrs) {
14291416 newMessageDiv . appendChild ( messageSpan ) ;
14301417
14311418 if ( attrs !== null && attrs !== "" ) {
1432- if ( isObject ( attrs ) ) {
1433- for ( const [ attrKey , attrValue ] of Object . entries ( attrs ) ) {
1434- messageSpan . setAttribute ( attrKey , attrValue ) ;
1419+ if ( isObject ( attrs ) ) {
1420+ for ( const [ attrKey , attrValue ] of Object . entries ( attrs ) ) {
1421+ messageSpan . setAttribute ( attrKey , attrValue ) ;
1422+ }
14351423 }
1436- }
14371424 }
14381425
14391426 messageContainer . appendChild ( newMessageDiv ) ;
@@ -1608,17 +1595,16 @@ function updateRoundsDisplay() {
16081595const applyWordHints = ( wordHints , dummy ) => {
16091596 const isDrawer = drawerID === ownID ;
16101597
1611- // We abuse the container to prevent the layout from jumping.
1612- if ( ! dummy ) {
1613- wordContainer . style . visibility = "visible" ;
1614- } else {
1615- wordContainer . style . visibility = "hidden" ;
1616- }
1598+ let wordLengths = [ ] ;
1599+ let count = 0 ;
16171600
16181601 wordContainer . replaceChildren (
1619- ...wordHints . map ( ( hint ) => {
1602+ ...wordHints . map ( ( hint , index ) => {
16201603 const hintSpan = document . createElement ( "span" ) ;
16211604 hintSpan . classList . add ( "hint" ) ;
1605+ if ( dummy ) {
1606+ hintSpan . style . visibility = "hidden" ;
1607+ }
16221608 if ( hint . character === 0 ) {
16231609 hintSpan . classList . add ( "hint-underline" ) ;
16241610 hintSpan . innerHTML = " " ;
@@ -1629,13 +1615,33 @@ const applyWordHints = (wordHints, dummy) => {
16291615 hintSpan . innerText = String . fromCharCode ( hint . character ) ;
16301616 }
16311617
1618+ // space
1619+ if ( hint . character === 32 ) {
1620+ wordLengths . push ( count ) ;
1621+ count = 0 ;
1622+ } else if ( index === wordHints . length - 1 ) {
1623+ count += 1 ;
1624+ wordLengths . push ( count ) ;
1625+ } else {
1626+ count += 1 ;
1627+ }
1628+
16321629 if ( hint . revealed && isDrawer ) {
16331630 hintSpan . classList . add ( "hint-revealed" ) ;
16341631 }
16351632
16361633 return hintSpan ;
16371634 } ) ,
16381635 ) ;
1636+
1637+ const lengthHint = document . createElement ( "sub" ) ;
1638+ lengthHint . classList . add ( "word-length-hint" ) ;
1639+ if ( dummy ) {
1640+ lengthHint . style . visibility = "hidden" ;
1641+ }
1642+ lengthHint . setAttribute ( "dir" , wordContainer . getAttribute ( "dir" ) ) ;
1643+ lengthHint . innerText = `(${ wordLengths . join ( ", " ) } )` ;
1644+ wordContainer . appendChild ( lengthHint ) ;
16391645} ;
16401646
16411647const set_dummy_word_hints = ( ) => {
@@ -2027,14 +2033,16 @@ function getCookie(name) {
20272033}
20282034
20292035function isString ( obj ) {
2030- return typeof obj === ' string' ;
2036+ return typeof obj === " string" ;
20312037}
20322038
20332039function isObject ( obj ) {
2034- return typeof obj === 'object' &&
2035- obj !== null &&
2036- ! Array . isArray ( obj ) &&
2037- Object . prototype . toString . call ( obj ) === '[object Object]' ;
2040+ return (
2041+ typeof obj === "object" &&
2042+ obj !== null &&
2043+ ! Array . isArray ( obj ) &&
2044+ Object . prototype . toString . call ( obj ) === "[object Object]"
2045+ ) ;
20382046}
20392047
20402048const connectToWebsocket = ( ) => {
0 commit comments