<commit_before>const sendEvent = require("../../browser-send-event.js");
const page = require("./page").page;
const { AbstractShot } = require("../../../shared/shot");

const TEN_SECONDS = 10 * 1000;

let model;

let firstRun = true;

exports.launch = function(m) {
  if (m.hasDeviceId) {
    if (m.shots) {
      m.shots = m.shots.map((shot) => new AbstractShot(m.backend, shot.id, shot.json));
    }
    let match = /[?&]q=([^&]{1,4000})/.exec(location.href);
    if (match) {
      m.defaultSearch = decodeURIComponent(match[1]);
    }
    model = m;
    render();
    if (firstRun && m.shots === null) {
      // The actual shot data hasn't been loaded yet, so we'll immediately request it:
      refreshModel();
    }
    firstRun = false;
    return;
  }
  if (window.wantsauth) {
    if (window.wantsauth.getAuthData()) {
      location.reload();
    } else {
      let authTimeout = setTimeout(() => {
        location.pathname = "";
      }, TEN_SECONDS);
      window.wantsauth.addAuthDataListener((data) => {
        clearTimeout(authTimeout);
        location.reload();
      });
    }
  }<commit_msg>Fix #2939, avoid infinite refresh loop on shots page<commit_after>const sendEvent = require("../../browser-send-event.js");
const page = require("./page").page;
const { AbstractShot } = require("../../../shared/shot");

const FIVE_SECONDS = 5 * 1000;

let model;

let firstRun = true;

exports.launch = function(m) {
  if (m.hasDeviceId) {
    if (m.shots) {
      m.shots = m.shots.map((shot) => new AbstractShot(m.backend, shot.id, shot.json));
    }
    let match = /[?&]q=([^&]{1,4000})/.exec(location.href);
    if (match) {
      m.defaultSearch = decodeURIComponent(match[1]);
    }
    model = m;
    render();
    if (firstRun && m.shots === null) {
      // The actual shot data hasn't been loaded yet, so we'll immediately request it:
      refreshModel();
    }
    firstRun = false;
    return;
  }
  if (window.wantsauth) {
    if (window.wantsauth.getAuthData() && location.search.indexOf("reloaded") === -1) {
      location.search = "reloaded";
      return;
    }
    let authTimeout = setTimeout(() => {
      // eslint-disable-next-line no-global-assign
      location = location.origin;
    }, FIVE_SECONDS);
    window.wantsauth.addAuthDataListener((data) => {
      if (location.search.indexOf("reloaded") > -1) {
        return;
      }
      clearTimeout(authTimeout);
      location.search = "reloaded";
    });
  }
{'fraction_non_alphanumeric': 0.17400162999185004, 'fraction_numerical': 0.011817440912795437, 'mean_word_length': 2.6641791044776117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6706706', 'n_tokens_mistral': 831, 'n_tokens_neox': 810, 'n_words': 169}