import { haveVotedOnQuestion } from './haveVotedOnQuestion' ; import { getSettings } from './settings' ; const tryShowButton = ( textContainer , okButton ) => { const { downvoteCondition } = getSettings ( ) ; if ( downvoteCondition === 'Never' || ( downvoteCondition === 'Non-dupes only' && textContainer . dataset . closeReasonId === 'Duplicate' ) ) { return false ; } okButton . style . visibility = 'visible' ; return true ; } ; export const showOkButtonWhenHovered = ( vtcContainer ) => { const downvoteButton = document . querySelector < HTMLElement > ( '.question .js-vote-down-btn' ) ! ; const showImminentDownvote = ( ) => { if ( ! haveVotedOnQuestion ( ) ) { downvoteButton . setAttribute ( 'data-cpuserscript-one-click-vtc-imminent-downvote' , '' ) ; } } ; const noImminentDownvote = ( ) => { downvoteButton . removeAttribute ( 'data-cpuserscript-one-click-vtc-imminent-downvote' ) ; } ; for ( const textContainer of ( vtcContainer . querySelectorAll < HTMLElement > ( '[data-close-reason-id]' ) ) ) { const okButton = textContainer . previousElementSibling as HTMLElement ; okButton . addEventListener ( 'mouseenter' , ( ) => { tryShowButton ( textContainer , okButton ) ; noImminentDownvote ( ) ; } ) ; okButton . addEventListener ( 'mouseleave' , ( e ) => { if ( e . relatedTarget !== textContainer ) { okButton . removeAttribute ( 'style' ) ; } } ) ; textContainer . addEventListener ( 'mouseenter' , ( ) => { if ( tryShowButton ( textContainer , okButton ) ) { showImminentDownvote ( ) ; } } ) ; textContainer . addEventListener ( 'mouseleave' , ( e ) => { if ( e . relatedTarget !== okButton ) { okButton . removeAttribute ( 'style' ) ; noImminentDownvote ( ) ; } } ) ; } } ;