import { getSettings } from './settings' ; export const canCreateInterface = ( ) => { const myProfile = document . querySelector < HTMLAnchorElement > ( '.my-profile' ) ; if ( ! myProfile ) { return ; } const myProfileLink = myProfile . getAttribute ( 'href' ) ; const { rep } = window . StackExchange . options . user ; if ( rep < 15 ) { console . error ( `Stack One Click VTC: Need 15 rep to flag and 3000 to close, but you only have ${ rep }` ) ; return ; } const stillVisiblePersonalAnswerAuthorAnchor = document . querySelector ( `.answer:not(.deleted-answer) .user-details[itemprop="author"] a[href^="${ myProfileLink }"]` ) ; if ( stillVisiblePersonalAnswerAuthorAnchor ) { return ; } if ( document . querySelector ( `.owner a[href^="${ myProfileLink }"]` ) ) { return ; } const emptySpaceToLeftOfContent = document . querySelector < HTMLElement > ( '.container' ) ! . getBoundingClientRect ( ) . left ; if ( emptySpaceToLeftOfContent < 250 ) { console . warn ( `Not enough space to put Stack One Click VTC interface to left of main content: 250px required, ${ Math . floor ( emptySpaceToLeftOfContent ) }px found` ) ; if ( document . querySelector < HTMLElement > ( '#left-sidebar' ) ! . offsetParent !== null ) { console . warn ( 'Consider disabling the left sidebar at https://stackoverflow.com/users/preferences/' ) ; } console . warn ( 'To acquire more space, consider installing Stack Right Content: https://github.com/CertainPerformance/Stack-Exchange-Userscripts/tree/master/Right-Content' ) ; return ; } const flagQuestionLink = document . querySelector < HTMLAnchorElement > ( '.js-flag-post-link ' ) ; if ( ! flagQuestionLink ) { return ; } if ( document . querySelector ( '#question.deleted-answer' ) ) { return ; } const questionTitle = document . querySelector ( '.question-hyperlink' ) ! . textContent ! ; if ( questionTitle . endsWith ( ' [closed]' ) || questionTitle . endsWith ( ' [duplicate]' ) ) { return ; } const closeQuestionLink = document . querySelector < HTMLAnchorElement > ( '.js-close-question-link' ) ; if ( closeQuestionLink && closeQuestionLink . title . includes ( 'You voted' ) ) { return ; } const questionId = Number ( window . location . href . match ( /\d+/ ) ! [ 0 ] ) ; if ( rep < 3000 && localStorage . cpUserscriptOneClickVTCSettings && getSettings ( ) . raisedCloseFlags . includes ( questionId ) ) { return ; } return true ; } ;