import { queueUtterance } from './queueUtterance' ; import { getState } from './state' ; import { targetBlankAllAnchors } from './targetBlankAllAnchors' ; import { addBorderWhenClicked } from './addBorderWhenClicked' ; import { temporarilyPreventClicks } from './temporarilyPreventClicks' ; import { pendingQuestionColor } from '../pendingQuestionColor' ; const getQuestionDivs = ( ) => [ ... document . querySelectorAll < HTMLInputElement > ( '#questions div.question-summary' ) ] ; const getQuestionId = ( questionDiv ) => Number ( questionDiv . id . match ( /\d+$/ ) ! [ 0 ] ) ; const seenQuestionsIds = new Set ( getQuestionDivs ( ) . map ( getQuestionId ) ) ; const watchedTags = document . querySelector < HTMLInputElement > ( '#search input' ) ?. value . match ( /[^\[\]]+(?=\])/g ) || [ ] ; const questionTagCountsLeftById = { } ; const siteName = window . location . href === 'https://example.com/fakepage' ? '' : window . StackExchange . options . site . name ; const siteNameSpokenText = siteName === 'Stack Overflow' ? '' : `${ siteName }, ` ; const tagSelector = '.post-tag' ; export const checkNewQuestions = ( ) => { temporarilyPreventClicks ( ) ; for ( const questionDiv of getQuestionDivs ( ) ) { const questionId = getQuestionId ( questionDiv ) ; if ( ! questionId || seenQuestionsIds . has ( questionId ) ) { continue ; } targetBlankAllAnchors ( questionDiv ) ; const { focusing } = getState ( ) ; if ( ! focusing ) { questionDiv . style . backgroundColor = pendingQuestionColor ; } if ( ! questionTagCountsLeftById . hasOwnProperty ( questionId ) ) { const watchedTagCountForThisQuestion = Array . from ( questionDiv . querySelectorAll ( tagSelector ) , a => a . textContent ! ) . reduce ( ( a , tag ) => a + Number ( watchedTags . includes ( tag ) ) , 0 ) ; questionTagCountsLeftById [ questionId ] = watchedTagCountForThisQuestion ; } questionTagCountsLeftById [ questionId ] -= 1 ; if ( watchedTags . length && questionTagCountsLeftById [ questionId ] !== 0 ) { continue ; } seenQuestionsIds . add ( questionId ) ; addBorderWhenClicked ( questionDiv ) ; if ( focusing ) { continue ; } const questionText = questionDiv . querySelector ( '.question-hyperlink' ) ! . textContent ; const questionTags = [ ... questionDiv . querySelectorAll ( tagSelector ) ] . map ( tagA => tagA . textContent ! . replace ( /\./g , ' dot ' ) ) ; const textToSpeak = `Question, ${ siteNameSpokenText } ${ questionText } ---- ${ questionTags . join ( ', ' ) }` ; queueUtterance ( textToSpeak , questionId ) ; } } ;