p = 'frontend/src/pages/QuizPage.jsx'
s = open(p).read()

# 1. No away detector in a study session.
s = s.replace('''  // Away from the desk is not time spent on the question, whether or not the
  // tab is still in front. Only while a session is actually being sat.
  const { asking: askingStillHere, away, confirmHere } =
    useAwayDetector({ enabled: !!attemptId && !!quizMode })
  const clockStopped = clockPaused || askingStillHere || away''',
'''  // Away from the desk is not time spent on the question, whether or not the
  // tab is still in front. Only in an exam: study is not being timed, so
  // nothing needs protecting from a cup of tea, and asking a learner reading
  // an explanation whether they are still there is an interruption in the
  // middle of the one thing study mode is for.
  const { asking: askingStillHere, away, confirmHere } =
    useAwayDetector({ enabled: !!attemptId && !!quizMode && quizMode !== 'study' })
  const clockStopped = clockPaused || askingStillHere || away''')

# 2. The clocks do not run in a study session at all — not displayed, and not
#    counted into anything.
s = s.replace('''  useEffect(() => {
    if (clockStopped || !attemptId) return undefined
    let tick = null''',
'''  useEffect(() => {
    // Not in study. An untimed session is untimed: no clock on the screen, and
    // no seconds banked into the per-question times that feed the average.
    // "13:12 average" over 26-second questions was the arithmetic of a number
    // nobody had asked for.
    if (clockStopped || !attemptId || isStudy) return undefined
    let tick = null''')
s = s.replace('''  }, [clockStopped, attemptId])''', '''  }, [clockStopped, attemptId, isStudy])''')

s = s.replace('''  // Same rule for the session and per-question clocks: away from the screen is
  // not time spent on the question.''',
'''  // Same rule for the session and per-question clocks: away from the screen is
  // not time spent on the question — and in a study session there are no
  // clocks to keep.''')
open(p, 'w').write(s)
print('written')
