It looks like this is a web page, not a feed. I looked for a feed associated with this page, but couldn't find one. Please enter the address of your feed to validate.

Source: http://poultrybookstore.com/10314/vegus1168-why-is-this-significant

  1.  
  2. <!DOCTYPE html>
  3. <!-- saved from url=(0029)chrome-error://chromewebdata/ -->
  4. <html dir="ltr" lang="zh"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.  
  6.  <meta name="color-scheme" content="light dark">
  7.  <meta name="theme-color" content="#fff">
  8.  <meta name="viewport" content="width=device-width, initial-scale=1.0,
  9.                                 maximum-scale=1.0, user-scalable=no">
  10.  <title>无法访问此网站</title>
  11.  <style>/* Copyright 2017 The Chromium Authors
  12. * Use of this source code is governed by a BSD-style license that can be
  13. * found in the LICENSE file. */
  14.  
  15. a {
  16.  color: var(--link-color);
  17. }
  18.  
  19. body {
  20.  --background-color: #fff;
  21.  --error-code-color: var(--google-gray-700);
  22.  --google-blue-100: rgb(210, 227, 252);
  23.  --google-blue-300: rgb(138, 180, 248);
  24.  --google-blue-600: rgb(26, 115, 232);
  25.  --google-blue-700: rgb(25, 103, 210);
  26.  --google-gray-100: rgb(241, 243, 244);
  27.  --google-gray-300: rgb(218, 220, 224);
  28.  --google-gray-500: rgb(154, 160, 166);
  29.  --google-gray-50: rgb(248, 249, 250);
  30.  --google-gray-600: rgb(128, 134, 139);
  31.  --google-gray-700: rgb(95, 99, 104);
  32.  --google-gray-800: rgb(60, 64, 67);
  33.  --google-gray-900: rgb(32, 33, 36);
  34.  --heading-color: var(--google-gray-900);
  35.  --link-color: rgb(88, 88, 88);
  36.  --popup-container-background-color: rgba(0,0,0,.65);
  37.  --primary-button-fill-color-active: var(--google-blue-700);
  38.  --primary-button-fill-color: var(--google-blue-600);
  39.  --primary-button-text-color: #fff;
  40.  --quiet-background-color: rgb(247, 247, 247);
  41.  --secondary-button-border-color: var(--google-gray-500);
  42.  --secondary-button-fill-color: #fff;
  43.  --secondary-button-hover-border-color: var(--google-gray-600);
  44.  --secondary-button-hover-fill-color: var(--google-gray-50);
  45.  --secondary-button-text-color: var(--google-gray-700);
  46.  --small-link-color: var(--google-gray-700);
  47.  --text-color: var(--google-gray-700);
  48.  background: var(--background-color);
  49.  color: var(--text-color);
  50.  word-wrap: break-word;
  51. }
  52.  
  53. .nav-wrapper .secondary-button {
  54.  background: var(--secondary-button-fill-color);
  55.  border: 1px solid var(--secondary-button-border-color);
  56.  color: var(--secondary-button-text-color);
  57.  float: none;
  58.  margin: 0;
  59.  padding: 8px 16px;
  60. }
  61.  
  62. .hidden {
  63.  display: none;
  64. }
  65.  
  66. html {
  67.  -webkit-text-size-adjust: 100%;
  68.  font-size: 125%;
  69. }
  70.  
  71. .icon {
  72.  background-repeat: no-repeat;
  73.  background-size: 100%;
  74. }
  75.  
  76. @media (prefers-color-scheme: dark) {
  77.  body {
  78.    --background-color: var(--google-gray-900);
  79.    --error-code-color: var(--google-gray-500);
  80.    --heading-color: var(--google-gray-500);
  81.    --link-color: var(--google-blue-300);
  82.    --primary-button-fill-color-active: rgb(129, 162, 208);
  83.    --primary-button-fill-color: var(--google-blue-300);
  84.    --primary-button-text-color: var(--google-gray-900);
  85.    --quiet-background-color: var(--background-color);
  86.    --secondary-button-border-color: var(--google-gray-700);
  87.    --secondary-button-fill-color: var(--google-gray-900);
  88.    --secondary-button-hover-fill-color: rgb(48, 51, 57);
  89.    --secondary-button-text-color: var(--google-blue-300);
  90.    --small-link-color: var(--google-blue-300);
  91.    --text-color: var(--google-gray-500);
  92.  }
  93. }
  94. </style>
  95.  <style>/* Copyright 2014 The Chromium Authors
  96.   Use of this source code is governed by a BSD-style license that can be
  97.   found in the LICENSE file. */
  98.  
  99. button {
  100.  border: 0;
  101.  border-radius: 4px;
  102.  box-sizing: border-box;
  103.  color: var(--primary-button-text-color);
  104.  cursor: pointer;
  105.  float: right;
  106.  font-size: .875em;
  107.  margin: 0;
  108.  padding: 8px 16px;
  109.  transition: box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1);
  110.  user-select: none;
  111. }
  112.  
  113. [dir='rtl'] button {
  114.  float: left;
  115. }
  116.  
  117. .bad-clock button,
  118. .captive-portal button,
  119. .https-only button,
  120. .insecure-form button,
  121. .lookalike-url button,
  122. .main-frame-blocked button,
  123. .neterror button,
  124. .pdf button,
  125. .ssl button,
  126. .enterprise-block button,
  127. .enterprise-warn button,
  128. .safe-browsing-billing button {
  129.  background: var(--primary-button-fill-color);
  130. }
  131.  
  132. button:active {
  133.  background: var(--primary-button-fill-color-active);
  134.  outline: 0;
  135. }
  136.  
  137. #debugging {
  138.  display: inline;
  139.  overflow: auto;
  140. }
  141.  
  142. .debugging-content {
  143.  line-height: 1em;
  144.  margin-bottom: 0;
  145.  margin-top: 1em;
  146. }
  147.  
  148. .debugging-content-fixed-width {
  149.  display: block;
  150.  font-family: monospace;
  151.  font-size: 1.2em;
  152.  margin-top: 0.5em;
  153. }
  154.  
  155. .debugging-title {
  156.  font-weight: bold;
  157. }
  158.  
  159. #details {
  160.  margin: 0 0 50px;
  161. }
  162.  
  163. #details p:not(:first-of-type) {
  164.  margin-top: 20px;
  165. }
  166.  
  167. .secondary-button:active {
  168.  border-color: white;
  169.  box-shadow: 0 1px 2px 0 rgba(60, 64, 67, .3),
  170.      0 2px 6px 2px rgba(60, 64, 67, .15);
  171. }
  172.  
  173. .secondary-button:hover {
  174.  background: var(--secondary-button-hover-fill-color);
  175.  border-color: var(--secondary-button-hover-border-color);
  176.  text-decoration: none;
  177. }
  178.  
  179. .error-code {
  180.  color: var(--error-code-color);
  181.  font-size: .8em;
  182.  margin-top: 12px;
  183.  text-transform: uppercase;
  184. }
  185.  
  186. #error-debugging-info {
  187.  font-size: 0.8em;
  188. }
  189.  
  190. h1 {
  191.  color: var(--heading-color);
  192.  font-size: 1.6em;
  193.  font-weight: normal;
  194.  line-height: 1.25em;
  195.  margin-bottom: 16px;
  196. }
  197.  
  198. h2 {
  199.  font-size: 1.2em;
  200.  font-weight: normal;
  201. }
  202.  
  203. .icon {
  204.  height: 72px;
  205.  margin: 0 0 40px;
  206.  width: 72px;
  207. }
  208.  
  209. input[type=checkbox] {
  210.  opacity: 0;
  211. }
  212.  
  213. input[type=checkbox]:focus ~ .checkbox::after {
  214.  outline: -webkit-focus-ring-color auto 5px;
  215. }
  216.  
  217. .interstitial-wrapper {
  218.  box-sizing: border-box;
  219.  font-size: 1em;
  220.  line-height: 1.6em;
  221.  margin: 14vh auto 0;
  222.  max-width: 600px;
  223.  width: 100%;
  224. }
  225.  
  226. #main-message > p {
  227.  display: inline;
  228. }
  229.  
  230. #extended-reporting-opt-in {
  231.  font-size: .875em;
  232.  margin-top: 32px;
  233. }
  234.  
  235. #extended-reporting-opt-in label {
  236.  display: grid;
  237.  grid-template-columns: 1.8em 1fr;
  238.  position: relative;
  239. }
  240.  
  241. #enhanced-protection-message {
  242.  border-radius: 4px;
  243.  font-size: 1em;
  244.  margin-top: 32px;
  245.  padding: 10px 5px;
  246. }
  247.  
  248. #enhanced-protection-message label {
  249.  display: grid;
  250.  grid-template-columns: 2.5em 1fr;
  251.  position: relative;
  252. }
  253.  
  254. #enhanced-protection-message div {
  255.  margin: 0.5em;
  256. }
  257.  
  258. #enhanced-protection-message .icon {
  259.  height: 1.5em;
  260.  vertical-align: middle;
  261.  width: 1.5em;
  262. }
  263.  
  264. .nav-wrapper {
  265.  margin-top: 51px;
  266. }
  267.  
  268. .nav-wrapper::after {
  269.  clear: both;
  270.  content: '';
  271.  display: table;
  272.  width: 100%;
  273. }
  274.  
  275. .small-link {
  276.  color: var(--small-link-color);
  277.  font-size: .875em;
  278. }
  279.  
  280. .checkboxes {
  281.  flex: 0 0 24px;
  282. }
  283.  
  284. .checkbox {
  285.  --padding: .9em;
  286.  background: transparent;
  287.  display: block;
  288.  height: 1em;
  289.  left: -1em;
  290.  padding-inline-start: var(--padding);
  291.  position: absolute;
  292.  right: 0;
  293.  top: -.5em;
  294.  width: 1em;
  295. }
  296.  
  297. .checkbox::after {
  298.  border: 1px solid white;
  299.  border-radius: 2px;
  300.  content: '';
  301.  height: 1em;
  302.  left: var(--padding);
  303.  position: absolute;
  304.  top: var(--padding);
  305.  width: 1em;
  306. }
  307.  
  308. .checkbox::before {
  309.  background: transparent;
  310.  border: 2px solid white;
  311.  border-inline-end-width: 0;
  312.  border-top-width: 0;
  313.  content: '';
  314.  height: .2em;
  315.  left: calc(.3em + var(--padding));
  316.  opacity: 0;
  317.  position: absolute;
  318.  top: calc(.3em  + var(--padding));
  319.  transform: rotate(-45deg);
  320.  width: .5em;
  321. }
  322.  
  323. input[type=checkbox]:checked ~ .checkbox::before {
  324.  opacity: 1;
  325. }
  326.  
  327. #recurrent-error-message {
  328.  background: #ededed;
  329.  border-radius: 4px;
  330.  margin-bottom: 16px;
  331.  margin-top: 12px;
  332.  padding: 12px 16px;
  333. }
  334.  
  335. .showing-recurrent-error-message #extended-reporting-opt-in {
  336.  margin-top: 16px;
  337. }
  338.  
  339. .showing-recurrent-error-message #enhanced-protection-message {
  340.  margin-top: 16px;
  341. }
  342.  
  343. @media (max-width: 700px) {
  344.  .interstitial-wrapper {
  345.    padding: 0 10%;
  346.  }
  347.  
  348.  #error-debugging-info {
  349.    overflow: auto;
  350.  }
  351. }
  352.  
  353. @media (max-width: 420px) {
  354.  button,
  355.  [dir='rtl'] button,
  356.  .small-link {
  357.    float: none;
  358.    font-size: .825em;
  359.    font-weight: 500;
  360.    margin: 0;
  361.    width: 100%;
  362.  }
  363.  
  364.  button {
  365.    padding: 16px 24px;
  366.  }
  367.  
  368.  #details {
  369.    margin: 20px 0 20px 0;
  370.  }
  371.  
  372.  #details p:not(:first-of-type) {
  373.    margin-top: 10px;
  374.  }
  375.  
  376.  .secondary-button:not(.hidden) {
  377.    display: block;
  378.    margin-top: 20px;
  379.    text-align: center;
  380.    width: 100%;
  381.  }
  382.  
  383.  .interstitial-wrapper {
  384.    padding: 0 5%;
  385.  }
  386.  
  387.  #extended-reporting-opt-in {
  388.    margin-top: 24px;
  389.  }
  390.  
  391.  #enhanced-protection-message {
  392.    margin-top: 24px;
  393.  }
  394.  
  395.  .nav-wrapper {
  396.    margin-top: 30px;
  397.  }
  398. }
  399.  
  400. /**
  401. * Mobile specific styling.
  402. * Navigation buttons are anchored to the bottom of the screen.
  403. * Details message replaces the top content in its own scrollable area.
  404. */
  405.  
  406. @media (max-width: 420px) {
  407.  .nav-wrapper .secondary-button {
  408.    border: 0;
  409.    margin: 16px 0 0;
  410.    margin-inline-end: 0;
  411.    padding-bottom: 16px;
  412.    padding-top: 16px;
  413.  }
  414. }
  415.  
  416. /* Fixed nav. */
  417. @media (min-width: 240px) and (max-width: 420px) and
  418.       (min-height: 401px),
  419.       (min-width: 421px) and (min-height: 240px) and
  420.       (max-height: 560px) {
  421.  body .nav-wrapper {
  422.    background: var(--background-color);
  423.    bottom: 0;
  424.    box-shadow: 0 -12px 24px var(--background-color);
  425.    left: 0;
  426.    margin: 0 auto;
  427.    max-width: 736px;
  428.    padding-inline-end: 24px;
  429.    padding-inline-start: 24px;
  430.    position: fixed;
  431.    right: 0;
  432.    width: 100%;
  433.    z-index: 2;
  434.  }
  435.  
  436.  .interstitial-wrapper {
  437.    max-width: 736px;
  438.  }
  439.  
  440.  #details,
  441.  #main-content {
  442.    padding-bottom: 40px;
  443.  }
  444.  
  445.  #details {
  446.    padding-top: 5.5vh;
  447.  }
  448.  
  449.  button.small-link {
  450.    color: var(--google-blue-600);
  451.  }
  452. }
  453.  
  454. @media (max-width: 420px) and (orientation: portrait),
  455.       (max-height: 560px) {
  456.  body {
  457.    margin: 0 auto;
  458.  }
  459.  
  460.  button,
  461.  [dir='rtl'] button,
  462.  button.small-link,
  463.  .nav-wrapper .secondary-button {
  464.    font-family: Roboto-Regular,Helvetica;
  465.    font-size: .933em;
  466.    margin: 6px 0;
  467.    transform: translatez(0);
  468.  }
  469.  
  470.  .nav-wrapper {
  471.    box-sizing: border-box;
  472.    padding-bottom: 8px;
  473.    width: 100%;
  474.  }
  475.  
  476.  #details {
  477.    box-sizing: border-box;
  478.    height: auto;
  479.    margin: 0;
  480.    opacity: 1;
  481.    transition: opacity 250ms cubic-bezier(0.4, 0, 0.2, 1);
  482.  }
  483.  
  484.  #details.hidden,
  485.  #main-content.hidden {
  486.    height: 0;
  487.    opacity: 0;
  488.    overflow: hidden;
  489.    padding-bottom: 0;
  490.    transition: none;
  491.  }
  492.  
  493.  h1 {
  494.    font-size: 1.5em;
  495.    margin-bottom: 8px;
  496.  }
  497.  
  498.  .icon {
  499.    margin-bottom: 5.69vh;
  500.  }
  501.  
  502.  .interstitial-wrapper {
  503.    box-sizing: border-box;
  504.    margin: 7vh auto 12px;
  505.    padding: 0 24px;
  506.    position: relative;
  507.  }
  508.  
  509.  .interstitial-wrapper p {
  510.    font-size: .95em;
  511.    line-height: 1.61em;
  512.    margin-top: 8px;
  513.  }
  514.  
  515.  #main-content {
  516.    margin: 0;
  517.    transition: opacity 100ms cubic-bezier(0.4, 0, 0.2, 1);
  518.  }
  519.  
  520.  .small-link {
  521.    border: 0;
  522.  }
  523.  
  524.  .suggested-left > #control-buttons,
  525.  .suggested-right > #control-buttons {
  526.    float: none;
  527.    margin: 0;
  528.  }
  529. }
  530.  
  531. @media (min-width: 421px) and (min-height: 500px) and (max-height: 560px) {
  532.  .interstitial-wrapper {
  533.    margin-top: 10vh;
  534.  }
  535. }
  536.  
  537. @media (min-height: 400px) and (orientation:portrait) {
  538.  .interstitial-wrapper {
  539.    margin-bottom: 145px;
  540.  }
  541. }
  542.  
  543. @media (min-height: 299px) {
  544.  .nav-wrapper {
  545.    padding-bottom: 16px;
  546.  }
  547. }
  548.  
  549. @media (max-height: 560px) and (min-height: 240px) and (orientation:landscape) {
  550.  .extended-reporting-has-checkbox #details {
  551.    padding-bottom: 80px;
  552.  }
  553. }
  554.  
  555. @media (min-height: 500px) and (max-height: 650px) and (max-width: 414px) and
  556.       (orientation: portrait) {
  557.  .interstitial-wrapper {
  558.    margin-top: 7vh;
  559.  }
  560. }
  561.  
  562. @media (min-height: 650px) and (max-width: 414px) and (orientation: portrait) {
  563.  .interstitial-wrapper {
  564.    margin-top: 10vh;
  565.  }
  566. }
  567.  
  568. /* Small mobile screens. No fixed nav. */
  569. @media (max-height: 400px) and (orientation: portrait),
  570.       (max-height: 239px) and (orientation: landscape),
  571.       (max-width: 419px) and (max-height: 399px) {
  572.  .interstitial-wrapper {
  573.    display: flex;
  574.    flex-direction: column;
  575.    margin-bottom: 0;
  576.  }
  577.  
  578.  #details {
  579.    flex: 1 1 auto;
  580.    order: 0;
  581.  }
  582.  
  583.  #main-content {
  584.    flex: 1 1 auto;
  585.    order: 0;
  586.  }
  587.  
  588.  .nav-wrapper {
  589.    flex: 0 1 auto;
  590.    margin-top: 8px;
  591.    order: 1;
  592.    padding-inline-end: 0;
  593.    padding-inline-start: 0;
  594.    position: relative;
  595.    width: 100%;
  596.  }
  597.  
  598.  button,
  599.  .nav-wrapper .secondary-button {
  600.    padding: 16px 24px;
  601.  }
  602.  
  603.  button.small-link {
  604.    color: var(--google-blue-600);
  605.  }
  606. }
  607.  
  608. @media (max-width: 239px) and (orientation: portrait) {
  609.  .nav-wrapper {
  610.    padding-inline-end: 0;
  611.    padding-inline-start: 0;
  612.  }
  613. }
  614. </style>
  615.  <style>/* Copyright 2013 The Chromium Authors
  616. * Use of this source code is governed by a BSD-style license that can be
  617. * found in the LICENSE file. */
  618.  
  619. /* Don't use the main frame div when the error is in a subframe. */
  620. html[subframe] #main-frame-error {
  621.  display: none;
  622. }
  623.  
  624. /* Don't use the subframe error div when the error is in a main frame. */
  625. html:not([subframe]) #sub-frame-error {
  626.  display: none;
  627. }
  628.  
  629. h1 {
  630.  margin-top: 0;
  631.  word-wrap: break-word;
  632. }
  633.  
  634. h1 span {
  635.  font-weight: 500;
  636. }
  637.  
  638. a {
  639.  text-decoration: none;
  640. }
  641.  
  642. .icon {
  643.  -webkit-user-select: none;
  644.  display: inline-block;
  645. }
  646.  
  647. .icon-generic {
  648.  /* Can't access chrome://theme/IDR_ERROR_NETWORK_GENERIC from an untrusted
  649.   * renderer process, so embed the resource manually. */
  650.  content: -webkit-image-set(
  651.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABIAQMAAABvIyEEAAAABlBMVEUAAABTU1OoaSf/AAAAAXRSTlMAQObYZgAAAENJREFUeF7tzbEJACEQRNGBLeAasBCza2lLEGx0CxFGG9hBMDDxRy/72O9FMnIFapGylsu1fgoBdkXfUHLrQgdfrlJN1BdYBjQQm3UAAAAASUVORK5CYII=) 1x,
  652.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJAAAACQAQMAAADdiHD7AAAABlBMVEUAAABTU1OoaSf/AAAAAXRSTlMAQObYZgAAAFJJREFUeF7t0cENgDAMQ9FwYgxG6WjpaIzCCAxQxVggFuDiCvlLOeRdHR9yzjncHVoq3npu+wQUrUuJHylSTmBaespJyJQoObUeyxDQb3bEm5Au81c0pSCD8HYAAAAASUVORK5CYII=) 2x);
  653. }
  654.  
  655. .icon-offline {
  656.  content: -webkit-image-set(
  657.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABIAQMAAABvIyEEAAAABlBMVEUAAABTU1OoaSf/AAAAAXRSTlMAQObYZgAAAGxJREFUeF7tyMEJwkAQRuFf5ipMKxYQiJ3Z2nSwrWwBA0+DQZcdxEOueaePp9+dQZFB7GpUcURSVU66yVNFj6LFICatThZB6r/ko/pbRpUgilY0Cbw5sNmb9txGXUKyuH7eV25x39DtJXUNPQGJtWFV+BT/QAAAAABJRU5ErkJggg==) 1x,
  658.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJAAAACQBAMAAAAVaP+LAAAAGFBMVEUAAABTU1NNTU1TU1NPT09SUlJSUlJTU1O8B7DEAAAAB3RSTlMAoArVKvVgBuEdKgAAAJ1JREFUeF7t1TEOwyAMQNG0Q6/UE+RMXD9d/tC6womIFSL9P+MnAYOXeTIzMzMzMzMzaz8J9Ri6HoITmuHXhISE8nEh9yxDh55aCEUoTGbbQwjqHwIkRAEiIaG0+0AA9VBMaE89Rogeoww936MQrWdBr4GN/z0IAdQ6nQ/FIpRXDwHcA+JIJcQowQAlFUA0MfQpXLlVQfkzR4igS6ENjknm/wiaGhsAAAAASUVORK5CYII=) 2x);
  659.  position: relative;
  660. }
  661.  
  662. .icon-disabled {
  663.  content: -webkit-image-set(
  664.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABICAMAAAAZF4G5AAAABlBMVEVMaXFTU1OXUj8tAAAAAXRSTlMAQObYZgAAASZJREFUeAHd11Fq7jAMRGGf/W/6PoWB67YMqv5DybwG/CFjRuR8JBw3+ByiRjgV9W/TJ31P0tBfC6+cj1haUFXKHmVJo5wP98WwQ0ZCbfUc6LQ6VuUBz31ikADkLMkDrfUC4rR6QGW+gF6rx7NaHWCj1Y/W6lf4L7utvgBSt3rBFSS/XBMPUILcJINHCBWYUfpWn4NBi1ZfudIc3rf6/NGEvEA+AsYTJozmXemjXeLZAov+mnkN2HfzXpMSVQDnGw++57qNJ4D1xitA2sJ+VAWMygSEaYf2mYPTjZfk2K8wmP7HLIH5Mg4/pP+PEcDzUvDMvYbs/2NWwPO5vBdMZE4EE5UTQLiBFDaUlTDPBRoJ9HdAYIkIo06og3BNXtCzy7zA1aXk5x+tJARq63eAygAAAABJRU5ErkJggg==) 1x,
  665.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOAAAACQAQMAAAArwfVjAAAABlBMVEVMaXFTU1OXUj8tAAAAAXRSTlMAQObYZgAAAYdJREFUeF7F1EFqwzAUBNARAmVj0FZe5QoBH6BX+dn4GlY2PYNzGx/A0CvkCIJuvIraKJKbgBvzf2g62weDGD7CYggpfFReis4J0ey9EGFIiEQQojFSlA9kSIiqd0KkFjKsewgRbStEN19mxUPTtmW9HQ/h6tyqNQ8NlSMZdzyE6qkoE0trVYGFm0n1WYeBhduzwbwBC7voS+vIxfeMjeaiLxsMMtQNwMPtuew+DjzcTHk8YMfDknEcIUOtf2lVfgVH3K4Xv5PRYAXRVMtItIJ3rfaCIVn9DsTH2NxisAVRex2Hh3hX+/mRUR08bAwPEYsI51ZxWH4Q0SpicQRXeyEaIug48FEdegARfMz/tADVsRciwTAxW308ehmC2gLraC+YCbV3QoTZexa+zegAEW5PhhgYfmbvJgcRqngGByOSXdFJcLk2JeDPEN0kxe1JhIt5FiFA+w+ItMELsUyPF2IaJ4aILqb4FbxPwhImwj6JauKgDUCYaxmYIsd4KXdMjIC9ItB5Bn4BNRwsG0XM2nwAAAAASUVORK5CYII=) 2x);
  666.  width: 112px;
  667. }
  668.  
  669. .hidden {
  670.  display: none;
  671. }
  672.  
  673. #suggestions-list a {
  674.  color: var(--google-blue-600);
  675. }
  676.  
  677. #suggestions-list p {
  678.  margin-block-end: 0;
  679. }
  680.  
  681. #suggestions-list ul {
  682.  margin-top: 0;
  683. }
  684.  
  685. .single-suggestion {
  686.  list-style-type: none;
  687.  padding-inline-start: 0;
  688. }
  689.  
  690. #error-information-button {
  691.  content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDB6Ii8+PHBhdGggZD0iTTExIDE4aDJ2LTJoLTJ2MnptMS0xNkM2LjQ4IDIgMiA2LjQ4IDIgMTJzNC40OCAxMCAxMCAxMCAxMC00LjQ4IDEwLTEwUzE3LjUyIDIgMTIgMnptMCAxOGMtNC40MSAwLTgtMy41OS04LThzMy41OS04IDgtOCA4IDMuNTkgOCA4LTMuNTkgOC04IDh6bTAtMTRjLTIuMjEgMC00IDEuNzktNCA0aDJjMC0xLjEuOS0yIDItMnMyIC45IDIgMmMwIDItMyAxLjc1LTMgNWgyYzAtMi4yNSAzLTIuNSAzLTUgMC0yLjIxLTEuNzktNC00LTR6Ii8+PC9zdmc+);
  692.  height: 24px;
  693.  vertical-align: -.15em;
  694.  width: 24px;
  695. }
  696.  
  697. .use-popup-container#error-information-popup-container
  698.  #error-information-popup {
  699.  align-items: center;
  700.  background-color: var(--popup-container-background-color);
  701.  display: flex;
  702.  height: 100%;
  703.  left: 0;
  704.  position: fixed;
  705.  top: 0;
  706.  width: 100%;
  707.  z-index: 100;
  708. }
  709.  
  710. .use-popup-container#error-information-popup-container
  711.  #error-information-popup-content > p {
  712.  margin-bottom: 11px;
  713.  margin-inline-start: 20px;
  714. }
  715.  
  716. .use-popup-container#error-information-popup-container #suggestions-list ul {
  717.  margin-inline-start: 15px;
  718. }
  719.  
  720. .use-popup-container#error-information-popup-container
  721.  #error-information-popup-box {
  722.  background-color: var(--background-color);
  723.  left: 5%;
  724.  padding-bottom: 15px;
  725.  padding-top: 15px;
  726.  position: fixed;
  727.  width: 90%;
  728.  z-index: 101;
  729. }
  730.  
  731. .use-popup-container#error-information-popup-container div.error-code {
  732.  margin-inline-start: 20px;
  733. }
  734.  
  735. .use-popup-container#error-information-popup-container #suggestions-list p {
  736.  margin-inline-start: 20px;
  737. }
  738.  
  739. :not(.use-popup-container)#error-information-popup-container
  740.  #error-information-popup-close {
  741.  display: none;
  742. }
  743.  
  744. #error-information-popup-close {
  745.  margin-bottom: 0;
  746.  margin-inline-end: 35px;
  747.  margin-top: 15px;
  748.  text-align: end;
  749. }
  750.  
  751. .link-button {
  752.  color: rgb(66, 133, 244);
  753.  display: inline-block;
  754.  font-weight: bold;
  755.  text-transform: uppercase;
  756. }
  757.  
  758. #sub-frame-error-details {
  759.  
  760.  color: #8F8F8F;
  761.  
  762.  /* Not done on mobile for performance reasons. */
  763.  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
  764.  
  765. }
  766.  
  767. [jscontent=hostName],
  768. [jscontent=failedUrl] {
  769.  overflow-wrap: break-word;
  770. }
  771.  
  772. .secondary-button {
  773.  background: #d9d9d9;
  774.  color: #696969;
  775.  margin-inline-end: 16px;
  776. }
  777.  
  778. .snackbar {
  779.  background: #323232;
  780.  border-radius: 2px;
  781.  bottom: 24px;
  782.  box-sizing: border-box;
  783.  color: #fff;
  784.  font-size: .87em;
  785.  left: 24px;
  786.  max-width: 568px;
  787.  min-width: 288px;
  788.  opacity: 0;
  789.  padding: 16px 24px 12px;
  790.  position: fixed;
  791.  transform: translateY(90px);
  792.  will-change: opacity, transform;
  793.  z-index: 999;
  794. }
  795.  
  796. .snackbar-show {
  797.  -webkit-animation:
  798.    show-snackbar 250ms cubic-bezier(0, 0, 0.2, 1) forwards,
  799.    hide-snackbar 250ms cubic-bezier(0.4, 0, 1, 1) forwards 5s;
  800. }
  801.  
  802. @-webkit-keyframes show-snackbar {
  803.  100% {
  804.    opacity: 1;
  805.    transform: translateY(0);
  806.  }
  807. }
  808.  
  809. @-webkit-keyframes hide-snackbar {
  810.  0% {
  811.    opacity: 1;
  812.    transform: translateY(0);
  813.  }
  814.  100% {
  815.    opacity: 0;
  816.    transform: translateY(90px);
  817.  }
  818. }
  819.  
  820. .suggestions {
  821.  margin-top: 18px;
  822. }
  823.  
  824. .suggestion-header {
  825.  font-weight: bold;
  826.  margin-bottom: 4px;
  827. }
  828.  
  829. .suggestion-body {
  830.  color: #777;
  831. }
  832.  
  833. /* Decrease padding at low sizes. */
  834. @media (max-width: 640px), (max-height: 640px) {
  835.  h1 {
  836.    margin: 0 0 15px;
  837.  }
  838.  .suggestions {
  839.    margin-top: 10px;
  840.  }
  841.  .suggestion-header {
  842.    margin-bottom: 0;
  843.  }
  844. }
  845.  
  846. #download-link,
  847. #download-link-clicked {
  848.  margin-bottom: 30px;
  849.  margin-top: 30px;
  850. }
  851.  
  852. #download-link-clicked {
  853.  color: #BBB;
  854. }
  855.  
  856. #download-link::before,
  857. #download-link-clicked::before {
  858.  content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxLjJlbSIgaGVpZ2h0PSIxLjJlbSIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNNSAyMGgxNHYtMkg1bTE0LTloLTRWM0g5djZINWw3IDcgNy03eiIgZmlsbD0iIzQyODVGNCIvPjwvc3ZnPg==);
  859.  display: inline-block;
  860.  margin-inline-end: 4px;
  861.  vertical-align: -webkit-baseline-middle;
  862. }
  863.  
  864. #download-link-clicked::before {
  865.  opacity: 0;
  866.  width: 0;
  867. }
  868.  
  869. #offline-content-list-visibility-card {
  870.  border: 1px solid white;
  871.  border-radius: 8px;
  872.  display: flex;
  873.  font-size: .8em;
  874.  justify-content: space-between;
  875.  line-height: 1;
  876. }
  877.  
  878. #offline-content-list.list-hidden #offline-content-list-visibility-card {
  879.  border-color: rgb(218, 220, 224);
  880. }
  881.  
  882. #offline-content-list-visibility-card > div {
  883.  padding: 1em;
  884. }
  885.  
  886. #offline-content-list-title {
  887.  color: var(--google-gray-700);
  888. }
  889.  
  890. #offline-content-list-show-text,
  891. #offline-content-list-hide-text {
  892.  color: rgb(66, 133, 244);
  893. }
  894.  
  895. /* Hides the "hide" text div when the offline content list is collapsed/hidden
  896. * and, alternatively, hides the "show" text div when the offline content list
  897. * is expanded/shown.
  898. */
  899. #offline-content-list.list-hidden #offline-content-list-hide-text,
  900. #offline-content-list:not(.list-hidden) #offline-content-list-show-text {
  901.  display: none;
  902. }
  903.  
  904. /* Controls the animation of the offline content list when it is expanded/shown.
  905. */
  906. #offline-content-suggestions {
  907.  /* Max-height has to be set for the height animation to work. The chosen value
  908.   * is a little greater than the maximum height the list will have, when all
  909.   * suggestions have images, so that it is never clamped. This makes so that
  910.   * when the actual height is smaller then the animation is not as smooth.
  911.   */
  912.  max-height: 27em;
  913.  transition: max-height 200ms ease-in, visibility 0s 200ms,
  914.              opacity 200ms 200ms linear;
  915. }
  916.  
  917. /* Controls the animation of the offline content list when it is
  918. * collapsed/hidden.
  919. */
  920. #offline-content-list.list-hidden #offline-content-suggestions {
  921.  max-height: 0;
  922.  opacity: 0;
  923.  transition: opacity 200ms linear, visibility 0s 200ms,
  924.              max-height 200ms 200ms ease-out;
  925.  visibility: hidden;
  926. }
  927.  
  928. #offline-content-list {
  929.  margin-inline-start: -5%;
  930.  width: 110%;
  931. }
  932.  
  933. /* The selectors below adjust the "overflow" of the suggestion cards contents
  934. * based on the same screen size based strategy used for the main frame, which
  935. * is applied by the `interstitial-wrapper` class. */
  936. @media (max-width: 420px)  {
  937.  #offline-content-list {
  938.    margin-inline-start: -2.5%;
  939.    width: 105%;
  940.  }
  941. }
  942. @media (max-width: 420px) and (orientation: portrait),
  943.       (max-height: 560px) {
  944.  #offline-content-list {
  945.    margin-inline-start: -12px;
  946.    width: calc(100% + 24px);
  947.  }
  948. }
  949.  
  950. .suggestion-with-image .offline-content-suggestion-thumbnail {
  951.  flex-basis: 8.2em;
  952.  flex-shrink: 0;
  953. }
  954.  
  955. .suggestion-with-image .offline-content-suggestion-thumbnail > img {
  956.  height: 100%;
  957.  width: 100%;
  958. }
  959.  
  960. .suggestion-with-image #offline-content-list:not(.is-rtl)
  961. .offline-content-suggestion-thumbnail > img {
  962.  border-bottom-right-radius: 7px;
  963.  border-top-right-radius: 7px;
  964. }
  965.  
  966. .suggestion-with-image #offline-content-list.is-rtl
  967. .offline-content-suggestion-thumbnail > img {
  968.  border-bottom-left-radius: 7px;
  969.  border-top-left-radius: 7px;
  970. }
  971.  
  972. .suggestion-with-icon .offline-content-suggestion-thumbnail {
  973.  align-items: center;
  974.  display: flex;
  975.  justify-content: center;
  976.  min-height: 4.2em;
  977.  min-width: 4.2em;
  978. }
  979.  
  980. .suggestion-with-icon .offline-content-suggestion-thumbnail > div {
  981.  align-items: center;
  982.  background-color: rgb(241, 243, 244);
  983.  border-radius: 50%;
  984.  display: flex;
  985.  height: 2.3em;
  986.  justify-content: center;
  987.  width: 2.3em;
  988. }
  989.  
  990. .suggestion-with-icon .offline-content-suggestion-thumbnail > div > img {
  991.  height: 1.45em;
  992.  width: 1.45em;
  993. }
  994.  
  995. .offline-content-suggestion-favicon {
  996.  height: 1em;
  997.  margin-inline-end: 0.4em;
  998.  width: 1.4em;
  999. }
  1000.  
  1001. .offline-content-suggestion-favicon > img {
  1002.  height: 1.4em;
  1003.  width: 1.4em;
  1004. }
  1005.  
  1006. .no-favicon .offline-content-suggestion-favicon {
  1007.  display: none;
  1008. }
  1009.  
  1010. .image-video {
  1011.  content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTcgMTAuNVY3YTEgMSAwIDAgMC0xLTFINGExIDEgMCAwIDAtMSAxdjEwYTEgMSAwIDAgMCAxIDFoMTJhMSAxIDAgMCAwIDEtMXYtMy41bDQgNHYtMTFsLTQgNHoiIGZpbGw9IiMzQzQwNDMiLz48L3N2Zz4=);
  1012. }
  1013.  
  1014. .image-music-note {
  1015.  content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIgM3Y5LjI2Yy0uNS0uMTctMS0uMjYtMS41LS4yNkM4IDEyIDYgMTQgNiAxNi41UzggMjEgMTAuNSAyMXM0LjUtMiA0LjUtNC41VjZoNFYzaC03eiIgZmlsbD0iIzNDNDA0MyIvPjwvc3ZnPg==);
  1016. }
  1017.  
  1018. .image-earth {
  1019.  content: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTIgMmM1LjUyIDAgMTAgNC40OCAxMCAxMHMtNC40OCAxMC0xMCAxMFMyIDE3LjUyIDIgMTIgNi40OCAyIDEyIDJ6TTQgMTJoNC40YzMuNDA3LjAyMiA0LjkyMiAxLjczIDQuNTQzIDUuMTI3SDkuNDg4djIuNDdhOC4wMDQgOC4wMDQgMCAwIDAgMTAuNDk4LTguMDgzQzE5LjMyNyAxMi41MDQgMTguMzMyIDEzIDE3IDEzYy0yLjEzNyAwLTMuMjA2LS45MTYtMy4yMDYtMi43NWgtMy43NDhjLS4yNzQtMi43MjguNjgzLTQuMDkyIDIuODctNC4wOTIgMC0uOTc1LjMyNy0xLjU5Ny44MTEtMS45N0E4LjAwNCA4LjAwNCAwIDAgMCA0IDEyeiIgZmlsbD0iIzNDNDA0MyIvPjwvc3ZnPg==);
  1020. }
  1021.  
  1022. .image-file {
  1023.  content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTMgOVYzLjVMMTguNSA5TTYgMmMtMS4xMSAwLTIgLjg5LTIgMnYxNmEyIDIgMCAwIDAgMiAyaDEyYTIgMiAwIDAgMCAyLTJWOGwtNi02SDZ6IiBmaWxsPSIjM0M0MDQzIi8+PC9zdmc+);
  1024. }
  1025.  
  1026. .offline-content-suggestion-texts {
  1027.  display: flex;
  1028.  flex-direction: column;
  1029.  justify-content: space-between;
  1030.  line-height: 1.3;
  1031.  padding: .9em;
  1032.  width: 100%;
  1033. }
  1034.  
  1035. .offline-content-suggestion-title {
  1036.  -webkit-box-orient: vertical;
  1037.  -webkit-line-clamp: 3;
  1038.  color: rgb(32, 33, 36);
  1039.  display: -webkit-box;
  1040.  font-size: 1.1em;
  1041.  overflow: hidden;
  1042.  text-overflow: ellipsis;
  1043. }
  1044.  
  1045. div.offline-content-suggestion {
  1046.  align-items: stretch;
  1047.  border: 1px solid rgb(218, 220, 224);
  1048.  border-radius: 8px;
  1049.  display: flex;
  1050.  justify-content: space-between;
  1051.  margin-bottom: .8em;
  1052. }
  1053.  
  1054. .suggestion-with-image {
  1055.  flex-direction: row;
  1056.  height: 8.2em;
  1057.  max-height: 8.2em;
  1058. }
  1059.  
  1060. .suggestion-with-icon {
  1061.  flex-direction: row-reverse;
  1062.  height: 4.2em;
  1063.  max-height: 4.2em;
  1064. }
  1065.  
  1066. .suggestion-with-icon .offline-content-suggestion-title {
  1067.  -webkit-line-clamp: 1;
  1068.  word-break: break-all;
  1069. }
  1070.  
  1071. .suggestion-with-icon .offline-content-suggestion-texts {
  1072.  padding-inline-start: 0;
  1073. }
  1074.  
  1075. .offline-content-suggestion-attribution-freshness {
  1076.  color: rgb(95, 99, 104);
  1077.  display: flex;
  1078.  font-size: .8em;
  1079.  line-height: 1.7em;
  1080. }
  1081.  
  1082. .offline-content-suggestion-attribution {
  1083.  -webkit-box-orient: vertical;
  1084.  -webkit-line-clamp: 1;
  1085.  display: -webkit-box;
  1086.  flex-shrink: 1;
  1087.  margin-inline-end: 0.3em;
  1088.  overflow: hidden;
  1089.  overflow-wrap: break-word;
  1090.  text-overflow: ellipsis;
  1091.  word-break: break-all;
  1092. }
  1093.  
  1094. .no-attribution .offline-content-suggestion-attribution {
  1095.  display: none;
  1096. }
  1097.  
  1098. .offline-content-suggestion-freshness::before {
  1099.  content: '-';
  1100.  display: inline-block;
  1101.  flex-shrink: 0;
  1102.  margin-inline-end: .1em;
  1103.  margin-inline-start: .1em;
  1104. }
  1105.  
  1106. .no-attribution .offline-content-suggestion-freshness::before {
  1107.  display: none;
  1108. }
  1109.  
  1110. .offline-content-suggestion-freshness {
  1111.  flex-shrink: 0;
  1112. }
  1113.  
  1114. .suggestion-with-image .offline-content-suggestion-pin-spacer {
  1115.  flex-grow: 100;
  1116.  flex-shrink: 1;
  1117. }
  1118.  
  1119. .suggestion-with-image .offline-content-suggestion-pin {
  1120.  content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCI+PGRlZnM+PHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjR2MjRIMFYweiIvPjwvZGVmcz48Y2xpcFBhdGggaWQ9ImIiPjx1c2UgeGxpbms6aHJlZj0iI2EiIG92ZXJmbG93PSJ2aXNpYmxlIi8+PC9jbGlwUGF0aD48cGF0aCBjbGlwLXBhdGg9InVybCgjYikiIGQ9Ik0xMiAyQzYuNSAyIDIgNi41IDIgMTJzNC41IDEwIDEwIDEwIDEwLTQuNSAxMC0xMFMxNy41IDIgMTIgMnptNSAxNkg3di0yaDEwdjJ6bS02LjctNEw3IDEwLjdsMS40LTEuNCAxLjkgMS45IDUuMy01LjNMMTcgNy4zIDEwLjMgMTR6IiBmaWxsPSIjOUFBMEE2Ii8+PC9zdmc+);
  1121.  flex-shrink: 0;
  1122.  height: 1.4em;
  1123.  margin-inline-start: .4em;
  1124.  width: 1.4em;
  1125. }
  1126.  
  1127. /* Controls the animation (and a bit more) of the launch-downloads-home action
  1128. * button when the offline content list is expanded/shown.
  1129. */
  1130. #offline-content-list-action {
  1131.  text-align: center;
  1132.  transition: visibility 0s 200ms, opacity 200ms 200ms linear;
  1133. }
  1134.  
  1135. /* Controls the animation of the launch-downloads-home action button when the
  1136. * offline content list is collapsed/hidden.
  1137. */
  1138. #offline-content-list.list-hidden #offline-content-list-action {
  1139.  opacity: 0;
  1140.  transition: opacity 200ms linear, visibility 0s 200ms;
  1141.  visibility: hidden;
  1142. }
  1143.  
  1144. #cancel-save-page-button {
  1145.  background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ij48Y2xpcFBhdGggaWQ9Im1hc2siPjxwYXRoIGQ9Ik0xMiAyQzYuNSAyIDIgNi41IDIgMTJzNC41IDEwIDEwIDEwIDEwLTQuNSAxMC0xMFMxNy41IDIgMTIgMnptNSAxNkg3di0yaDEwdjJ6bS02LjctNEw3IDEwLjdsMS40LTEuNCAxLjkgMS45IDUuMy01LjNMMTcgNy4zIDEwLjMgMTR6IiBmaWxsPSIjOUFBMEE2Ii8+PC9jbGlwUGF0aD48cGF0aCBjbGlwLXBhdGg9InVybCgjbWFzaykiIGZpbGw9IiM5QUEwQTYiIGQ9Ik0wIDBoMjR2MjRIMHoiLz48cGF0aCBjbGlwLXBhdGg9InVybCgjbWFzaykiIGZpbGw9IiMxQTczRTgiIHN0eWxlPSJhbmltYXRpb246b2ZmbGluZUFuaW1hdGlvbiA0cyBpbmZpbml0ZSIgZD0iTTAgMGgyNHYyNEgweiIvPjxzdHlsZT5Aa2V5ZnJhbWVzIG9mZmxpbmVBbmltYXRpb257MCUsMzUle2hlaWdodDowfTYwJXtoZWlnaHQ6MTAwJX05MCV7ZmlsbC1vcGFjaXR5OjF9dG97ZmlsbC1vcGFjaXR5OjB9fTwvc3R5bGU+PC9zdmc+);
  1146.  background-position: right 27px center;
  1147.  background-repeat: no-repeat;
  1148.  border: 1px solid var(--google-gray-300);
  1149.  border-radius: 5px;
  1150.  color: var(--google-gray-700);
  1151.  margin-bottom: 26px;
  1152.  padding-bottom: 16px;
  1153.  padding-inline-end: 88px;
  1154.  padding-inline-start: 16px;
  1155.  padding-top: 16px;
  1156.  text-align: start;
  1157. }
  1158.  
  1159. html[dir='rtl'] #cancel-save-page-button {
  1160.  background-position: left 27px center;
  1161. }
  1162.  
  1163. #save-page-for-later-button {
  1164.  display: flex;
  1165.  justify-content: start;
  1166. }
  1167.  
  1168. #save-page-for-later-button a::before {
  1169.  content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxLjJlbSIgaGVpZ2h0PSIxLjJlbSIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNNSAyMGgxNHYtMkg1bTE0LTloLTRWM0g5djZINWw3IDcgNy03eiIgZmlsbD0iIzQyODVGNCIvPjwvc3ZnPg==);
  1170.  display: inline-block;
  1171.  margin-inline-end: 4px;
  1172.  vertical-align: -webkit-baseline-middle;
  1173. }
  1174.  
  1175. .hidden#save-page-for-later-button {
  1176.  display: none;
  1177. }
  1178.  
  1179. /* Don't allow overflow when in a subframe. */
  1180. html[subframe] body {
  1181.  overflow: hidden;
  1182. }
  1183.  
  1184. #sub-frame-error {
  1185.  -webkit-align-items: center;
  1186.  -webkit-flex-flow: column;
  1187.  -webkit-justify-content: center;
  1188.  background-color: #DDD;
  1189.  display: -webkit-flex;
  1190.  height: 100%;
  1191.  left: 0;
  1192.  position: absolute;
  1193.  text-align: center;
  1194.  top: 0;
  1195.  transition: background-color 200ms ease-in-out;
  1196.  width: 100%;
  1197. }
  1198.  
  1199. #sub-frame-error:hover {
  1200.  background-color: #EEE;
  1201. }
  1202.  
  1203. #sub-frame-error .icon-generic {
  1204.  margin: 0 0 16px;
  1205. }
  1206.  
  1207. #sub-frame-error-details {
  1208.  margin: 0 10px;
  1209.  text-align: center;
  1210.  visibility: hidden;
  1211. }
  1212.  
  1213. /* Show details only when hovering. */
  1214. #sub-frame-error:hover #sub-frame-error-details {
  1215.  visibility: visible;
  1216. }
  1217.  
  1218. /* If the iframe is too small, always hide the error code. */
  1219. /* TODO(mmenke): See if overflow: no-display works better, once supported. */
  1220. @media (max-width: 200px), (max-height: 95px) {
  1221.  #sub-frame-error-details {
  1222.    display: none;
  1223.  }
  1224. }
  1225.  
  1226. /* Adjust icon for small embedded frames in apps. */
  1227. @media (max-height: 100px) {
  1228.  #sub-frame-error .icon-generic {
  1229.    height: auto;
  1230.    margin: 0;
  1231.    padding-top: 0;
  1232.    width: 25px;
  1233.  }
  1234. }
  1235.  
  1236. /* details-button is special; it's a <button> element that looks like a link. */
  1237. #details-button {
  1238.  box-shadow: none;
  1239.  min-width: 0;
  1240. }
  1241.  
  1242. /* Styles for platform dependent separation of controls and details button. */
  1243. .suggested-left > #control-buttons,
  1244. .suggested-right > #details-button {
  1245.  float: left;
  1246. }
  1247.  
  1248. .suggested-right > #control-buttons,
  1249. .suggested-left > #details-button {
  1250.  float: right;
  1251. }
  1252.  
  1253. .suggested-left .secondary-button {
  1254.  margin-inline-end: 0;
  1255.  margin-inline-start: 16px;
  1256. }
  1257.  
  1258. #details-button.singular {
  1259.  float: none;
  1260. }
  1261.  
  1262. /* download-button shows both icon and text. */
  1263. #download-button {
  1264.  padding-bottom: 4px;
  1265.  padding-top: 4px;
  1266.  position: relative;
  1267. }
  1268.  
  1269. #download-button::before {
  1270.  background: -webkit-image-set(
  1271.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAQAAABKfvVzAAAAO0lEQVQ4y2NgGArgPxIY1YChsOE/LtBAmpYG0mxpIOSDBpKUo2lpIDZxNJCkHKqlYZAla3RAHQ1DFgAARRroHyLNTwwAAAAASUVORK5CYII=) 1x,
  1272.      url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAAZElEQVRYw+3Ruw3AMAwDUY3OzZUmRRD4E9iim9wNwAdbEURHyk4AAAAATiCVK8lLyPsKeT9K3lsownnunfkPxO78hKiYHxBV8x2icr5BVM+/CMf8g3DN34Rzns6ViwHUAUQ/6wIAd5Km7l6c8AAAAABJRU5ErkJggg==) 2x)
  1273.    no-repeat;
  1274.  content: '';
  1275.  display: inline-block;
  1276.  height: 24px;
  1277.  margin-inline-end: 4px;
  1278.  margin-inline-start: -4px;
  1279.  vertical-align: middle;
  1280.  width: 24px;
  1281. }
  1282.  
  1283. #download-button:disabled {
  1284.  background: rgb(180, 206, 249);
  1285.  color: rgb(255, 255, 255);
  1286. }
  1287.  
  1288. #buttons::after {
  1289.  clear: both;
  1290.  content: '';
  1291.  display: block;
  1292.  width: 100%;
  1293. }
  1294.  
  1295. /* Offline page */
  1296. html[dir='rtl'] .runner-container,
  1297. html[dir='rtl'].offline .icon-offline {
  1298.  transform: scaleX(-1);
  1299. }
  1300.  
  1301. .offline {
  1302.  transition: filter 1.5s cubic-bezier(0.65, 0.05, 0.36, 1),
  1303.              background-color 1.5s cubic-bezier(0.65, 0.05, 0.36, 1);
  1304.  
  1305.  will-change: filter, background-color;
  1306.  
  1307. }
  1308.  
  1309. .offline body {
  1310.  transition: background-color 1.5s cubic-bezier(0.65, 0.05, 0.36, 1);
  1311. }
  1312.  
  1313. .offline #main-message > p {
  1314.  display: none;
  1315. }
  1316.  
  1317. .offline.inverted {
  1318.  background-color: #fff;
  1319.  filter: invert(1);
  1320. }
  1321.  
  1322. .offline.inverted body {
  1323.  background-color: #fff;
  1324. }
  1325.  
  1326. .offline .interstitial-wrapper {
  1327.  color: var(--text-color);
  1328.  font-size: 1em;
  1329.  line-height: 1.55;
  1330.  margin: 0 auto;
  1331.  max-width: 600px;
  1332.  padding-top: 100px;
  1333.  position: relative;
  1334.  width: 100%;
  1335. }
  1336.  
  1337. .offline .runner-container {
  1338.  direction: ltr;
  1339.  height: 150px;
  1340.  max-width: 600px;
  1341.  overflow: hidden;
  1342.  position: absolute;
  1343.  top: 35px;
  1344.  width: 44px;
  1345. }
  1346.  
  1347. .offline .runner-container:focus {
  1348.  outline: none;
  1349. }
  1350.  
  1351. .offline .runner-container:focus-visible {
  1352.  outline: 3px solid var(--google-blue-300);
  1353. }
  1354.  
  1355. .offline .runner-canvas {
  1356.  height: 150px;
  1357.  max-width: 600px;
  1358.  opacity: 1;
  1359.  overflow: hidden;
  1360.  position: absolute;
  1361.  top: 0;
  1362.  z-index: 10;
  1363. }
  1364.  
  1365. .offline .controller {
  1366.  height: 100vh;
  1367.  left: 0;
  1368.  position: absolute;
  1369.  top: 0;
  1370.  width: 100vw;
  1371.  z-index: 9;
  1372. }
  1373.  
  1374. #offline-resources {
  1375.  display: none;
  1376. }
  1377.  
  1378. #offline-instruction {
  1379.  image-rendering: pixelated;
  1380.  left: 0;
  1381.  margin: auto;
  1382.  position: absolute;
  1383.  right: 0;
  1384.  top: 60px;
  1385.  width: fit-content;
  1386. }
  1387.  
  1388. .offline-runner-live-region {
  1389.  bottom: 0;
  1390.  clip-path: polygon(0 0, 0 0, 0 0);
  1391.  color: var(--background-color);
  1392.  display: block;
  1393.  font-size: xx-small;
  1394.  overflow: hidden;
  1395.  position: absolute;
  1396.  text-align: center;
  1397.  transition: color 1.5s cubic-bezier(0.65, 0.05, 0.36, 1);
  1398.  user-select: none;
  1399. }
  1400.  
  1401. /* Custom toggle */
  1402. .slow-speed-option {
  1403.  align-items: center;
  1404.  background: var(--google-gray-50);
  1405.  border-radius: 24px/50%;
  1406.  bottom: 0;
  1407.  color: var(--error-code-color);
  1408.  display: inline-flex;
  1409.  font-size: 1em;
  1410.  left: 0;
  1411.  line-height: 1.1em;
  1412.  margin: 5px auto;
  1413.  padding: 2px 12px 3px 20px;
  1414.  position: absolute;
  1415.  right: 0;
  1416.  width: max-content;
  1417.  z-index: 999;
  1418. }
  1419.  
  1420. .slow-speed-option.hidden {
  1421.  display: none;
  1422. }
  1423.  
  1424. .slow-speed-option [type=checkbox] {
  1425.  opacity: 0;
  1426.  pointer-events: none;
  1427.  position: absolute;
  1428. }
  1429.  
  1430. .slow-speed-option .slow-speed-toggle {
  1431.  cursor: pointer;
  1432.  margin-inline-start: 8px;
  1433.  padding: 8px 4px;
  1434.  position: relative;
  1435. }
  1436.  
  1437. .slow-speed-option [type=checkbox]:disabled ~ .slow-speed-toggle {
  1438.  cursor: default;
  1439. }
  1440.  
  1441. .slow-speed-option-label [type=checkbox] {
  1442.  opacity: 0;
  1443.  pointer-events: none;
  1444.  position: absolute;
  1445. }
  1446.  
  1447. .slow-speed-option .slow-speed-toggle::before,
  1448. .slow-speed-option .slow-speed-toggle::after {
  1449.  content: '';
  1450.  display: block;
  1451.  margin: 0 3px;
  1452.  transition: all 100ms cubic-bezier(0.4, 0, 1, 1);
  1453. }
  1454.  
  1455. .slow-speed-option .slow-speed-toggle::before {
  1456.  background: rgb(189,193,198);
  1457.  border-radius: 0.65em;
  1458.  height: 0.9em;
  1459.  width: 2em;
  1460. }
  1461.  
  1462. .slow-speed-option .slow-speed-toggle::after {
  1463.  background: #fff;
  1464.  border-radius: 50%;
  1465.  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 40%);
  1466.  height: 1.2em;
  1467.  position: absolute;
  1468.  top: 51%;
  1469.  transform: translate(-20%, -50%);
  1470.  width: 1.1em;
  1471. }
  1472.  
  1473. .slow-speed-option [type=checkbox]:focus + .slow-speed-toggle {
  1474.  box-shadow: 0 0 8px rgb(94, 158, 214);
  1475.  outline: 1px solid rgb(93, 157, 213);
  1476. }
  1477.  
  1478. .slow-speed-option [type=checkbox]:checked + .slow-speed-toggle::before {
  1479.  background: var(--google-blue-600);
  1480.  opacity: 0.5;
  1481. }
  1482.  
  1483. .slow-speed-option [type=checkbox]:checked + .slow-speed-toggle::after {
  1484.  background: var(--google-blue-600);
  1485.  transform: translate(calc(2em - 90%), -50%);
  1486. }
  1487.  
  1488. .slow-speed-option [type=checkbox]:checked:disabled +
  1489.  .slow-speed-toggle::before {
  1490.  background: rgb(189,193,198);
  1491. }
  1492.  
  1493. .slow-speed-option [type=checkbox]:checked:disabled +
  1494.  .slow-speed-toggle::after {
  1495.  background: var(--google-gray-50);
  1496. }
  1497.  
  1498. @media (max-width: 420px) {
  1499.  #download-button {
  1500.    padding-bottom: 12px;
  1501.    padding-top: 12px;
  1502.  }
  1503.  
  1504.  .suggested-left > #control-buttons,
  1505.  .suggested-right > #control-buttons {
  1506.    float: none;
  1507.  }
  1508.  
  1509.  .snackbar {
  1510.    border-radius: 0;
  1511.    bottom: 0;
  1512.    left: 0;
  1513.    width: 100%;
  1514.  }
  1515. }
  1516.  
  1517. @media (max-height: 350px) {
  1518.  h1 {
  1519.    margin: 0 0 15px;
  1520.  }
  1521.  
  1522.  .icon-offline {
  1523.    margin: 0 0 10px;
  1524.  }
  1525.  
  1526.  .interstitial-wrapper {
  1527.    margin-top: 5%;
  1528.  }
  1529.  
  1530.  .nav-wrapper {
  1531.    margin-top: 30px;
  1532.  }
  1533. }
  1534.  
  1535. @media (min-width: 420px) and (max-width: 736px) and
  1536.       (min-height: 240px) and (max-height: 420px) and
  1537.       (orientation:landscape) {
  1538.  .interstitial-wrapper {
  1539.    margin-bottom: 100px;
  1540.  }
  1541. }
  1542.  
  1543. @media (max-width: 360px) and (max-height: 480px) {
  1544.  .offline .interstitial-wrapper {
  1545.    padding-top: 60px;
  1546.  }
  1547.  
  1548.  .offline .runner-container {
  1549.    top: 8px;
  1550.  }
  1551. }
  1552.  
  1553. @media (min-height: 240px) and (orientation: landscape) {
  1554.  .offline .interstitial-wrapper {
  1555.    margin-bottom: 90px;
  1556.  }
  1557.  
  1558.  .icon-offline {
  1559.    margin-bottom: 20px;
  1560.  }
  1561. }
  1562.  
  1563. @media (max-height: 320px) and (orientation: landscape) {
  1564.  .icon-offline {
  1565.    margin-bottom: 0;
  1566.  }
  1567.  
  1568.  .offline .runner-container {
  1569.    top: 10px;
  1570.  }
  1571. }
  1572.  
  1573. @media (max-width: 240px) {
  1574.  button {
  1575.    padding-inline-end: 12px;
  1576.    padding-inline-start: 12px;
  1577.  }
  1578.  
  1579.  .interstitial-wrapper {
  1580.    overflow: inherit;
  1581.    padding: 0 8px;
  1582.  }
  1583. }
  1584.  
  1585. @media (max-width: 120px) {
  1586.  button {
  1587.    width: auto;
  1588.  }
  1589. }
  1590.  
  1591. .arcade-mode,
  1592. .arcade-mode .runner-container,
  1593. .arcade-mode .runner-canvas {
  1594.  image-rendering: pixelated;
  1595.  max-width: 100%;
  1596.  overflow: hidden;
  1597. }
  1598.  
  1599. .arcade-mode #buttons,
  1600. .arcade-mode #main-content {
  1601.  opacity: 0;
  1602.  overflow: hidden;
  1603. }
  1604.  
  1605. .arcade-mode .interstitial-wrapper {
  1606.  height: 100vh;
  1607.  max-width: 100%;
  1608.  overflow: hidden;
  1609. }
  1610.  
  1611. .arcade-mode .runner-container {
  1612.  left: 0;
  1613.  margin: auto;
  1614.  right: 0;
  1615.  transform-origin: top center;
  1616.  transition: transform 250ms cubic-bezier(0.4, 0, 1, 1) 400ms;
  1617.  z-index: 2;
  1618. }
  1619.  
  1620. @media (prefers-color-scheme: dark) {
  1621.  .icon {
  1622.    filter: invert(1);
  1623.  }
  1624.  
  1625.  .offline .runner-canvas {
  1626.    filter: invert(1);
  1627.  }
  1628.  
  1629.  .offline.inverted {
  1630.    background-color: var(--background-color);
  1631.    filter: invert(0);
  1632.  }
  1633.  
  1634.  .offline.inverted body {
  1635.    background-color: #fff;
  1636.  }
  1637.  
  1638.  .offline.inverted .offline-runner-live-region {
  1639.    color: #fff;
  1640.  }
  1641.  
  1642.  #suggestions-list a {
  1643.    color: var(--link-color);
  1644.  }
  1645.  
  1646.  #error-information-button {
  1647.    filter: invert(0.6);
  1648.  }
  1649.  
  1650.  .slow-speed-option {
  1651.    background: var(--google-gray-800);
  1652.    color: var(--google-gray-100);
  1653.  }
  1654.  
  1655.  .slow-speed-option .slow-speed-toggle::before,
  1656.  .slow-speed-option [type=checkbox]:checked:disabled +
  1657.    .slow-speed-toggle::before {
  1658.     background: rgb(189,193,198);
  1659.  }
  1660.  
  1661.  .slow-speed-option [type=checkbox]:checked + .slow-speed-toggle::after,
  1662.  .slow-speed-option [type=checkbox]:checked + .slow-speed-toggle::before {
  1663.    background: var(--google-blue-300);
  1664.  }
  1665. }
  1666. </style>
  1667.  <script>// Copyright 2013 The Chromium Authors
  1668. // Use of this source code is governed by a BSD-style license that can be
  1669. // found in the LICENSE file.
  1670.  
  1671. /**
  1672. * @typedef {{
  1673. *   downloadButtonClick: function(),
  1674. *   reloadButtonClick: function(string),
  1675. *   detailsButtonClick: function(),
  1676. *   diagnoseErrorsButtonClick: function(),
  1677. *   portalSigninsButtonClick: function(),
  1678. *   trackEasterEgg: function(),
  1679. *   updateEasterEggHighScore: function(number),
  1680. *   resetEasterEggHighScore: function(),
  1681. *   launchOfflineItem: function(string, string),
  1682. *   savePageForLater: function(),
  1683. *   cancelSavePage: function(),
  1684. *   listVisibilityChange: function(boolean),
  1685. * }}
  1686. */
  1687. // eslint-disable-next-line no-var
  1688. var errorPageController;
  1689.  
  1690. const HIDDEN_CLASS = 'hidden';
  1691.  
  1692. // Decodes a UTF16 string that is encoded as base64.
  1693. function decodeUTF16Base64ToString(encoded_text) {
  1694.  const data = atob(encoded_text);
  1695.  let result = '';
  1696.  for (let i = 0; i < data.length; i += 2) {
  1697.    result +=
  1698.        String.fromCharCode(data.charCodeAt(i) * 256 + data.charCodeAt(i + 1));
  1699.  }
  1700.  return result;
  1701. }
  1702.  
  1703. function toggleHelpBox() {
  1704.  const helpBoxOuter = document.getElementById('details');
  1705.  helpBoxOuter.classList.toggle(HIDDEN_CLASS);
  1706.  const detailsButton = document.getElementById('details-button');
  1707.  if (helpBoxOuter.classList.contains(HIDDEN_CLASS)) {
  1708.    /** @suppress {missingProperties} */
  1709.    detailsButton.innerText = detailsButton.detailsText;
  1710.  } else {
  1711.    /** @suppress {missingProperties} */
  1712.    detailsButton.innerText = detailsButton.hideDetailsText;
  1713.  }
  1714.  
  1715.  // Details appears over the main content on small screens.
  1716.  if (mobileNav) {
  1717.    document.getElementById('main-content').classList.toggle(HIDDEN_CLASS);
  1718.    const runnerContainer = document.querySelector('.runner-container');
  1719.    if (runnerContainer) {
  1720.      runnerContainer.classList.toggle(HIDDEN_CLASS);
  1721.    }
  1722.  }
  1723. }
  1724.  
  1725. function diagnoseErrors() {
  1726.  if (window.errorPageController) {
  1727.    errorPageController.diagnoseErrorsButtonClick();
  1728.  }
  1729. }
  1730.  
  1731. function portalSignin() {
  1732.  if (window.errorPageController) {
  1733.    errorPageController.portalSigninButtonClick();
  1734.  }
  1735. }
  1736.  
  1737. // Subframes use a different layout but the same html file.  This is to make it
  1738. // easier to support platforms that load the error page via different
  1739. // mechanisms (Currently just iOS). We also use the subframe style for portals
  1740. // as they are embedded like subframes and can't be interacted with by the user.
  1741. let isSubFrame = false;
  1742. if (window.top.location !== window.location || window.portalHost) {
  1743.  document.documentElement.setAttribute('subframe', '');
  1744.  isSubFrame = true;
  1745. }
  1746.  
  1747. // Re-renders the error page using |strings| as the dictionary of values.
  1748. // Used by NetErrorTabHelper to update DNS error pages with probe results.
  1749. function updateForDnsProbe(strings) {
  1750.  const context = new JsEvalContext(strings);
  1751.  jstProcess(context, document.getElementById('t'));
  1752.  onDocumentLoadOrUpdate();
  1753. }
  1754.  
  1755. // Adds an icon class to the list and removes classes previously set.
  1756. function updateIconClass(newClass) {
  1757.  const frameSelector = isSubFrame ? '#sub-frame-error' : '#main-frame-error';
  1758.  const iconEl = document.querySelector(frameSelector + ' .icon');
  1759.  
  1760.  if (iconEl.classList.contains(newClass)) {
  1761.    return;
  1762.  }
  1763.  
  1764.  iconEl.className = 'icon ' + newClass;
  1765. }
  1766.  
  1767. // Implements button clicks.  This function is needed during the transition
  1768. // between implementing these in trunk chromium and implementing them in iOS.
  1769. function reloadButtonClick(url) {
  1770.  if (window.errorPageController) {
  1771.    //
  1772.  
  1773.    //
  1774.    errorPageController.reloadButtonClick();
  1775.    //
  1776.  } else {
  1777.    window.location = url;
  1778.  }
  1779. }
  1780.  
  1781. function downloadButtonClick() {
  1782.  if (window.errorPageController) {
  1783.    errorPageController.downloadButtonClick();
  1784.    const downloadButton = document.getElementById('download-button');
  1785.    downloadButton.disabled = true;
  1786.    /** @suppress {missingProperties} */
  1787.    downloadButton.textContent = downloadButton.disabledText;
  1788.  
  1789.    document.getElementById('download-link-wrapper')
  1790.        .classList.add(HIDDEN_CLASS);
  1791.    document.getElementById('download-link-clicked-wrapper')
  1792.        .classList.remove(HIDDEN_CLASS);
  1793.  }
  1794. }
  1795.  
  1796. function detailsButtonClick() {
  1797.  if (window.errorPageController) {
  1798.    errorPageController.detailsButtonClick();
  1799.  }
  1800. }
  1801.  
  1802. let primaryControlOnLeft = true;
  1803. // clang-format off
  1804. //
  1805.  
  1806. function setAutoFetchState(scheduled, can_schedule) {
  1807.  document.getElementById('cancel-save-page-button')
  1808.      .classList.toggle(HIDDEN_CLASS, !scheduled);
  1809.  document.getElementById('save-page-for-later-button')
  1810.      .classList.toggle(HIDDEN_CLASS, scheduled || !can_schedule);
  1811. }
  1812.  
  1813. function savePageLaterClick() {
  1814.  errorPageController.savePageForLater();
  1815.  // savePageForLater will eventually trigger a call to setAutoFetchState() when
  1816.  // it completes.
  1817. }
  1818.  
  1819. function cancelSavePageClick() {
  1820.  errorPageController.cancelSavePage();
  1821.  // setAutoFetchState is not called in response to cancelSavePage(), so do it
  1822.  // now.
  1823.  setAutoFetchState(false, true);
  1824. }
  1825.  
  1826. function toggleErrorInformationPopup() {
  1827.  document.getElementById('error-information-popup-container')
  1828.      .classList.toggle(HIDDEN_CLASS);
  1829. }
  1830.  
  1831. function launchOfflineItem(itemID, name_space) {
  1832.  errorPageController.launchOfflineItem(itemID, name_space);
  1833. }
  1834.  
  1835. function launchDownloadsPage() {
  1836.  errorPageController.launchDownloadsPage();
  1837. }
  1838.  
  1839. function getIconForSuggestedItem(item) {
  1840.  // Note: |item.content_type| contains the enum values from
  1841.  // chrome::mojom::AvailableContentType.
  1842.  switch (item.content_type) {
  1843.    case 1:  // kVideo
  1844.      return 'image-video';
  1845.    case 2:  // kAudio
  1846.      return 'image-music-note';
  1847.    case 0:  // kPrefetchedPage
  1848.    case 3:  // kOtherPage
  1849.      return 'image-earth';
  1850.  }
  1851.  return 'image-file';
  1852. }
  1853.  
  1854. function getSuggestedContentDiv(item, index) {
  1855.  // Note: See AvailableContentToValue in available_offline_content_helper.cc
  1856.  // for the data contained in an |item|.
  1857.  // TODO(carlosk): Present |snippet_base64| when that content becomes
  1858.  // available.
  1859.  let thumbnail = '';
  1860.  const extraContainerClasses = [];
  1861.  // html_inline.py will try to replace src attributes with data URIs using a
  1862.  // simple regex. The following is obfuscated slightly to avoid that.
  1863.  const source = 'src';
  1864.  if (item.thumbnail_data_uri) {
  1865.    extraContainerClasses.push('suggestion-with-image');
  1866.    thumbnail = `<img ${source}="${item.thumbnail_data_uri}">`;
  1867.  } else {
  1868.    extraContainerClasses.push('suggestion-with-icon');
  1869.    const iconClass = getIconForSuggestedItem(item);
  1870.    thumbnail = `<div><img class="${iconClass}"></div>`;
  1871.  }
  1872.  
  1873.  let favicon = '';
  1874.  if (item.favicon_data_uri) {
  1875.    favicon = `<img ${source}="${item.favicon_data_uri}">`;
  1876.  } else {
  1877.    extraContainerClasses.push('no-favicon');
  1878.  }
  1879.  
  1880.  if (!item.attribution_base64) {
  1881.    extraContainerClasses.push('no-attribution');
  1882.  }
  1883.  
  1884.  return `
  1885.  <div class="offline-content-suggestion ${extraContainerClasses.join(' ')}"
  1886.    onclick="launchOfflineItem('${item.ID}', '${item.name_space}')">
  1887.      <div class="offline-content-suggestion-texts">
  1888.        <div id="offline-content-suggestion-title-${index}"
  1889.             class="offline-content-suggestion-title">
  1890.        </div>
  1891.        <div class="offline-content-suggestion-attribution-freshness">
  1892.          <div id="offline-content-suggestion-favicon-${index}"
  1893.               class="offline-content-suggestion-favicon">
  1894.            ${favicon}
  1895.          </div>
  1896.          <div id="offline-content-suggestion-attribution-${index}"
  1897.               class="offline-content-suggestion-attribution">
  1898.          </div>
  1899.          <div class="offline-content-suggestion-freshness">
  1900.            ${item.date_modified}
  1901.          </div>
  1902.          <div class="offline-content-suggestion-pin-spacer"></div>
  1903.          <div class="offline-content-suggestion-pin"></div>
  1904.        </div>
  1905.      </div>
  1906.      <div class="offline-content-suggestion-thumbnail">
  1907.        ${thumbnail}
  1908.      </div>
  1909.  </div>`;
  1910. }
  1911.  
  1912. /**
  1913. * @typedef {{
  1914. *   ID: string,
  1915. *   name_space: string,
  1916. *   title_base64: string,
  1917. *   snippet_base64: string,
  1918. *   date_modified: string,
  1919. *   attribution_base64: string,
  1920. *   thumbnail_data_uri: string,
  1921. *   favicon_data_uri: string,
  1922. *   content_type: number,
  1923. * }}
  1924. */
  1925. let AvailableOfflineContent;
  1926.  
  1927. // Populates a list of suggested offline content.
  1928. // Note: For security reasons all content downloaded from the web is considered
  1929. // unsafe and must be securely handled to be presented on the dino page. Images
  1930. // have already been safely re-encoded but textual content -- like title and
  1931. // attribution -- must be properly handled here.
  1932. // @param {boolean} isShown
  1933. // @param {Array<AvailableOfflineContent>} suggestions
  1934. function offlineContentAvailable(isShown, suggestions) {
  1935.  if (!suggestions || !loadTimeData.valueExists('offlineContentList')) {
  1936.    return;
  1937.  }
  1938.  
  1939.  const suggestionsHTML = [];
  1940.  for (let index = 0; index < suggestions.length; index++) {
  1941.    suggestionsHTML.push(getSuggestedContentDiv(suggestions[index], index));
  1942.  }
  1943.  
  1944.  document.getElementById('offline-content-suggestions').innerHTML =
  1945.      suggestionsHTML.join('\n');
  1946.  
  1947.  // Sets textual web content using |textContent| to make sure it's handled as
  1948.  // plain text.
  1949.  for (let index = 0; index < suggestions.length; index++) {
  1950.    document.getElementById(`offline-content-suggestion-title-${index}`)
  1951.        .textContent =
  1952.        decodeUTF16Base64ToString(suggestions[index].title_base64);
  1953.    document.getElementById(`offline-content-suggestion-attribution-${index}`)
  1954.        .textContent =
  1955.        decodeUTF16Base64ToString(suggestions[index].attribution_base64);
  1956.  }
  1957.  
  1958.  const contentListElement = document.getElementById('offline-content-list');
  1959.  if (document.dir === 'rtl') {
  1960.    contentListElement.classList.add('is-rtl');
  1961.  }
  1962.  contentListElement.hidden = false;
  1963.  // The list is configured as hidden by default. Show it if needed.
  1964.  if (isShown) {
  1965.    toggleOfflineContentListVisibility(false);
  1966.  }
  1967. }
  1968.  
  1969. function toggleOfflineContentListVisibility(updatePref) {
  1970.  if (!loadTimeData.valueExists('offlineContentList')) {
  1971.    return;
  1972.  }
  1973.  
  1974.  const contentListElement = document.getElementById('offline-content-list');
  1975.  const isVisible = !contentListElement.classList.toggle('list-hidden');
  1976.  
  1977.  if (updatePref && window.errorPageController) {
  1978.    errorPageController.listVisibilityChanged(isVisible);
  1979.  }
  1980. }
  1981.  
  1982. // Called on document load, and from updateForDnsProbe().
  1983. function onDocumentLoadOrUpdate() {
  1984.  const downloadButtonVisible = loadTimeData.valueExists('downloadButton') &&
  1985.      loadTimeData.getValue('downloadButton').msg;
  1986.  const detailsButton = document.getElementById('details-button');
  1987.  
  1988.  // If offline content suggestions will be visible, the usual buttons will not
  1989.  // be presented.
  1990.  const offlineContentVisible =
  1991.      loadTimeData.valueExists('suggestedOfflineContentPresentation');
  1992.  if (offlineContentVisible) {
  1993.    document.querySelector('.nav-wrapper').classList.add(HIDDEN_CLASS);
  1994.    detailsButton.classList.add(HIDDEN_CLASS);
  1995.  
  1996.    document.getElementById('download-link').hidden = !downloadButtonVisible;
  1997.    document.getElementById('download-links-wrapper')
  1998.        .classList.remove(HIDDEN_CLASS);
  1999.    document.getElementById('error-information-popup-container')
  2000.        .classList.add('use-popup-container', HIDDEN_CLASS);
  2001.    document.getElementById('error-information-button')
  2002.        .classList.remove(HIDDEN_CLASS);
  2003.  }
  2004.  
  2005.  const attemptAutoFetch = loadTimeData.valueExists('attemptAutoFetch') &&
  2006.      loadTimeData.getValue('attemptAutoFetch');
  2007.  
  2008.  const reloadButtonVisible = loadTimeData.valueExists('reloadButton') &&
  2009.      loadTimeData.getValue('reloadButton').msg;
  2010.  
  2011.  const reloadButton = document.getElementById('reload-button');
  2012.  const downloadButton = document.getElementById('download-button');
  2013.  if (reloadButton.style.display === 'none' &&
  2014.      downloadButton.style.display === 'none') {
  2015.    detailsButton.classList.add('singular');
  2016.  }
  2017.  
  2018.  // Show or hide control buttons.
  2019.  const controlButtonDiv = document.getElementById('control-buttons');
  2020.  controlButtonDiv.hidden =
  2021.      offlineContentVisible || !(reloadButtonVisible || downloadButtonVisible);
  2022.  
  2023.  const iconClass = loadTimeData.valueExists('iconClass') &&
  2024.      loadTimeData.getValue('iconClass');
  2025.  
  2026.  updateIconClass(iconClass);
  2027.  
  2028.  if (!isSubFrame && iconClass === 'icon-offline') {
  2029.    document.documentElement.classList.add('offline');
  2030.    new Runner('.interstitial-wrapper');
  2031.  }
  2032. }
  2033.  
  2034. function onDocumentLoad() {
  2035.  // Sets up the proper button layout for the current platform.
  2036.  const buttonsDiv = document.getElementById('buttons');
  2037.  if (primaryControlOnLeft) {
  2038.    buttonsDiv.classList.add('suggested-left');
  2039.  } else {
  2040.    buttonsDiv.classList.add('suggested-right');
  2041.  }
  2042.  
  2043.  onDocumentLoadOrUpdate();
  2044. }
  2045.  
  2046. document.addEventListener('DOMContentLoaded', onDocumentLoad);
  2047. </script>
  2048.  <script>// Copyright 2015 The Chromium Authors
  2049. // Use of this source code is governed by a BSD-style license that can be
  2050. // found in the LICENSE file.
  2051.  
  2052. let mobileNav = false;
  2053.  
  2054. /**
  2055. * For small screen mobile the navigation buttons are moved
  2056. * below the advanced text.
  2057. */
  2058. function onResize() {
  2059.  const helpOuterBox = document.querySelector('#details');
  2060.  const mainContent = document.querySelector('#main-content');
  2061.  const mediaQuery = '(min-width: 240px) and (max-width: 420px) and ' +
  2062.      '(min-height: 401px), ' +
  2063.      '(max-height: 560px) and (min-height: 240px) and ' +
  2064.      '(min-width: 421px)';
  2065.  
  2066.  const detailsHidden = helpOuterBox.classList.contains(HIDDEN_CLASS);
  2067.  const runnerContainer = document.querySelector('.runner-container');
  2068.  
  2069.  // Check for change in nav status.
  2070.  if (mobileNav !== window.matchMedia(mediaQuery).matches) {
  2071.    mobileNav = !mobileNav;
  2072.  
  2073.    // Handle showing the top content / details sections according to state.
  2074.    if (mobileNav) {
  2075.      mainContent.classList.toggle(HIDDEN_CLASS, !detailsHidden);
  2076.      helpOuterBox.classList.toggle(HIDDEN_CLASS, detailsHidden);
  2077.      if (runnerContainer) {
  2078.        runnerContainer.classList.toggle(HIDDEN_CLASS, !detailsHidden);
  2079.      }
  2080.    } else if (!detailsHidden) {
  2081.      // Non mobile nav with visible details.
  2082.      mainContent.classList.remove(HIDDEN_CLASS);
  2083.      helpOuterBox.classList.remove(HIDDEN_CLASS);
  2084.      if (runnerContainer) {
  2085.        runnerContainer.classList.remove(HIDDEN_CLASS);
  2086.      }
  2087.    }
  2088.  }
  2089. }
  2090.  
  2091. function setupMobileNav() {
  2092.  window.addEventListener('resize', onResize);
  2093.  onResize();
  2094. }
  2095.  
  2096. document.addEventListener('DOMContentLoaded', setupMobileNav);
  2097. </script>
  2098.  <script>// Copyright 2014 The Chromium Authors
  2099. // Use of this source code is governed by a BSD-style license that can be
  2100. // found in the LICENSE file.
  2101.  
  2102. /**
  2103. * T-Rex runner.
  2104. * @param {string} outerContainerId Outer containing element id.
  2105. * @param {!Object=} opt_config
  2106. * @constructor
  2107. * @implements {EventListener}
  2108. * @export
  2109. */
  2110. function Runner(outerContainerId, opt_config) {
  2111.  // Singleton
  2112.  if (Runner.instance_) {
  2113.    return Runner.instance_;
  2114.  }
  2115.  Runner.instance_ = this;
  2116.  
  2117.  this.outerContainerEl = document.querySelector(outerContainerId);
  2118.  this.containerEl = null;
  2119.  this.snackbarEl = null;
  2120.  // A div to intercept touch events. Only set while (playing && useTouch).
  2121.  this.touchController = null;
  2122.  
  2123.  this.config = opt_config || Object.assign(Runner.config, Runner.normalConfig);
  2124.  // Logical dimensions of the container.
  2125.  this.dimensions = Runner.defaultDimensions;
  2126.  
  2127.  this.gameType = null;
  2128.  Runner.spriteDefinition = Runner.spriteDefinitionByType['original'];
  2129.  
  2130.  this.altGameImageSprite = null;
  2131.  this.altGameModeActive = false;
  2132.  this.altGameModeFlashTimer = null;
  2133.  this.fadeInTimer = 0;
  2134.  
  2135.  this.canvas = null;
  2136.  this.canvasCtx = null;
  2137.  
  2138.  this.tRex = null;
  2139.  
  2140.  this.distanceMeter = null;
  2141.  this.distanceRan = 0;
  2142.  
  2143.  this.highestScore = 0;
  2144.  this.syncHighestScore = false;
  2145.  
  2146.  this.time = 0;
  2147.  this.runningTime = 0;
  2148.  this.msPerFrame = 1000 / FPS;
  2149.  this.currentSpeed = this.config.SPEED;
  2150.  Runner.slowDown = false;
  2151.  
  2152.  this.obstacles = [];
  2153.  
  2154.  this.activated = false; // Whether the easter egg has been activated.
  2155.  this.playing = false; // Whether the game is currently in play state.
  2156.  this.crashed = false;
  2157.  this.paused = false;
  2158.  this.inverted = false;
  2159.  this.invertTimer = 0;
  2160.  this.resizeTimerId_ = null;
  2161.  
  2162.  this.playCount = 0;
  2163.  
  2164.  // Sound FX.
  2165.  this.audioBuffer = null;
  2166.  
  2167.  /** @type {Object} */
  2168.  this.soundFx = {};
  2169.  this.generatedSoundFx = null;
  2170.  
  2171.  // Global web audio context for playing sounds.
  2172.  this.audioContext = null;
  2173.  
  2174.  // Images.
  2175.  this.images = {};
  2176.  this.imagesLoaded = 0;
  2177.  
  2178.  // Gamepad state.
  2179.  this.pollingGamepads = false;
  2180.  this.gamepadIndex = undefined;
  2181.  this.previousGamepad = null;
  2182.  
  2183.  if (this.isDisabled()) {
  2184.    this.setupDisabledRunner();
  2185.  } else {
  2186.    if (Runner.isAltGameModeEnabled()) {
  2187.      this.initAltGameType();
  2188.      Runner.gameType = this.gameType;
  2189.    }
  2190.    this.loadImages();
  2191.  
  2192.    window['initializeEasterEggHighScore'] =
  2193.        this.initializeHighScore.bind(this);
  2194.  }
  2195. }
  2196.  
  2197. /**
  2198. * Default game width.
  2199. * @const
  2200. */
  2201. const DEFAULT_WIDTH = 600;
  2202.  
  2203. /**
  2204. * Frames per second.
  2205. * @const
  2206. */
  2207. const FPS = 60;
  2208.  
  2209. /** @const */
  2210. const IS_HIDPI = window.devicePixelRatio > 1;
  2211.  
  2212. /** @const */
  2213. const IS_IOS = /CriOS/.test(window.navigator.userAgent);
  2214.  
  2215. /** @const */
  2216. const IS_MOBILE = /Android/.test(window.navigator.userAgent) || IS_IOS;
  2217.  
  2218. /** @const */
  2219. const IS_RTL = document.querySelector('html').dir == 'rtl';
  2220.  
  2221. /** @const */
  2222. const ARCADE_MODE_URL = 'chrome://dino/';
  2223.  
  2224. /** @const */
  2225. const RESOURCE_POSTFIX = 'offline-resources-';
  2226.  
  2227. /** @const */
  2228. const A11Y_STRINGS = {
  2229.  ariaLabel: 'dinoGameA11yAriaLabel',
  2230.  description: 'dinoGameA11yDescription',
  2231.  gameOver: 'dinoGameA11yGameOver',
  2232.  highScore: 'dinoGameA11yHighScore',
  2233.  jump: 'dinoGameA11yJump',
  2234.  started: 'dinoGameA11yStartGame',
  2235.  speedLabel: 'dinoGameA11ySpeedToggle',
  2236. };
  2237.  
  2238. /**
  2239. * Default game configuration.
  2240. * Shared config for all  versions of the game. Additional parameters are
  2241. * defined in Runner.normalConfig and Runner.slowConfig.
  2242. */
  2243. Runner.config = {
  2244.  AUDIOCUE_PROXIMITY_THRESHOLD: 190,
  2245.  AUDIOCUE_PROXIMITY_THRESHOLD_MOBILE_A11Y: 250,
  2246.  BG_CLOUD_SPEED: 0.2,
  2247.  BOTTOM_PAD: 10,
  2248.  // Scroll Y threshold at which the game can be activated.
  2249.  CANVAS_IN_VIEW_OFFSET: -10,
  2250.  CLEAR_TIME: 3000,
  2251.  CLOUD_FREQUENCY: 0.5,
  2252.  FADE_DURATION: 1,
  2253.  FLASH_DURATION: 1000,
  2254.  GAMEOVER_CLEAR_TIME: 1200,
  2255.  INITIAL_JUMP_VELOCITY: 12,
  2256.  INVERT_FADE_DURATION: 12000,
  2257.  MAX_BLINK_COUNT: 3,
  2258.  MAX_CLOUDS: 6,
  2259.  MAX_OBSTACLE_LENGTH: 3,
  2260.  MAX_OBSTACLE_DUPLICATION: 2,
  2261.  RESOURCE_TEMPLATE_ID: 'audio-resources',
  2262.  SPEED: 6,
  2263.  SPEED_DROP_COEFFICIENT: 3,
  2264.  ARCADE_MODE_INITIAL_TOP_POSITION: 35,
  2265.  ARCADE_MODE_TOP_POSITION_PERCENT: 0.1,
  2266. };
  2267.  
  2268. Runner.normalConfig = {
  2269.  ACCELERATION: 0.001,
  2270.  AUDIOCUE_PROXIMITY_THRESHOLD: 190,
  2271.  AUDIOCUE_PROXIMITY_THRESHOLD_MOBILE_A11Y: 250,
  2272.  GAP_COEFFICIENT: 0.6,
  2273.  INVERT_DISTANCE: 700,
  2274.  MAX_SPEED: 13,
  2275.  MOBILE_SPEED_COEFFICIENT: 1.2,
  2276.  SPEED: 6,
  2277. };
  2278.  
  2279.  
  2280. Runner.slowConfig = {
  2281.  ACCELERATION: 0.0005,
  2282.  AUDIOCUE_PROXIMITY_THRESHOLD: 170,
  2283.  AUDIOCUE_PROXIMITY_THRESHOLD_MOBILE_A11Y: 220,
  2284.  GAP_COEFFICIENT: 0.3,
  2285.  INVERT_DISTANCE: 350,
  2286.  MAX_SPEED: 9,
  2287.  MOBILE_SPEED_COEFFICIENT: 1.5,
  2288.  SPEED: 4.2,
  2289. };
  2290.  
  2291.  
  2292. /**
  2293. * Default dimensions.
  2294. */
  2295. Runner.defaultDimensions = {
  2296.  WIDTH: DEFAULT_WIDTH,
  2297.  HEIGHT: 150,
  2298. };
  2299.  
  2300.  
  2301. /**
  2302. * CSS class names.
  2303. * @enum {string}
  2304. */
  2305. Runner.classes = {
  2306.  ARCADE_MODE: 'arcade-mode',
  2307.  CANVAS: 'runner-canvas',
  2308.  CONTAINER: 'runner-container',
  2309.  CRASHED: 'crashed',
  2310.  ICON: 'icon-offline',
  2311.  INVERTED: 'inverted',
  2312.  SNACKBAR: 'snackbar',
  2313.  SNACKBAR_SHOW: 'snackbar-show',
  2314.  TOUCH_CONTROLLER: 'controller',
  2315. };
  2316.  
  2317.  
  2318. /**
  2319. * Sound FX. Reference to the ID of the audio tag on interstitial page.
  2320. * @enum {string}
  2321. */
  2322. Runner.sounds = {
  2323.  BUTTON_PRESS: 'offline-sound-press',
  2324.  HIT: 'offline-sound-hit',
  2325.  SCORE: 'offline-sound-reached',
  2326. };
  2327.  
  2328.  
  2329. /**
  2330. * Key code mapping.
  2331. * @enum {Object}
  2332. */
  2333. Runner.keycodes = {
  2334.  JUMP: {'38': 1, '32': 1},  // Up, spacebar
  2335.  DUCK: {'40': 1},           // Down
  2336.  RESTART: {'13': 1},        // Enter
  2337. };
  2338.  
  2339.  
  2340. /**
  2341. * Runner event names.
  2342. * @enum {string}
  2343. */
  2344. Runner.events = {
  2345.  ANIM_END: 'webkitAnimationEnd',
  2346.  CLICK: 'click',
  2347.  KEYDOWN: 'keydown',
  2348.  KEYUP: 'keyup',
  2349.  POINTERDOWN: 'pointerdown',
  2350.  POINTERUP: 'pointerup',
  2351.  RESIZE: 'resize',
  2352.  TOUCHEND: 'touchend',
  2353.  TOUCHSTART: 'touchstart',
  2354.  VISIBILITY: 'visibilitychange',
  2355.  BLUR: 'blur',
  2356.  FOCUS: 'focus',
  2357.  LOAD: 'load',
  2358.  GAMEPADCONNECTED: 'gamepadconnected',
  2359. };
  2360.  
  2361. Runner.prototype = {
  2362.  /**
  2363.   * Initialize alternative game type.
  2364.   */
  2365.  initAltGameType() {
  2366.    if (GAME_TYPE.length > 0) {
  2367.      this.gameType = loadTimeData && loadTimeData.valueExists('altGameType') ?
  2368.          GAME_TYPE[parseInt(loadTimeData.getValue('altGameType'), 10) - 1] :
  2369.          '';
  2370.    }
  2371.  },
  2372.  
  2373.  /**
  2374.   * Whether the easter egg has been disabled. CrOS enterprise enrolled devices.
  2375.   * @return {boolean}
  2376.   */
  2377.  isDisabled() {
  2378.    return loadTimeData && loadTimeData.valueExists('disabledEasterEgg');
  2379.  },
  2380.  
  2381.  /**
  2382.   * For disabled instances, set up a snackbar with the disabled message.
  2383.   */
  2384.  setupDisabledRunner() {
  2385.    this.containerEl = document.createElement('div');
  2386.    this.containerEl.className = Runner.classes.SNACKBAR;
  2387.    this.containerEl.textContent = loadTimeData.getValue('disabledEasterEgg');
  2388.    this.outerContainerEl.appendChild(this.containerEl);
  2389.  
  2390.    // Show notification when the activation key is pressed.
  2391.    document.addEventListener(Runner.events.KEYDOWN, function(e) {
  2392.      if (Runner.keycodes.JUMP[e.keyCode]) {
  2393.        this.containerEl.classList.add(Runner.classes.SNACKBAR_SHOW);
  2394.        document.querySelector('.icon').classList.add('icon-disabled');
  2395.      }
  2396.    }.bind(this));
  2397.  },
  2398.  
  2399.  /**
  2400.   * Setting individual settings for debugging.
  2401.   * @param {string} setting
  2402.   * @param {number|string} value
  2403.   */
  2404.  updateConfigSetting(setting, value) {
  2405.    if (setting in this.config && value !== undefined) {
  2406.      this.config[setting] = value;
  2407.  
  2408.      switch (setting) {
  2409.        case 'GRAVITY':
  2410.        case 'MIN_JUMP_HEIGHT':
  2411.        case 'SPEED_DROP_COEFFICIENT':
  2412.          this.tRex.config[setting] = value;
  2413.          break;
  2414.        case 'INITIAL_JUMP_VELOCITY':
  2415.          this.tRex.setJumpVelocity(value);
  2416.          break;
  2417.        case 'SPEED':
  2418.          this.setSpeed(/** @type {number} */ (value));
  2419.          break;
  2420.      }
  2421.    }
  2422.  },
  2423.  
  2424.  /**
  2425.   * Creates an on page image element from the base 64 encoded string source.
  2426.   * @param {string} resourceName Name in data object,
  2427.   * @return {HTMLImageElement} The created element.
  2428.   */
  2429.  createImageElement(resourceName) {
  2430.    const imgSrc = loadTimeData && loadTimeData.valueExists(resourceName) ?
  2431.        loadTimeData.getString(resourceName) :
  2432.        null;
  2433.  
  2434.    if (imgSrc) {
  2435.      const el =
  2436.          /** @type {HTMLImageElement} */ (document.createElement('img'));
  2437.      el.id = resourceName;
  2438.      el.src = imgSrc;
  2439.      document.getElementById('offline-resources').appendChild(el);
  2440.      return el;
  2441.    }
  2442.    return null;
  2443.  },
  2444.  
  2445.  /**
  2446.   * Cache the appropriate image sprite from the page and get the sprite sheet
  2447.   * definition.
  2448.   */
  2449.  loadImages() {
  2450.    let scale = '1x';
  2451.    this.spriteDef = Runner.spriteDefinition.LDPI;
  2452.    if (IS_HIDPI) {
  2453.      scale = '2x';
  2454.      this.spriteDef = Runner.spriteDefinition.HDPI;
  2455.    }
  2456.  
  2457.    Runner.imageSprite = /** @type {HTMLImageElement} */
  2458.        (document.getElementById(RESOURCE_POSTFIX + scale));
  2459.  
  2460.    if (this.gameType) {
  2461.      Runner.altGameImageSprite = /** @type {HTMLImageElement} */
  2462.          (this.createImageElement('altGameSpecificImage' + scale));
  2463.      Runner.altCommonImageSprite = /** @type {HTMLImageElement} */
  2464.          (this.createImageElement('altGameCommonImage' + scale));
  2465.    }
  2466.    Runner.origImageSprite = Runner.imageSprite;
  2467.  
  2468.    // Disable the alt game mode if the sprites can't be loaded.
  2469.    if (!Runner.altGameImageSprite || !Runner.altCommonImageSprite) {
  2470.      Runner.isAltGameModeEnabled = () => false;
  2471.      this.altGameModeActive = false;
  2472.    }
  2473.  
  2474.    if (Runner.imageSprite.complete) {
  2475.      this.init();
  2476.    } else {
  2477.      // If the images are not yet loaded, add a listener.
  2478.      Runner.imageSprite.addEventListener(Runner.events.LOAD,
  2479.          this.init.bind(this));
  2480.    }
  2481.  },
  2482.  
  2483.  /**
  2484.   * Load and decode base 64 encoded sounds.
  2485.   */
  2486.  loadSounds() {
  2487.    if (!IS_IOS) {
  2488.      this.audioContext = new AudioContext();
  2489.  
  2490.      const resourceTemplate =
  2491.          document.getElementById(this.config.RESOURCE_TEMPLATE_ID).content;
  2492.  
  2493.      for (const sound in Runner.sounds) {
  2494.        let soundSrc =
  2495.            resourceTemplate.getElementById(Runner.sounds[sound]).src;
  2496.        soundSrc = soundSrc.substr(soundSrc.indexOf(',') + 1);
  2497.        const buffer = decodeBase64ToArrayBuffer(soundSrc);
  2498.  
  2499.        // Async, so no guarantee of order in array.
  2500.        this.audioContext.decodeAudioData(buffer, function(index, audioData) {
  2501.            this.soundFx[index] = audioData;
  2502.          }.bind(this, sound));
  2503.      }
  2504.    }
  2505.  },
  2506.  
  2507.  /**
  2508.   * Sets the game speed. Adjust the speed accordingly if on a smaller screen.
  2509.   * @param {number=} opt_speed
  2510.   */
  2511.  setSpeed(opt_speed) {
  2512.    const speed = opt_speed || this.currentSpeed;
  2513.  
  2514.    // Reduce the speed on smaller mobile screens.
  2515.    if (this.dimensions.WIDTH < DEFAULT_WIDTH) {
  2516.      const mobileSpeed = Runner.slowDown ? speed :
  2517.                                            speed * this.dimensions.WIDTH /
  2518.              DEFAULT_WIDTH * this.config.MOBILE_SPEED_COEFFICIENT;
  2519.      this.currentSpeed = mobileSpeed > speed ? speed : mobileSpeed;
  2520.    } else if (opt_speed) {
  2521.      this.currentSpeed = opt_speed;
  2522.    }
  2523.  },
  2524.  
  2525.  /**
  2526.   * Game initialiser.
  2527.   */
  2528.  init() {
  2529.    // Hide the static icon.
  2530.    document.querySelector('.' + Runner.classes.ICON).style.visibility =
  2531.        'hidden';
  2532.  
  2533.    this.adjustDimensions();
  2534.    this.setSpeed();
  2535.  
  2536.    const ariaLabel = getA11yString(A11Y_STRINGS.ariaLabel);
  2537.    this.containerEl = document.createElement('div');
  2538.    this.containerEl.setAttribute('role', IS_MOBILE ? 'button' : 'application');
  2539.    this.containerEl.setAttribute('tabindex', '0');
  2540.    this.containerEl.setAttribute('title', ariaLabel);
  2541.  
  2542.    this.containerEl.className = Runner.classes.CONTAINER;
  2543.  
  2544.    // Player canvas container.
  2545.    this.canvas = createCanvas(this.containerEl, this.dimensions.WIDTH,
  2546.        this.dimensions.HEIGHT);
  2547.  
  2548.    // Live region for game status updates.
  2549.    this.a11yStatusEl = document.createElement('span');
  2550.    this.a11yStatusEl.className = 'offline-runner-live-region';
  2551.    this.a11yStatusEl.setAttribute('aria-live', 'assertive');
  2552.    this.a11yStatusEl.textContent = '';
  2553.    Runner.a11yStatusEl = this.a11yStatusEl;
  2554.  
  2555.    // Add checkbox to slow down the game.
  2556.    this.slowSpeedCheckboxLabel = document.createElement('label');
  2557.    this.slowSpeedCheckboxLabel.className = 'slow-speed-option hidden';
  2558.    this.slowSpeedCheckboxLabel.textContent =
  2559.        getA11yString(A11Y_STRINGS.speedLabel);
  2560.  
  2561.    this.slowSpeedCheckbox = document.createElement('input');
  2562.    this.slowSpeedCheckbox.setAttribute('type', 'checkbox');
  2563.    this.slowSpeedCheckbox.setAttribute(
  2564.        'title', getA11yString(A11Y_STRINGS.speedLabel));
  2565.    this.slowSpeedCheckbox.setAttribute('tabindex', '0');
  2566.    this.slowSpeedCheckbox.setAttribute('checked', 'checked');
  2567.  
  2568.    this.slowSpeedToggleEl = document.createElement('span');
  2569.    this.slowSpeedToggleEl.className = 'slow-speed-toggle';
  2570.  
  2571.    this.slowSpeedCheckboxLabel.appendChild(this.slowSpeedCheckbox);
  2572.    this.slowSpeedCheckboxLabel.appendChild(this.slowSpeedToggleEl);
  2573.  
  2574.    if (IS_IOS) {
  2575.      this.outerContainerEl.appendChild(this.a11yStatusEl);
  2576.    } else {
  2577.      this.containerEl.appendChild(this.a11yStatusEl);
  2578.    }
  2579.  
  2580.    announcePhrase(getA11yString(A11Y_STRINGS.description));
  2581.  
  2582.    this.generatedSoundFx = new GeneratedSoundFx();
  2583.  
  2584.    this.canvasCtx =
  2585.        /** @type {CanvasRenderingContext2D} */ (this.canvas.getContext('2d'));
  2586.    this.canvasCtx.fillStyle = '#f7f7f7';
  2587.    this.canvasCtx.fill();
  2588.    Runner.updateCanvasScaling(this.canvas);
  2589.  
  2590.    // Horizon contains clouds, obstacles and the ground.
  2591.    this.horizon = new Horizon(this.canvas, this.spriteDef, this.dimensions,
  2592.        this.config.GAP_COEFFICIENT);
  2593.  
  2594.    // Distance meter
  2595.    this.distanceMeter = new DistanceMeter(this.canvas,
  2596.          this.spriteDef.TEXT_SPRITE, this.dimensions.WIDTH);
  2597.  
  2598.    // Draw t-rex
  2599.    this.tRex = new Trex(this.canvas, this.spriteDef.TREX);
  2600.  
  2601.    this.outerContainerEl.appendChild(this.containerEl);
  2602.    this.outerContainerEl.appendChild(this.slowSpeedCheckboxLabel);
  2603.  
  2604.    this.startListening();
  2605.    this.update();
  2606.  
  2607.    window.addEventListener(Runner.events.RESIZE,
  2608.        this.debounceResize.bind(this));
  2609.  
  2610.    // Handle dark mode
  2611.    const darkModeMediaQuery =
  2612.        window.matchMedia('(prefers-color-scheme: dark)');
  2613.    this.isDarkMode = darkModeMediaQuery && darkModeMediaQuery.matches;
  2614.    darkModeMediaQuery.addListener((e) => {
  2615.      this.isDarkMode = e.matches;
  2616.    });
  2617.  },
  2618.  
  2619.  /**
  2620.   * Create the touch controller. A div that covers whole screen.
  2621.   */
  2622.  createTouchController() {
  2623.    this.touchController = document.createElement('div');
  2624.    this.touchController.className = Runner.classes.TOUCH_CONTROLLER;
  2625.    this.touchController.addEventListener(Runner.events.TOUCHSTART, this);
  2626.    this.touchController.addEventListener(Runner.events.TOUCHEND, this);
  2627.    this.outerContainerEl.appendChild(this.touchController);
  2628.  },
  2629.  
  2630.  /**
  2631.   * Debounce the resize event.
  2632.   */
  2633.  debounceResize() {
  2634.    if (!this.resizeTimerId_) {
  2635.      this.resizeTimerId_ =
  2636.          setInterval(this.adjustDimensions.bind(this), 250);
  2637.    }
  2638.  },
  2639.  
  2640.  /**
  2641.   * Adjust game space dimensions on resize.
  2642.   */
  2643.  adjustDimensions() {
  2644.    clearInterval(this.resizeTimerId_);
  2645.    this.resizeTimerId_ = null;
  2646.  
  2647.    const boxStyles = window.getComputedStyle(this.outerContainerEl);
  2648.    const padding = Number(boxStyles.paddingLeft.substr(0,
  2649.        boxStyles.paddingLeft.length - 2));
  2650.  
  2651.    this.dimensions.WIDTH = this.outerContainerEl.offsetWidth - padding * 2;
  2652.    if (this.isArcadeMode()) {
  2653.      this.dimensions.WIDTH = Math.min(DEFAULT_WIDTH, this.dimensions.WIDTH);
  2654.      if (this.activated) {
  2655.        this.setArcadeModeContainerScale();
  2656.      }
  2657.    }
  2658.  
  2659.    // Redraw the elements back onto the canvas.
  2660.    if (this.canvas) {
  2661.      this.canvas.width = this.dimensions.WIDTH;
  2662.      this.canvas.height = this.dimensions.HEIGHT;
  2663.  
  2664.      Runner.updateCanvasScaling(this.canvas);
  2665.  
  2666.      this.distanceMeter.calcXPos(this.dimensions.WIDTH);
  2667.      this.clearCanvas();
  2668.      this.horizon.update(0, 0, true);
  2669.      this.tRex.update(0);
  2670.  
  2671.      // Outer container and distance meter.
  2672.      if (this.playing || this.crashed || this.paused) {
  2673.        this.containerEl.style.width = this.dimensions.WIDTH + 'px';
  2674.        this.containerEl.style.height = this.dimensions.HEIGHT + 'px';
  2675.        this.distanceMeter.update(0, Math.ceil(this.distanceRan));
  2676.        this.stop();
  2677.      } else {
  2678.        this.tRex.draw(0, 0);
  2679.      }
  2680.  
  2681.      // Game over panel.
  2682.      if (this.crashed && this.gameOverPanel) {
  2683.        this.gameOverPanel.updateDimensions(this.dimensions.WIDTH);
  2684.        this.gameOverPanel.draw(this.altGameModeActive, this.tRex);
  2685.      }
  2686.    }
  2687.  },
  2688.  
  2689.  /**
  2690.   * Play the game intro.
  2691.   * Canvas container width expands out to the full width.
  2692.   */
  2693.  playIntro() {
  2694.    if (!this.activated && !this.crashed) {
  2695.      this.playingIntro = true;
  2696.      this.tRex.playingIntro = true;
  2697.  
  2698.      // CSS animation definition.
  2699.      const keyframes = '@-webkit-keyframes intro { ' +
  2700.            'from { width:' + Trex.config.WIDTH + 'px }' +
  2701.            'to { width: ' + this.dimensions.WIDTH + 'px }' +
  2702.          '}';
  2703.      document.styleSheets[0].insertRule(keyframes, 0);
  2704.  
  2705.      this.containerEl.addEventListener(Runner.events.ANIM_END,
  2706.          this.startGame.bind(this));
  2707.  
  2708.      this.containerEl.style.webkitAnimation = 'intro .4s ease-out 1 both';
  2709.      this.containerEl.style.width = this.dimensions.WIDTH + 'px';
  2710.  
  2711.      this.setPlayStatus(true);
  2712.      this.activated = true;
  2713.    } else if (this.crashed) {
  2714.      this.restart();
  2715.    }
  2716.  },
  2717.  
  2718.  
  2719.  /**
  2720.   * Update the game status to started.
  2721.   */
  2722.  startGame() {
  2723.    if (this.isArcadeMode()) {
  2724.      this.setArcadeMode();
  2725.    }
  2726.    this.toggleSpeed();
  2727.    this.runningTime = 0;
  2728.    this.playingIntro = false;
  2729.    this.tRex.playingIntro = false;
  2730.    this.containerEl.style.webkitAnimation = '';
  2731.    this.playCount++;
  2732.    this.generatedSoundFx.background();
  2733.    announcePhrase(getA11yString(A11Y_STRINGS.started));
  2734.  
  2735.    if (Runner.audioCues) {
  2736.      this.containerEl.setAttribute('title', getA11yString(A11Y_STRINGS.jump));
  2737.    }
  2738.  
  2739.    // Handle tabbing off the page. Pause the current game.
  2740.    document.addEventListener(Runner.events.VISIBILITY,
  2741.          this.onVisibilityChange.bind(this));
  2742.  
  2743.    window.addEventListener(Runner.events.BLUR,
  2744.          this.onVisibilityChange.bind(this));
  2745.  
  2746.    window.addEventListener(Runner.events.FOCUS,
  2747.          this.onVisibilityChange.bind(this));
  2748.  },
  2749.  
  2750.  clearCanvas() {
  2751.    this.canvasCtx.clearRect(0, 0, this.dimensions.WIDTH,
  2752.        this.dimensions.HEIGHT);
  2753.  },
  2754.  
  2755.  /**
  2756.   * Checks whether the canvas area is in the viewport of the browser
  2757.   * through the current scroll position.
  2758.   * @return boolean.
  2759.   */
  2760.  isCanvasInView() {
  2761.    return this.containerEl.getBoundingClientRect().top >
  2762.        Runner.config.CANVAS_IN_VIEW_OFFSET;
  2763.  },
  2764.  
  2765.  /**
  2766.   * Enable the alt game mode. Switching out the sprites.
  2767.   */
  2768.  enableAltGameMode() {
  2769.    Runner.imageSprite = Runner.altGameImageSprite;
  2770.    Runner.spriteDefinition = Runner.spriteDefinitionByType[Runner.gameType];
  2771.  
  2772.    if (IS_HIDPI) {
  2773.      this.spriteDef = Runner.spriteDefinition.HDPI;
  2774.    } else {
  2775.      this.spriteDef = Runner.spriteDefinition.LDPI;
  2776.    }
  2777.  
  2778.    this.altGameModeActive = true;
  2779.    this.tRex.enableAltGameMode(this.spriteDef.TREX);
  2780.    this.horizon.enableAltGameMode(this.spriteDef);
  2781.    this.generatedSoundFx.background();
  2782.  },
  2783.  
  2784.  /**
  2785.   * Update the game frame and schedules the next one.
  2786.   */
  2787.  update() {
  2788.    this.updatePending = false;
  2789.  
  2790.    const now = getTimeStamp();
  2791.    let deltaTime = now - (this.time || now);
  2792.  
  2793.    // Flashing when switching game modes.
  2794.    if (this.altGameModeFlashTimer < 0 || this.altGameModeFlashTimer === 0) {
  2795.      this.altGameModeFlashTimer = null;
  2796.      this.tRex.setFlashing(false);
  2797.      this.enableAltGameMode();
  2798.    } else if (this.altGameModeFlashTimer > 0) {
  2799.      this.altGameModeFlashTimer -= deltaTime;
  2800.      this.tRex.update(deltaTime);
  2801.      deltaTime = 0;
  2802.    }
  2803.  
  2804.    this.time = now;
  2805.  
  2806.    if (this.playing) {
  2807.      this.clearCanvas();
  2808.  
  2809.      // Additional fade in - Prevents jump when switching sprites
  2810.      if (this.altGameModeActive &&
  2811.          this.fadeInTimer <= this.config.FADE_DURATION) {
  2812.        this.fadeInTimer += deltaTime / 1000;
  2813.        this.canvasCtx.globalAlpha = this.fadeInTimer;
  2814.      } else {
  2815.        this.canvasCtx.globalAlpha = 1;
  2816.      }
  2817.  
  2818.      if (this.tRex.jumping) {
  2819.        this.tRex.updateJump(deltaTime);
  2820.      }
  2821.  
  2822.      this.runningTime += deltaTime;
  2823.      const hasObstacles = this.runningTime > this.config.CLEAR_TIME;
  2824.  
  2825.      // First jump triggers the intro.
  2826.      if (this.tRex.jumpCount === 1 && !this.playingIntro) {
  2827.        this.playIntro();
  2828.      }
  2829.  
  2830.      // The horizon doesn't move until the intro is over.
  2831.      if (this.playingIntro) {
  2832.        this.horizon.update(0, this.currentSpeed, hasObstacles);
  2833.      } else if (!this.crashed) {
  2834.        const showNightMode = this.isDarkMode ^ this.inverted;
  2835.        deltaTime = !this.activated ? 0 : deltaTime;
  2836.        this.horizon.update(
  2837.            deltaTime, this.currentSpeed, hasObstacles, showNightMode);
  2838.      }
  2839.  
  2840.      // Check for collisions.
  2841.      let collision = hasObstacles &&
  2842.          checkForCollision(this.horizon.obstacles[0], this.tRex);
  2843.  
  2844.      // For a11y, audio cues.
  2845.      if (Runner.audioCues && hasObstacles) {
  2846.        const jumpObstacle =
  2847.            this.horizon.obstacles[0].typeConfig.type != 'COLLECTABLE';
  2848.  
  2849.        if (!this.horizon.obstacles[0].jumpAlerted) {
  2850.          const threshold = Runner.isMobileMouseInput ?
  2851.              Runner.config.AUDIOCUE_PROXIMITY_THRESHOLD_MOBILE_A11Y :
  2852.              Runner.config.AUDIOCUE_PROXIMITY_THRESHOLD;
  2853.          const adjProximityThreshold = threshold +
  2854.              (threshold * Math.log10(this.currentSpeed / Runner.config.SPEED));
  2855.  
  2856.          if (this.horizon.obstacles[0].xPos < adjProximityThreshold) {
  2857.            if (jumpObstacle) {
  2858.              this.generatedSoundFx.jump();
  2859.            }
  2860.            this.horizon.obstacles[0].jumpAlerted = true;
  2861.          }
  2862.        }
  2863.      }
  2864.  
  2865.      // Activated alt game mode.
  2866.      if (Runner.isAltGameModeEnabled() && collision &&
  2867.          this.horizon.obstacles[0].typeConfig.type == 'COLLECTABLE') {
  2868.        this.horizon.removeFirstObstacle();
  2869.        this.tRex.setFlashing(true);
  2870.        collision = false;
  2871.        this.altGameModeFlashTimer = this.config.FLASH_DURATION;
  2872.        this.runningTime = 0;
  2873.        this.generatedSoundFx.collect();
  2874.      }
  2875.  
  2876.      if (!collision) {
  2877.        this.distanceRan += this.currentSpeed * deltaTime / this.msPerFrame;
  2878.  
  2879.        if (this.currentSpeed < this.config.MAX_SPEED) {
  2880.          this.currentSpeed += this.config.ACCELERATION;
  2881.        }
  2882.      } else {
  2883.        this.gameOver();
  2884.      }
  2885.  
  2886.      const playAchievementSound = this.distanceMeter.update(deltaTime,
  2887.          Math.ceil(this.distanceRan));
  2888.  
  2889.      if (!Runner.audioCues && playAchievementSound) {
  2890.        this.playSound(this.soundFx.SCORE);
  2891.      }
  2892.  
  2893.      // Night mode.
  2894.      if (!Runner.isAltGameModeEnabled()) {
  2895.        if (this.invertTimer > this.config.INVERT_FADE_DURATION) {
  2896.          this.invertTimer = 0;
  2897.          this.invertTrigger = false;
  2898.          this.invert(false);
  2899.        } else if (this.invertTimer) {
  2900.          this.invertTimer += deltaTime;
  2901.        } else {
  2902.          const actualDistance =
  2903.              this.distanceMeter.getActualDistance(Math.ceil(this.distanceRan));
  2904.  
  2905.          if (actualDistance > 0) {
  2906.            this.invertTrigger =
  2907.                !(actualDistance % this.config.INVERT_DISTANCE);
  2908.  
  2909.            if (this.invertTrigger && this.invertTimer === 0) {
  2910.              this.invertTimer += deltaTime;
  2911.              this.invert(false);
  2912.            }
  2913.          }
  2914.        }
  2915.      }
  2916.    }
  2917.  
  2918.    if (this.playing || (!this.activated &&
  2919.        this.tRex.blinkCount < Runner.config.MAX_BLINK_COUNT)) {
  2920.      this.tRex.update(deltaTime);
  2921.      this.scheduleNextUpdate();
  2922.    }
  2923.  },
  2924.  
  2925.  /**
  2926.   * Event handler.
  2927.   * @param {Event} e
  2928.   */
  2929.  handleEvent(e) {
  2930.    return (function(evtType, events) {
  2931.      switch (evtType) {
  2932.        case events.KEYDOWN:
  2933.        case events.TOUCHSTART:
  2934.        case events.POINTERDOWN:
  2935.          this.onKeyDown(e);
  2936.          break;
  2937.        case events.KEYUP:
  2938.        case events.TOUCHEND:
  2939.        case events.POINTERUP:
  2940.          this.onKeyUp(e);
  2941.          break;
  2942.        case events.GAMEPADCONNECTED:
  2943.          this.onGamepadConnected(e);
  2944.          break;
  2945.      }
  2946.    }.bind(this))(e.type, Runner.events);
  2947.  },
  2948.  
  2949.  /**
  2950.   * Initialize audio cues if activated by focus on the canvas element.
  2951.   * @param {Event} e
  2952.   */
  2953.  handleCanvasKeyPress(e) {
  2954.    if (!this.activated && !Runner.audioCues) {
  2955.      this.toggleSpeed();
  2956.      Runner.audioCues = true;
  2957.      this.generatedSoundFx.init();
  2958.      Runner.generatedSoundFx = this.generatedSoundFx;
  2959.      Runner.config.CLEAR_TIME *= 1.2;
  2960.    } else if (e.keyCode && Runner.keycodes.JUMP[e.keyCode]) {
  2961.      this.onKeyDown(e);
  2962.    }
  2963.  },
  2964.  
  2965.  /**
  2966.   * Prevent space key press from scrolling.
  2967.   * @param {Event} e
  2968.   */
  2969.  preventScrolling(e) {
  2970.    if (e.keyCode === 32) {
  2971.      e.preventDefault();
  2972.    }
  2973.  },
  2974.  
  2975.  /**
  2976.   * Toggle speed setting if toggle is shown.
  2977.   */
  2978.  toggleSpeed() {
  2979.    if (Runner.audioCues) {
  2980.      const speedChange = Runner.slowDown != this.slowSpeedCheckbox.checked;
  2981.  
  2982.      if (speedChange) {
  2983.        Runner.slowDown = this.slowSpeedCheckbox.checked;
  2984.        const updatedConfig =
  2985.            Runner.slowDown ? Runner.slowConfig : Runner.normalConfig;
  2986.  
  2987.        Runner.config = Object.assign(Runner.config, updatedConfig);
  2988.        this.currentSpeed = updatedConfig.SPEED;
  2989.        this.tRex.enableSlowConfig();
  2990.        this.horizon.adjustObstacleSpeed();
  2991.      }
  2992.      if (this.playing) {
  2993.        this.disableSpeedToggle(true);
  2994.      }
  2995.    }
  2996.  },
  2997.  
  2998.  /**
  2999.   * Show the speed toggle.
  3000.   * From focus event or when audio cues are activated.
  3001.   * @param {Event=} e
  3002.   */
  3003.  showSpeedToggle(e) {
  3004.    const isFocusEvent = e && e.type == 'focus';
  3005.    if (Runner.audioCues || isFocusEvent) {
  3006.      this.slowSpeedCheckboxLabel.classList.toggle(
  3007.          HIDDEN_CLASS, isFocusEvent ? false : !this.crashed);
  3008.    }
  3009.  },
  3010.  
  3011.  /**
  3012.   * Disable the speed toggle.
  3013.   * @param {boolean} disable
  3014.   */
  3015.  disableSpeedToggle(disable) {
  3016.    if (disable) {
  3017.      this.slowSpeedCheckbox.setAttribute('disabled', 'disabled');
  3018.    } else {
  3019.      this.slowSpeedCheckbox.removeAttribute('disabled');
  3020.    }
  3021.  },
  3022.  
  3023.  /**
  3024.   * Bind relevant key / mouse / touch listeners.
  3025.   */
  3026.  startListening() {
  3027.    // A11y keyboard / screen reader activation.
  3028.    this.containerEl.addEventListener(
  3029.        Runner.events.KEYDOWN, this.handleCanvasKeyPress.bind(this));
  3030.    if (!IS_MOBILE) {
  3031.      this.containerEl.addEventListener(
  3032.          Runner.events.FOCUS, this.showSpeedToggle.bind(this));
  3033.    }
  3034.    this.canvas.addEventListener(
  3035.        Runner.events.KEYDOWN, this.preventScrolling.bind(this));
  3036.    this.canvas.addEventListener(
  3037.        Runner.events.KEYUP, this.preventScrolling.bind(this));
  3038.  
  3039.    // Keys.
  3040.    document.addEventListener(Runner.events.KEYDOWN, this);
  3041.    document.addEventListener(Runner.events.KEYUP, this);
  3042.  
  3043.    // Touch / pointer.
  3044.    this.containerEl.addEventListener(Runner.events.TOUCHSTART, this);
  3045.    document.addEventListener(Runner.events.POINTERDOWN, this);
  3046.    document.addEventListener(Runner.events.POINTERUP, this);
  3047.  
  3048.    if (this.isArcadeMode()) {
  3049.      // Gamepad
  3050.      window.addEventListener(Runner.events.GAMEPADCONNECTED, this);
  3051.    }
  3052.  },
  3053.  
  3054.  /**
  3055.   * Remove all listeners.
  3056.   */
  3057.  stopListening() {
  3058.    document.removeEventListener(Runner.events.KEYDOWN, this);
  3059.    document.removeEventListener(Runner.events.KEYUP, this);
  3060.  
  3061.    if (this.touchController) {
  3062.      this.touchController.removeEventListener(Runner.events.TOUCHSTART, this);
  3063.      this.touchController.removeEventListener(Runner.events.TOUCHEND, this);
  3064.    }
  3065.  
  3066.    this.containerEl.removeEventListener(Runner.events.TOUCHSTART, this);
  3067.    document.removeEventListener(Runner.events.POINTERDOWN, this);
  3068.    document.removeEventListener(Runner.events.POINTERUP, this);
  3069.  
  3070.    if (this.isArcadeMode()) {
  3071.      window.removeEventListener(Runner.events.GAMEPADCONNECTED, this);
  3072.    }
  3073.  },
  3074.  
  3075.  /**
  3076.   * Process keydown.
  3077.   * @param {Event} e
  3078.   */
  3079.  onKeyDown(e) {
  3080.    // Prevent native page scrolling whilst tapping on mobile.
  3081.    if (IS_MOBILE && this.playing) {
  3082.      e.preventDefault();
  3083.    }
  3084.  
  3085.    if (this.isCanvasInView()) {
  3086.      // Allow toggling of speed toggle.
  3087.      if (Runner.keycodes.JUMP[e.keyCode] &&
  3088.          e.target == this.slowSpeedCheckbox) {
  3089.        return;
  3090.      }
  3091.  
  3092.      if (!this.crashed && !this.paused) {
  3093.        // For a11y, screen reader activation.
  3094.        const isMobileMouseInput = IS_MOBILE &&
  3095.                e.type === Runner.events.POINTERDOWN &&
  3096.                e.pointerType == 'mouse' && e.target == this.containerEl ||
  3097.            (IS_IOS && e.pointerType == 'touch' &&
  3098.             document.activeElement == this.containerEl);
  3099.  
  3100.        if (Runner.keycodes.JUMP[e.keyCode] ||
  3101.            e.type === Runner.events.TOUCHSTART || isMobileMouseInput ||
  3102.            (Runner.keycodes.DUCK[e.keyCode] && this.altGameModeActive)) {
  3103.          e.preventDefault();
  3104.          // Starting the game for the first time.
  3105.          if (!this.playing) {
  3106.            // Started by touch so create a touch controller.
  3107.            if (!this.touchController && e.type === Runner.events.TOUCHSTART) {
  3108.              this.createTouchController();
  3109.            }
  3110.  
  3111.            if (isMobileMouseInput) {
  3112.              this.handleCanvasKeyPress(e);
  3113.            }
  3114.            this.loadSounds();
  3115.            this.setPlayStatus(true);
  3116.            this.update();
  3117.            if (window.errorPageController) {
  3118.              errorPageController.trackEasterEgg();
  3119.            }
  3120.          }
  3121.          // Start jump.
  3122.          if (!this.tRex.jumping && !this.tRex.ducking) {
  3123.            if (Runner.audioCues) {
  3124.              this.generatedSoundFx.cancelFootSteps();
  3125.            } else {
  3126.              this.playSound(this.soundFx.BUTTON_PRESS);
  3127.            }
  3128.            this.tRex.startJump(this.currentSpeed);
  3129.          }
  3130.          // Ducking is disabled on alt game modes.
  3131.        } else if (
  3132.            !this.altGameModeActive && this.playing &&
  3133.            Runner.keycodes.DUCK[e.keyCode]) {
  3134.          e.preventDefault();
  3135.          if (this.tRex.jumping) {
  3136.            // Speed drop, activated only when jump key is not pressed.
  3137.            this.tRex.setSpeedDrop();
  3138.          } else if (!this.tRex.jumping && !this.tRex.ducking) {
  3139.            // Duck.
  3140.            this.tRex.setDuck(true);
  3141.          }
  3142.        }
  3143.      }
  3144.    }
  3145.  },
  3146.  
  3147.  /**
  3148.   * Process key up.
  3149.   * @param {Event} e
  3150.   */
  3151.  onKeyUp(e) {
  3152.    const keyCode = String(e.keyCode);
  3153.    const isjumpKey = Runner.keycodes.JUMP[keyCode] ||
  3154.        e.type === Runner.events.TOUCHEND || e.type === Runner.events.POINTERUP;
  3155.  
  3156.    if (this.isRunning() && isjumpKey) {
  3157.      this.tRex.endJump();
  3158.    } else if (Runner.keycodes.DUCK[keyCode]) {
  3159.      this.tRex.speedDrop = false;
  3160.      this.tRex.setDuck(false);
  3161.    } else if (this.crashed) {
  3162.      // Check that enough time has elapsed before allowing jump key to restart.
  3163.      const deltaTime = getTimeStamp() - this.time;
  3164.  
  3165.      if (this.isCanvasInView() &&
  3166.          (Runner.keycodes.RESTART[keyCode] || this.isLeftClickOnCanvas(e) ||
  3167.          (deltaTime >= this.config.GAMEOVER_CLEAR_TIME &&
  3168.          Runner.keycodes.JUMP[keyCode]))) {
  3169.        this.handleGameOverClicks(e);
  3170.      }
  3171.    } else if (this.paused && isjumpKey) {
  3172.      // Reset the jump state
  3173.      this.tRex.reset();
  3174.      this.play();
  3175.    }
  3176.  },
  3177.  
  3178.  /**
  3179.   * Process gamepad connected event.
  3180.   * @param {Event} e
  3181.   */
  3182.  onGamepadConnected(e) {
  3183.    if (!this.pollingGamepads) {
  3184.      this.pollGamepadState();
  3185.    }
  3186.  },
  3187.  
  3188.  /**
  3189.   * rAF loop for gamepad polling.
  3190.   */
  3191.  pollGamepadState() {
  3192.    const gamepads = navigator.getGamepads();
  3193.    this.pollActiveGamepad(gamepads);
  3194.  
  3195.    this.pollingGamepads = true;
  3196.    requestAnimationFrame(this.pollGamepadState.bind(this));
  3197.  },
  3198.  
  3199.  /**
  3200.   * Polls for a gamepad with the jump button pressed. If one is found this
  3201.   * becomes the "active" gamepad and all others are ignored.
  3202.   * @param {!Array<Gamepad>} gamepads
  3203.   */
  3204.  pollForActiveGamepad(gamepads) {
  3205.    for (let i = 0; i < gamepads.length; ++i) {
  3206.      if (gamepads[i] && gamepads[i].buttons.length > 0 &&
  3207.          gamepads[i].buttons[0].pressed) {
  3208.        this.gamepadIndex = i;
  3209.        this.pollActiveGamepad(gamepads);
  3210.        return;
  3211.      }
  3212.    }
  3213.  },
  3214.  
  3215.  /**
  3216.   * Polls the chosen gamepad for button presses and generates KeyboardEvents
  3217.   * to integrate with the rest of the game logic.
  3218.   * @param {!Array<Gamepad>} gamepads
  3219.   */
  3220.  pollActiveGamepad(gamepads) {
  3221.    if (this.gamepadIndex === undefined) {
  3222.      this.pollForActiveGamepad(gamepads);
  3223.      return;
  3224.    }
  3225.  
  3226.    const gamepad = gamepads[this.gamepadIndex];
  3227.    if (!gamepad) {
  3228.      this.gamepadIndex = undefined;
  3229.      this.pollForActiveGamepad(gamepads);
  3230.      return;
  3231.    }
  3232.  
  3233.    // The gamepad specification defines the typical mapping of physical buttons
  3234.    // to button indicies: https://w3c.github.io/gamepad/#remapping
  3235.    this.pollGamepadButton(gamepad, 0, 38);  // Jump
  3236.    if (gamepad.buttons.length >= 2) {
  3237.      this.pollGamepadButton(gamepad, 1, 40);  // Duck
  3238.    }
  3239.    if (gamepad.buttons.length >= 10) {
  3240.      this.pollGamepadButton(gamepad, 9, 13);  // Restart
  3241.    }
  3242.  
  3243.    this.previousGamepad = gamepad;
  3244.  },
  3245.  
  3246.  /**
  3247.   * Generates a key event based on a gamepad button.
  3248.   * @param {!Gamepad} gamepad
  3249.   * @param {number} buttonIndex
  3250.   * @param {number} keyCode
  3251.   */
  3252.  pollGamepadButton(gamepad, buttonIndex, keyCode) {
  3253.    const state = gamepad.buttons[buttonIndex].pressed;
  3254.    let previousState = false;
  3255.    if (this.previousGamepad) {
  3256.      previousState = this.previousGamepad.buttons[buttonIndex].pressed;
  3257.    }
  3258.    // Generate key events on the rising and falling edge of a button press.
  3259.    if (state !== previousState) {
  3260.      const e = new KeyboardEvent(state ? Runner.events.KEYDOWN
  3261.                                      : Runner.events.KEYUP,
  3262.                                { keyCode: keyCode });
  3263.      document.dispatchEvent(e);
  3264.    }
  3265.  },
  3266.  
  3267.  /**
  3268.   * Handle interactions on the game over screen state.
  3269.   * A user is able to tap the high score twice to reset it.
  3270.   * @param {Event} e
  3271.   */
  3272.  handleGameOverClicks(e) {
  3273.    if (e.target != this.slowSpeedCheckbox) {
  3274.      e.preventDefault();
  3275.      if (this.distanceMeter.hasClickedOnHighScore(e) && this.highestScore) {
  3276.        if (this.distanceMeter.isHighScoreFlashing()) {
  3277.          // Subsequent click, reset the high score.
  3278.          this.saveHighScore(0, true);
  3279.          this.distanceMeter.resetHighScore();
  3280.        } else {
  3281.          // First click, flash the high score.
  3282.          this.distanceMeter.startHighScoreFlashing();
  3283.        }
  3284.      } else {
  3285.        this.distanceMeter.cancelHighScoreFlashing();
  3286.        this.restart();
  3287.      }
  3288.    }
  3289.  },
  3290.  
  3291.  /**
  3292.   * Returns whether the event was a left click on canvas.
  3293.   * On Windows right click is registered as a click.
  3294.   * @param {Event} e
  3295.   * @return {boolean}
  3296.   */
  3297.  isLeftClickOnCanvas(e) {
  3298.    return e.button != null && e.button < 2 &&
  3299.        e.type === Runner.events.POINTERUP &&
  3300.        (e.target === this.canvas ||
  3301.         (IS_MOBILE && Runner.audioCues && e.target === this.containerEl));
  3302.  },
  3303.  
  3304.  /**
  3305.   * RequestAnimationFrame wrapper.
  3306.   */
  3307.  scheduleNextUpdate() {
  3308.    if (!this.updatePending) {
  3309.      this.updatePending = true;
  3310.      this.raqId = requestAnimationFrame(this.update.bind(this));
  3311.    }
  3312.  },
  3313.  
  3314.  /**
  3315.   * Whether the game is running.
  3316.   * @return {boolean}
  3317.   */
  3318.  isRunning() {
  3319.    return !!this.raqId;
  3320.  },
  3321.  
  3322.  /**
  3323.   * Set the initial high score as stored in the user's profile.
  3324.   * @param {number} highScore
  3325.   */
  3326.  initializeHighScore(highScore) {
  3327.    this.syncHighestScore = true;
  3328.    highScore = Math.ceil(highScore);
  3329.    if (highScore < this.highestScore) {
  3330.      if (window.errorPageController) {
  3331.        errorPageController.updateEasterEggHighScore(this.highestScore);
  3332.      }
  3333.      return;
  3334.    }
  3335.    this.highestScore = highScore;
  3336.    this.distanceMeter.setHighScore(this.highestScore);
  3337.  },
  3338.  
  3339.  /**
  3340.   * Sets the current high score and saves to the profile if available.
  3341.   * @param {number} distanceRan Total distance ran.
  3342.   * @param {boolean=} opt_resetScore Whether to reset the score.
  3343.   */
  3344.  saveHighScore(distanceRan, opt_resetScore) {
  3345.    this.highestScore = Math.ceil(distanceRan);
  3346.    this.distanceMeter.setHighScore(this.highestScore);
  3347.  
  3348.    // Store the new high score in the profile.
  3349.    if (this.syncHighestScore && window.errorPageController) {
  3350.      if (opt_resetScore) {
  3351.        errorPageController.resetEasterEggHighScore();
  3352.      } else {
  3353.        errorPageController.updateEasterEggHighScore(this.highestScore);
  3354.      }
  3355.    }
  3356.  },
  3357.  
  3358.  /**
  3359.   * Game over state.
  3360.   */
  3361.  gameOver() {
  3362.    this.playSound(this.soundFx.HIT);
  3363.    vibrate(200);
  3364.  
  3365.    this.stop();
  3366.    this.crashed = true;
  3367.    this.distanceMeter.achievement = false;
  3368.  
  3369.    this.tRex.update(100, Trex.status.CRASHED);
  3370.  
  3371.    // Game over panel.
  3372.    if (!this.gameOverPanel) {
  3373.      const origSpriteDef = IS_HIDPI ?
  3374.          Runner.spriteDefinitionByType.original.HDPI :
  3375.          Runner.spriteDefinitionByType.original.LDPI;
  3376.  
  3377.      if (this.canvas) {
  3378.        if (Runner.isAltGameModeEnabled) {
  3379.          this.gameOverPanel = new GameOverPanel(
  3380.              this.canvas, origSpriteDef.TEXT_SPRITE, origSpriteDef.RESTART,
  3381.              this.dimensions, origSpriteDef.ALT_GAME_END,
  3382.              this.altGameModeActive);
  3383.        } else {
  3384.          this.gameOverPanel = new GameOverPanel(
  3385.              this.canvas, origSpriteDef.TEXT_SPRITE, origSpriteDef.RESTART,
  3386.              this.dimensions);
  3387.        }
  3388.      }
  3389.    }
  3390.  
  3391.    this.gameOverPanel.draw(this.altGameModeActive, this.tRex);
  3392.  
  3393.    // Update the high score.
  3394.    if (this.distanceRan > this.highestScore) {
  3395.      this.saveHighScore(this.distanceRan);
  3396.    }
  3397.  
  3398.    // Reset the time clock.
  3399.    this.time = getTimeStamp();
  3400.  
  3401.    if (Runner.audioCues) {
  3402.      this.generatedSoundFx.stopAll();
  3403.      announcePhrase(
  3404.          getA11yString(A11Y_STRINGS.gameOver)
  3405.              .replace(
  3406.                  '$1',
  3407.                  this.distanceMeter.getActualDistance(this.distanceRan)
  3408.                      .toString()) +
  3409.          ' ' +
  3410.          getA11yString(A11Y_STRINGS.highScore)
  3411.              .replace(
  3412.                  '$1',
  3413.  
  3414.                  this.distanceMeter.getActualDistance(this.highestScore)
  3415.                      .toString()));
  3416.      this.containerEl.setAttribute(
  3417.          'title', getA11yString(A11Y_STRINGS.ariaLabel));
  3418.    }
  3419.    this.showSpeedToggle();
  3420.    this.disableSpeedToggle(false);
  3421.  },
  3422.  
  3423.  stop() {
  3424.    this.setPlayStatus(false);
  3425.    this.paused = true;
  3426.    cancelAnimationFrame(this.raqId);
  3427.    this.raqId = 0;
  3428.    this.generatedSoundFx.stopAll();
  3429.  },
  3430.  
  3431.  play() {
  3432.    if (!this.crashed) {
  3433.      this.setPlayStatus(true);
  3434.      this.paused = false;
  3435.      this.tRex.update(0, Trex.status.RUNNING);
  3436.      this.time = getTimeStamp();
  3437.      this.update();
  3438.      this.generatedSoundFx.background();
  3439.    }
  3440.  },
  3441.  
  3442.  restart() {
  3443.    if (!this.raqId) {
  3444.      this.playCount++;
  3445.      this.runningTime = 0;
  3446.      this.setPlayStatus(true);
  3447.      this.toggleSpeed();
  3448.      this.paused = false;
  3449.      this.crashed = false;
  3450.      this.distanceRan = 0;
  3451.      this.setSpeed(this.config.SPEED);
  3452.      this.time = getTimeStamp();
  3453.      this.containerEl.classList.remove(Runner.classes.CRASHED);
  3454.      this.clearCanvas();
  3455.      this.distanceMeter.reset();
  3456.      this.horizon.reset();
  3457.      this.tRex.reset();
  3458.      this.playSound(this.soundFx.BUTTON_PRESS);
  3459.      this.invert(true);
  3460.      this.flashTimer = null;
  3461.      this.update();
  3462.      this.gameOverPanel.reset();
  3463.      this.generatedSoundFx.background();
  3464.      this.containerEl.setAttribute('title', getA11yString(A11Y_STRINGS.jump));
  3465.      announcePhrase(getA11yString(A11Y_STRINGS.started));
  3466.    }
  3467.  },
  3468.  
  3469.  setPlayStatus(isPlaying) {
  3470.    if (this.touchController) {
  3471.      this.touchController.classList.toggle(HIDDEN_CLASS, !isPlaying);
  3472.    }
  3473.    this.playing = isPlaying;
  3474.  },
  3475.  
  3476.  /**
  3477.   * Whether the game should go into arcade mode.
  3478.   * @return {boolean}
  3479.   */
  3480.  isArcadeMode() {
  3481.    // In RTL languages the title is wrapped with the left to right mark
  3482.    // control characters &#x202A; and &#x202C but are invisible.
  3483.    return IS_RTL ? document.title.indexOf(ARCADE_MODE_URL) == 1 :
  3484.                    document.title === ARCADE_MODE_URL;
  3485.  },
  3486.  
  3487.  /**
  3488.   * Hides offline messaging for a fullscreen game only experience.
  3489.   */
  3490.  setArcadeMode() {
  3491.    document.body.classList.add(Runner.classes.ARCADE_MODE);
  3492.    this.setArcadeModeContainerScale();
  3493.  },
  3494.  
  3495.  /**
  3496.   * Sets the scaling for arcade mode.
  3497.   */
  3498.  setArcadeModeContainerScale() {
  3499.    const windowHeight = window.innerHeight;
  3500.    const scaleHeight = windowHeight / this.dimensions.HEIGHT;
  3501.    const scaleWidth = window.innerWidth / this.dimensions.WIDTH;
  3502.    const scale = Math.max(1, Math.min(scaleHeight, scaleWidth));
  3503.    const scaledCanvasHeight = this.dimensions.HEIGHT * scale;
  3504.    // Positions the game container at 10% of the available vertical window
  3505.    // height minus the game container height.
  3506.    const translateY = Math.ceil(Math.max(0, (windowHeight - scaledCanvasHeight -
  3507.        Runner.config.ARCADE_MODE_INITIAL_TOP_POSITION) *
  3508.        Runner.config.ARCADE_MODE_TOP_POSITION_PERCENT)) *
  3509.        window.devicePixelRatio;
  3510.  
  3511.    const cssScale = IS_RTL ? -scale + ',' + scale : scale;
  3512.    this.containerEl.style.transform =
  3513.        'scale(' + cssScale + ') translateY(' + translateY + 'px)';
  3514.  },
  3515.  
  3516.  /**
  3517.   * Pause the game if the tab is not in focus.
  3518.   */
  3519.  onVisibilityChange(e) {
  3520.    if (document.hidden || document.webkitHidden || e.type === 'blur' ||
  3521.        document.visibilityState !== 'visible') {
  3522.      this.stop();
  3523.    } else if (!this.crashed) {
  3524.      this.tRex.reset();
  3525.      this.play();
  3526.    }
  3527.  },
  3528.  
  3529.  /**
  3530.   * Play a sound.
  3531.   * @param {AudioBuffer} soundBuffer
  3532.   */
  3533.  playSound(soundBuffer) {
  3534.    if (soundBuffer) {
  3535.      const sourceNode = this.audioContext.createBufferSource();
  3536.      sourceNode.buffer = soundBuffer;
  3537.      sourceNode.connect(this.audioContext.destination);
  3538.      sourceNode.start(0);
  3539.    }
  3540.  },
  3541.  
  3542.  /**
  3543.   * Inverts the current page / canvas colors.
  3544.   * @param {boolean} reset Whether to reset colors.
  3545.   */
  3546.  invert(reset) {
  3547.    const htmlEl = document.firstElementChild;
  3548.  
  3549.    if (reset) {
  3550.      htmlEl.classList.toggle(Runner.classes.INVERTED,
  3551.          false);
  3552.      this.invertTimer = 0;
  3553.      this.inverted = false;
  3554.    } else {
  3555.      this.inverted = htmlEl.classList.toggle(
  3556.          Runner.classes.INVERTED, this.invertTrigger);
  3557.    }
  3558.  },
  3559. };
  3560.  
  3561.  
  3562. /**
  3563. * Updates the canvas size taking into
  3564. * account the backing store pixel ratio and
  3565. * the device pixel ratio.
  3566. *
  3567. * See article by Paul Lewis:
  3568. * http://www.html5rocks.com/en/tutorials/canvas/hidpi/
  3569. *
  3570. * @param {HTMLCanvasElement} canvas
  3571. * @param {number=} opt_width
  3572. * @param {number=} opt_height
  3573. * @return {boolean} Whether the canvas was scaled.
  3574. */
  3575. Runner.updateCanvasScaling = function(canvas, opt_width, opt_height) {
  3576.  const context =
  3577.      /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
  3578.  
  3579.  // Query the various pixel ratios
  3580.  const devicePixelRatio = Math.floor(window.devicePixelRatio) || 1;
  3581.  /** @suppress {missingProperties} */
  3582.  const backingStoreRatio =
  3583.      Math.floor(context.webkitBackingStorePixelRatio) || 1;
  3584.  const ratio = devicePixelRatio / backingStoreRatio;
  3585.  
  3586.  // Upscale the canvas if the two ratios don't match
  3587.  if (devicePixelRatio !== backingStoreRatio) {
  3588.    const oldWidth = opt_width || canvas.width;
  3589.    const oldHeight = opt_height || canvas.height;
  3590.  
  3591.    canvas.width = oldWidth * ratio;
  3592.    canvas.height = oldHeight * ratio;
  3593.  
  3594.    canvas.style.width = oldWidth + 'px';
  3595.    canvas.style.height = oldHeight + 'px';
  3596.  
  3597.    // Scale the context to counter the fact that we've manually scaled
  3598.    // our canvas element.
  3599.    context.scale(ratio, ratio);
  3600.    return true;
  3601.  } else if (devicePixelRatio === 1) {
  3602.    // Reset the canvas width / height. Fixes scaling bug when the page is
  3603.    // zoomed and the devicePixelRatio changes accordingly.
  3604.    canvas.style.width = canvas.width + 'px';
  3605.    canvas.style.height = canvas.height + 'px';
  3606.  }
  3607.  return false;
  3608. };
  3609.  
  3610.  
  3611. /**
  3612. * Whether events are enabled.
  3613. * @return {boolean}
  3614. */
  3615. Runner.isAltGameModeEnabled = function() {
  3616.  return loadTimeData && loadTimeData.valueExists('enableAltGameMode');
  3617. };
  3618.  
  3619.  
  3620. /**
  3621. * Generated sound FX class for audio cues.
  3622. * @constructor
  3623. */
  3624. function GeneratedSoundFx() {
  3625.  this.audioCues = false;
  3626.  this.context = null;
  3627.  this.panner = null;
  3628. }
  3629.  
  3630. GeneratedSoundFx.prototype = {
  3631.  init() {
  3632.    this.audioCues = true;
  3633.    if (!this.context) {
  3634.      // iOS only supports the webkit version.
  3635.      this.context = window.webkitAudioContext ? new webkitAudioContext() :
  3636.                                                 new AudioContext();
  3637.      if (IS_IOS) {
  3638.        this.context.onstatechange = (function() {
  3639.                                       if (this.context.state != 'running') {
  3640.                                         this.context.resume();
  3641.                                       }
  3642.                                     }).bind(this);
  3643.        this.context.resume();
  3644.      }
  3645.      this.panner = this.context.createStereoPanner ?
  3646.          this.context.createStereoPanner() :
  3647.          null;
  3648.    }
  3649.  },
  3650.  
  3651.  stopAll() {
  3652.    this.cancelFootSteps();
  3653.  },
  3654.  
  3655.  /**
  3656.   * Play oscillators at certain frequency and for a certain time.
  3657.   * @param {number} frequency
  3658.   * @param {number} startTime
  3659.   * @param {number} duration
  3660.   * @param {?number=} opt_vol
  3661.   * @param {number=} opt_pan
  3662.   */
  3663.  playNote(frequency, startTime, duration, opt_vol, opt_pan) {
  3664.    const osc1 = this.context.createOscillator();
  3665.    const osc2 = this.context.createOscillator();
  3666.    const volume = this.context.createGain();
  3667.  
  3668.    // Set oscillator wave type
  3669.    osc1.type = 'triangle';
  3670.    osc2.type = 'triangle';
  3671.    volume.gain.value = 0.1;
  3672.  
  3673.    // Set up node routing
  3674.    if (this.panner) {
  3675.      this.panner.pan.value = opt_pan || 0;
  3676.      osc1.connect(volume).connect(this.panner);
  3677.      osc2.connect(volume).connect(this.panner);
  3678.      this.panner.connect(this.context.destination);
  3679.    } else {
  3680.      osc1.connect(volume);
  3681.      osc2.connect(volume);
  3682.      volume.connect(this.context.destination);
  3683.    }
  3684.  
  3685.    // Detune oscillators for chorus effect
  3686.    osc1.frequency.value = frequency + 1;
  3687.    osc2.frequency.value = frequency - 2;
  3688.  
  3689.    // Fade out
  3690.    volume.gain.setValueAtTime(opt_vol || 0.01, startTime + duration - 0.05);
  3691.    volume.gain.linearRampToValueAtTime(0.00001, startTime + duration);
  3692.  
  3693.    // Start oscillators
  3694.    osc1.start(startTime);
  3695.    osc2.start(startTime);
  3696.    // Stop oscillators
  3697.    osc1.stop(startTime + duration);
  3698.    osc2.stop(startTime + duration);
  3699.  },
  3700.  
  3701.  background() {
  3702.    if (this.audioCues) {
  3703.      const now = this.context.currentTime;
  3704.      this.playNote(493.883, now, 0.116);
  3705.      this.playNote(659.255, now + 0.116, 0.232);
  3706.      this.loopFootSteps();
  3707.    }
  3708.  },
  3709.  
  3710.  loopFootSteps() {
  3711.    if (this.audioCues && !this.bgSoundIntervalId) {
  3712.      this.bgSoundIntervalId = setInterval(function() {
  3713.        this.playNote(73.42, this.context.currentTime, 0.05, 0.16);
  3714.        this.playNote(69.30, this.context.currentTime + 0.116, 0.116, 0.16);
  3715.      }.bind(this), 280);
  3716.    }
  3717.  },
  3718.  
  3719.  cancelFootSteps() {
  3720.    if (this.audioCues && this.bgSoundIntervalId) {
  3721.      clearInterval(this.bgSoundIntervalId);
  3722.      this.bgSoundIntervalId = null;
  3723.      this.playNote(103.83, this.context.currentTime, 0.232, 0.02);
  3724.      this.playNote(116.54, this.context.currentTime + 0.116, 0.232, 0.02);
  3725.    }
  3726.  },
  3727.  
  3728.  collect() {
  3729.    if (this.audioCues) {
  3730.      this.cancelFootSteps();
  3731.      const now = this.context.currentTime;
  3732.      this.playNote(830.61, now, 0.116);
  3733.      this.playNote(1318.51, now + 0.116, 0.232);
  3734.    }
  3735.  },
  3736.  
  3737.  jump() {
  3738.    if (this.audioCues) {
  3739.      const now = this.context.currentTime;
  3740.      this.playNote(659.25, now, 0.116, 0.3, -0.6);
  3741.      this.playNote(880, now + 0.116, 0.232, 0.3, -0.6);
  3742.    }
  3743.  },
  3744. };
  3745.  
  3746.  
  3747. /**
  3748. * Speak a phrase using Speech Synthesis API for a11y.
  3749. * @param {string} phrase Sentence to speak.
  3750. */
  3751. function speakPhrase(phrase) {
  3752.  if ('speechSynthesis' in window) {
  3753.    const msg = new SpeechSynthesisUtterance(phrase);
  3754.    const voices = window.speechSynthesis.getVoices();
  3755.    msg.text = phrase;
  3756.    speechSynthesis.speak(msg);
  3757.  }
  3758. }
  3759.  
  3760.  
  3761. /**
  3762. * For screen readers make an announcement to the live region.
  3763. * @param {string} phrase Sentence to speak.
  3764. */
  3765. function announcePhrase(phrase) {
  3766.  if (Runner.a11yStatusEl) {
  3767.    Runner.a11yStatusEl.textContent = '';
  3768.    Runner.a11yStatusEl.textContent = phrase;
  3769.  }
  3770. }
  3771.  
  3772.  
  3773. /**
  3774. * Returns a string from loadTimeData data object.
  3775. * @param {string} stringName
  3776. * @return {string}
  3777. */
  3778. function getA11yString(stringName) {
  3779.  return loadTimeData && loadTimeData.valueExists(stringName) ?
  3780.      loadTimeData.getString(stringName) :
  3781.      '';
  3782. }
  3783.  
  3784.  
  3785. /**
  3786. * Get random number.
  3787. * @param {number} min
  3788. * @param {number} max
  3789. */
  3790. function getRandomNum(min, max) {
  3791.  return Math.floor(Math.random() * (max - min + 1)) + min;
  3792. }
  3793.  
  3794.  
  3795. /**
  3796. * Vibrate on mobile devices.
  3797. * @param {number} duration Duration of the vibration in milliseconds.
  3798. */
  3799. function vibrate(duration) {
  3800.  if (IS_MOBILE && window.navigator.vibrate) {
  3801.    window.navigator.vibrate(duration);
  3802.  }
  3803. }
  3804.  
  3805.  
  3806. /**
  3807. * Create canvas element.
  3808. * @param {Element} container Element to append canvas to.
  3809. * @param {number} width
  3810. * @param {number} height
  3811. * @param {string=} opt_classname
  3812. * @return {HTMLCanvasElement}
  3813. */
  3814. function createCanvas(container, width, height, opt_classname) {
  3815.  const canvas =
  3816.      /** @type {!HTMLCanvasElement} */ (document.createElement('canvas'));
  3817.  canvas.className = opt_classname ? Runner.classes.CANVAS + ' ' +
  3818.      opt_classname : Runner.classes.CANVAS;
  3819.  canvas.width = width;
  3820.  canvas.height = height;
  3821.  container.appendChild(canvas);
  3822.  
  3823.  return canvas;
  3824. }
  3825.  
  3826.  
  3827. /**
  3828. * Decodes the base 64 audio to ArrayBuffer used by Web Audio.
  3829. * @param {string} base64String
  3830. */
  3831. function decodeBase64ToArrayBuffer(base64String) {
  3832.  const len = (base64String.length / 4) * 3;
  3833.  const str = atob(base64String);
  3834.  const arrayBuffer = new ArrayBuffer(len);
  3835.  const bytes = new Uint8Array(arrayBuffer);
  3836.  
  3837.  for (let i = 0; i < len; i++) {
  3838.    bytes[i] = str.charCodeAt(i);
  3839.  }
  3840.  return bytes.buffer;
  3841. }
  3842.  
  3843.  
  3844. /**
  3845. * Return the current timestamp.
  3846. * @return {number}
  3847. */
  3848. function getTimeStamp() {
  3849.  return IS_IOS ? new Date().getTime() : performance.now();
  3850. }
  3851.  
  3852.  
  3853. //******************************************************************************
  3854.  
  3855.  
  3856. /**
  3857. * Game over panel.
  3858. * @param {!HTMLCanvasElement} canvas
  3859. * @param {Object} textImgPos
  3860. * @param {Object} restartImgPos
  3861. * @param {!Object} dimensions Canvas dimensions.
  3862. * @param {Object=} opt_altGameEndImgPos
  3863. * @param {boolean=} opt_altGameActive
  3864. * @constructor
  3865. */
  3866. function GameOverPanel(
  3867.    canvas, textImgPos, restartImgPos, dimensions, opt_altGameEndImgPos,
  3868.    opt_altGameActive) {
  3869.  this.canvas = canvas;
  3870.  this.canvasCtx =
  3871.      /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
  3872.  this.canvasDimensions = dimensions;
  3873.  this.textImgPos = textImgPos;
  3874.  this.restartImgPos = restartImgPos;
  3875.  this.altGameEndImgPos = opt_altGameEndImgPos;
  3876.  this.altGameModeActive = opt_altGameActive;
  3877.  
  3878.  // Retry animation.
  3879.  this.frameTimeStamp = 0;
  3880.  this.animTimer = 0;
  3881.  this.currentFrame = 0;
  3882.  
  3883.  this.gameOverRafId = null;
  3884.  
  3885.  this.flashTimer = 0;
  3886.  this.flashCounter = 0;
  3887.  this.originalText = true;
  3888. }
  3889.  
  3890. GameOverPanel.RESTART_ANIM_DURATION = 875;
  3891. GameOverPanel.LOGO_PAUSE_DURATION = 875;
  3892. GameOverPanel.FLASH_ITERATIONS = 5;
  3893.  
  3894. /**
  3895. * Animation frames spec.
  3896. */
  3897. GameOverPanel.animConfig = {
  3898.  frames: [0, 36, 72, 108, 144, 180, 216, 252],
  3899.  msPerFrame: GameOverPanel.RESTART_ANIM_DURATION / 8,
  3900. };
  3901.  
  3902. /**
  3903. * Dimensions used in the panel.
  3904. * @enum {number}
  3905. */
  3906. GameOverPanel.dimensions = {
  3907.  TEXT_X: 0,
  3908.  TEXT_Y: 13,
  3909.  TEXT_WIDTH: 191,
  3910.  TEXT_HEIGHT: 11,
  3911.  RESTART_WIDTH: 36,
  3912.  RESTART_HEIGHT: 32,
  3913. };
  3914.  
  3915.  
  3916. GameOverPanel.prototype = {
  3917.  /**
  3918.   * Update the panel dimensions.
  3919.   * @param {number} width New canvas width.
  3920.   * @param {number} opt_height Optional new canvas height.
  3921.   */
  3922.  updateDimensions(width, opt_height) {
  3923.    this.canvasDimensions.WIDTH = width;
  3924.    if (opt_height) {
  3925.      this.canvasDimensions.HEIGHT = opt_height;
  3926.    }
  3927.    this.currentFrame = GameOverPanel.animConfig.frames.length - 1;
  3928.  },
  3929.  
  3930.  drawGameOverText(dimensions, opt_useAltText) {
  3931.    const centerX = this.canvasDimensions.WIDTH / 2;
  3932.    let textSourceX = dimensions.TEXT_X;
  3933.    let textSourceY = dimensions.TEXT_Y;
  3934.    let textSourceWidth = dimensions.TEXT_WIDTH;
  3935.    let textSourceHeight = dimensions.TEXT_HEIGHT;
  3936.  
  3937.    const textTargetX = Math.round(centerX - (dimensions.TEXT_WIDTH / 2));
  3938.    const textTargetY = Math.round((this.canvasDimensions.HEIGHT - 25) / 3);
  3939.    const textTargetWidth = dimensions.TEXT_WIDTH;
  3940.    const textTargetHeight = dimensions.TEXT_HEIGHT;
  3941.  
  3942.    if (IS_HIDPI) {
  3943.      textSourceY *= 2;
  3944.      textSourceX *= 2;
  3945.      textSourceWidth *= 2;
  3946.      textSourceHeight *= 2;
  3947.    }
  3948.  
  3949.    if (!opt_useAltText) {
  3950.      textSourceX += this.textImgPos.x;
  3951.      textSourceY += this.textImgPos.y;
  3952.    }
  3953.  
  3954.    const spriteSource =
  3955.        opt_useAltText ? Runner.altCommonImageSprite : Runner.origImageSprite;
  3956.  
  3957.    this.canvasCtx.save();
  3958.  
  3959.    if (IS_RTL) {
  3960.      this.canvasCtx.translate(this.canvasDimensions.WIDTH, 0);
  3961.      this.canvasCtx.scale(-1, 1);
  3962.    }
  3963.  
  3964.    // Game over text from sprite.
  3965.    this.canvasCtx.drawImage(
  3966.        spriteSource, textSourceX, textSourceY, textSourceWidth,
  3967.        textSourceHeight, textTargetX, textTargetY, textTargetWidth,
  3968.        textTargetHeight);
  3969.  
  3970.    this.canvasCtx.restore();
  3971.  },
  3972.  
  3973.  /**
  3974.   * Draw additional adornments for alternative game types.
  3975.   */
  3976.  drawAltGameElements(tRex) {
  3977.    // Additional adornments.
  3978.    if (this.altGameModeActive && Runner.spriteDefinition.ALT_GAME_END_CONFIG) {
  3979.      const altGameEndConfig = Runner.spriteDefinition.ALT_GAME_END_CONFIG;
  3980.  
  3981.      let altGameEndSourceWidth = altGameEndConfig.WIDTH;
  3982.      let altGameEndSourceHeight = altGameEndConfig.HEIGHT;
  3983.      const altGameEndTargetX = tRex.xPos + altGameEndConfig.X_OFFSET;
  3984.      const altGameEndTargetY = tRex.yPos + altGameEndConfig.Y_OFFSET;
  3985.  
  3986.      if (IS_HIDPI) {
  3987.        altGameEndSourceWidth *= 2;
  3988.        altGameEndSourceHeight *= 2;
  3989.      }
  3990.  
  3991.      this.canvasCtx.drawImage(
  3992.          Runner.altCommonImageSprite, this.altGameEndImgPos.x,
  3993.          this.altGameEndImgPos.y, altGameEndSourceWidth,
  3994.          altGameEndSourceHeight, altGameEndTargetX, altGameEndTargetY,
  3995.          altGameEndConfig.WIDTH, altGameEndConfig.HEIGHT);
  3996.    }
  3997.  },
  3998.  
  3999.  /**
  4000.   * Draw restart button.
  4001.   */
  4002.  drawRestartButton() {
  4003.    const dimensions = GameOverPanel.dimensions;
  4004.    let framePosX = GameOverPanel.animConfig.frames[this.currentFrame];
  4005.    let restartSourceWidth = dimensions.RESTART_WIDTH;
  4006.    let restartSourceHeight = dimensions.RESTART_HEIGHT;
  4007.    const restartTargetX =
  4008.        (this.canvasDimensions.WIDTH / 2) - (dimensions.RESTART_WIDTH / 2);
  4009.    const restartTargetY = this.canvasDimensions.HEIGHT / 2;
  4010.  
  4011.    if (IS_HIDPI) {
  4012.      restartSourceWidth *= 2;
  4013.      restartSourceHeight *= 2;
  4014.      framePosX *= 2;
  4015.    }
  4016.  
  4017.    this.canvasCtx.save();
  4018.  
  4019.    if (IS_RTL) {
  4020.      this.canvasCtx.translate(this.canvasDimensions.WIDTH, 0);
  4021.      this.canvasCtx.scale(-1, 1);
  4022.    }
  4023.  
  4024.    this.canvasCtx.drawImage(
  4025.        Runner.origImageSprite, this.restartImgPos.x + framePosX,
  4026.        this.restartImgPos.y, restartSourceWidth, restartSourceHeight,
  4027.        restartTargetX, restartTargetY, dimensions.RESTART_WIDTH,
  4028.        dimensions.RESTART_HEIGHT);
  4029.    this.canvasCtx.restore();
  4030.  },
  4031.  
  4032.  
  4033.  /**
  4034.   * Draw the panel.
  4035.   * @param {boolean} opt_altGameModeActive
  4036.   * @param {!Trex} opt_tRex
  4037.   */
  4038.  draw(opt_altGameModeActive, opt_tRex) {
  4039.    if (opt_altGameModeActive) {
  4040.      this.altGameModeActive = opt_altGameModeActive;
  4041.    }
  4042.  
  4043.    this.drawGameOverText(GameOverPanel.dimensions, false);
  4044.    this.drawRestartButton();
  4045.    this.drawAltGameElements(opt_tRex);
  4046.    this.update();
  4047.  },
  4048.  
  4049.  /**
  4050.   * Update animation frames.
  4051.   */
  4052.  update() {
  4053.    const now = getTimeStamp();
  4054.    const deltaTime = now - (this.frameTimeStamp || now);
  4055.  
  4056.    this.frameTimeStamp = now;
  4057.    this.animTimer += deltaTime;
  4058.    this.flashTimer += deltaTime;
  4059.  
  4060.    // Restart Button
  4061.    if (this.currentFrame == 0 &&
  4062.        this.animTimer > GameOverPanel.LOGO_PAUSE_DURATION) {
  4063.      this.animTimer = 0;
  4064.      this.currentFrame++;
  4065.      this.drawRestartButton();
  4066.    } else if (
  4067.        this.currentFrame > 0 &&
  4068.        this.currentFrame < GameOverPanel.animConfig.frames.length) {
  4069.      if (this.animTimer >= GameOverPanel.animConfig.msPerFrame) {
  4070.        this.currentFrame++;
  4071.        this.drawRestartButton();
  4072.      }
  4073.    } else if (
  4074.        !this.altGameModeActive &&
  4075.        this.currentFrame == GameOverPanel.animConfig.frames.length) {
  4076.      this.reset();
  4077.      return;
  4078.    }
  4079.  
  4080.    // Game over text
  4081.    if (this.altGameModeActive &&
  4082.        Runner.spriteDefinitionByType.original.ALT_GAME_OVER_TEXT_CONFIG) {
  4083.      const altTextConfig =
  4084.          Runner.spriteDefinitionByType.original.ALT_GAME_OVER_TEXT_CONFIG;
  4085.  
  4086.      if (this.flashCounter < GameOverPanel.FLASH_ITERATIONS &&
  4087.          this.flashTimer > altTextConfig.FLASH_DURATION) {
  4088.        this.flashTimer = 0;
  4089.        this.originalText = !this.originalText;
  4090.  
  4091.        this.clearGameOverTextBounds();
  4092.        if (this.originalText) {
  4093.          this.drawGameOverText(GameOverPanel.dimensions, false);
  4094.          this.flashCounter++;
  4095.        } else {
  4096.          this.drawGameOverText(altTextConfig, true);
  4097.        }
  4098.      } else if (this.flashCounter >= GameOverPanel.FLASH_ITERATIONS) {
  4099.        this.reset();
  4100.        return;
  4101.      }
  4102.    }
  4103.  
  4104.    this.gameOverRafId = requestAnimationFrame(this.update.bind(this));
  4105.  },
  4106.  
  4107.  /**
  4108.   * Clear game over text.
  4109.   */
  4110.  clearGameOverTextBounds() {
  4111.    this.canvasCtx.save();
  4112.  
  4113.    this.canvasCtx.clearRect(
  4114.        Math.round(
  4115.            this.canvasDimensions.WIDTH / 2 -
  4116.            (GameOverPanel.dimensions.TEXT_WIDTH / 2)),
  4117.        Math.round((this.canvasDimensions.HEIGHT - 25) / 3),
  4118.        GameOverPanel.dimensions.TEXT_WIDTH,
  4119.        GameOverPanel.dimensions.TEXT_HEIGHT + 4);
  4120.    this.canvasCtx.restore();
  4121.  },
  4122.  
  4123.  reset() {
  4124.    if (this.gameOverRafId) {
  4125.      cancelAnimationFrame(this.gameOverRafId);
  4126.      this.gameOverRafId = null;
  4127.    }
  4128.    this.animTimer = 0;
  4129.    this.frameTimeStamp = 0;
  4130.    this.currentFrame = 0;
  4131.    this.flashTimer = 0;
  4132.    this.flashCounter = 0;
  4133.    this.originalText = true;
  4134.  },
  4135. };
  4136.  
  4137.  
  4138. //******************************************************************************
  4139.  
  4140. /**
  4141. * Check for a collision.
  4142. * @param {!Obstacle} obstacle
  4143. * @param {!Trex} tRex T-rex object.
  4144. * @param {CanvasRenderingContext2D=} opt_canvasCtx Optional canvas context for
  4145. *    drawing collision boxes.
  4146. * @return {Array<CollisionBox>|undefined}
  4147. */
  4148. function checkForCollision(obstacle, tRex, opt_canvasCtx) {
  4149.  const obstacleBoxXPos = Runner.defaultDimensions.WIDTH + obstacle.xPos;
  4150.  
  4151.  // Adjustments are made to the bounding box as there is a 1 pixel white
  4152.  // border around the t-rex and obstacles.
  4153.  const tRexBox = new CollisionBox(
  4154.      tRex.xPos + 1,
  4155.      tRex.yPos + 1,
  4156.      tRex.config.WIDTH - 2,
  4157.      tRex.config.HEIGHT - 2);
  4158.  
  4159.  const obstacleBox = new CollisionBox(
  4160.      obstacle.xPos + 1,
  4161.      obstacle.yPos + 1,
  4162.      obstacle.typeConfig.width * obstacle.size - 2,
  4163.      obstacle.typeConfig.height - 2);
  4164.  
  4165.  // Debug outer box
  4166.  if (opt_canvasCtx) {
  4167.    drawCollisionBoxes(opt_canvasCtx, tRexBox, obstacleBox);
  4168.  }
  4169.  
  4170.  // Simple outer bounds check.
  4171.  if (boxCompare(tRexBox, obstacleBox)) {
  4172.    const collisionBoxes = obstacle.collisionBoxes;
  4173.    let tRexCollisionBoxes = [];
  4174.  
  4175.    if (Runner.isAltGameModeEnabled()) {
  4176.      tRexCollisionBoxes = Runner.spriteDefinition.TREX.COLLISION_BOXES;
  4177.    } else {
  4178.      tRexCollisionBoxes = tRex.ducking ? Trex.collisionBoxes.DUCKING :
  4179.                                          Trex.collisionBoxes.RUNNING;
  4180.    }
  4181.  
  4182.    // Detailed axis aligned box check.
  4183.    for (let t = 0; t < tRexCollisionBoxes.length; t++) {
  4184.      for (let i = 0; i < collisionBoxes.length; i++) {
  4185.        // Adjust the box to actual positions.
  4186.        const adjTrexBox =
  4187.            createAdjustedCollisionBox(tRexCollisionBoxes[t], tRexBox);
  4188.        const adjObstacleBox =
  4189.            createAdjustedCollisionBox(collisionBoxes[i], obstacleBox);
  4190.        const crashed = boxCompare(adjTrexBox, adjObstacleBox);
  4191.  
  4192.        // Draw boxes for debug.
  4193.        if (opt_canvasCtx) {
  4194.          drawCollisionBoxes(opt_canvasCtx, adjTrexBox, adjObstacleBox);
  4195.        }
  4196.  
  4197.        if (crashed) {
  4198.          return [adjTrexBox, adjObstacleBox];
  4199.        }
  4200.      }
  4201.    }
  4202.  }
  4203. }
  4204.  
  4205.  
  4206. /**
  4207. * Adjust the collision box.
  4208. * @param {!CollisionBox} box The original box.
  4209. * @param {!CollisionBox} adjustment Adjustment box.
  4210. * @return {CollisionBox} The adjusted collision box object.
  4211. */
  4212. function createAdjustedCollisionBox(box, adjustment) {
  4213.  return new CollisionBox(
  4214.      box.x + adjustment.x,
  4215.      box.y + adjustment.y,
  4216.      box.width,
  4217.      box.height);
  4218. }
  4219.  
  4220.  
  4221. /**
  4222. * Draw the collision boxes for debug.
  4223. */
  4224. function drawCollisionBoxes(canvasCtx, tRexBox, obstacleBox) {
  4225.  canvasCtx.save();
  4226.  canvasCtx.strokeStyle = '#f00';
  4227.  canvasCtx.strokeRect(tRexBox.x, tRexBox.y, tRexBox.width, tRexBox.height);
  4228.  
  4229.  canvasCtx.strokeStyle = '#0f0';
  4230.  canvasCtx.strokeRect(obstacleBox.x, obstacleBox.y,
  4231.      obstacleBox.width, obstacleBox.height);
  4232.  canvasCtx.restore();
  4233. }
  4234.  
  4235.  
  4236. /**
  4237. * Compare two collision boxes for a collision.
  4238. * @param {CollisionBox} tRexBox
  4239. * @param {CollisionBox} obstacleBox
  4240. * @return {boolean} Whether the boxes intersected.
  4241. */
  4242. function boxCompare(tRexBox, obstacleBox) {
  4243.  let crashed = false;
  4244.  const tRexBoxX = tRexBox.x;
  4245.  const tRexBoxY = tRexBox.y;
  4246.  
  4247.  const obstacleBoxX = obstacleBox.x;
  4248.  const obstacleBoxY = obstacleBox.y;
  4249.  
  4250.  // Axis-Aligned Bounding Box method.
  4251.  if (tRexBox.x < obstacleBoxX + obstacleBox.width &&
  4252.      tRexBox.x + tRexBox.width > obstacleBoxX &&
  4253.      tRexBox.y < obstacleBox.y + obstacleBox.height &&
  4254.      tRexBox.height + tRexBox.y > obstacleBox.y) {
  4255.    crashed = true;
  4256.  }
  4257.  
  4258.  return crashed;
  4259. }
  4260.  
  4261.  
  4262. //******************************************************************************
  4263.  
  4264. /**
  4265. * Collision box object.
  4266. * @param {number} x X position.
  4267. * @param {number} y Y Position.
  4268. * @param {number} w Width.
  4269. * @param {number} h Height.
  4270. * @constructor
  4271. */
  4272. function CollisionBox(x, y, w, h) {
  4273.  this.x = x;
  4274.  this.y = y;
  4275.  this.width = w;
  4276.  this.height = h;
  4277. }
  4278.  
  4279.  
  4280. //******************************************************************************
  4281.  
  4282. /**
  4283. * Obstacle.
  4284. * @param {CanvasRenderingContext2D} canvasCtx
  4285. * @param {ObstacleType} type
  4286. * @param {Object} spriteImgPos Obstacle position in sprite.
  4287. * @param {Object} dimensions
  4288. * @param {number} gapCoefficient Mutipler in determining the gap.
  4289. * @param {number} speed
  4290. * @param {number=} opt_xOffset
  4291. * @param {boolean=} opt_isAltGameMode
  4292. * @constructor
  4293. */
  4294. function Obstacle(
  4295.    canvasCtx, type, spriteImgPos, dimensions, gapCoefficient, speed,
  4296.    opt_xOffset, opt_isAltGameMode) {
  4297.  this.canvasCtx = canvasCtx;
  4298.  this.spritePos = spriteImgPos;
  4299.  this.typeConfig = type;
  4300.  this.gapCoefficient = Runner.slowDown ? gapCoefficient * 2 : gapCoefficient;
  4301.  this.size = getRandomNum(1, Obstacle.MAX_OBSTACLE_LENGTH);
  4302.  this.dimensions = dimensions;
  4303.  this.remove = false;
  4304.  this.xPos = dimensions.WIDTH + (opt_xOffset || 0);
  4305.  this.yPos = 0;
  4306.  this.width = 0;
  4307.  this.collisionBoxes = [];
  4308.  this.gap = 0;
  4309.  this.speedOffset = 0;
  4310.  this.altGameModeActive = opt_isAltGameMode;
  4311.  this.imageSprite = this.typeConfig.type == 'COLLECTABLE' ?
  4312.      Runner.altCommonImageSprite :
  4313.      this.altGameModeActive ? Runner.altGameImageSprite : Runner.imageSprite;
  4314.  
  4315.  // For animated obstacles.
  4316.  this.currentFrame = 0;
  4317.  this.timer = 0;
  4318.  
  4319.  this.init(speed);
  4320. }
  4321.  
  4322. /**
  4323. * Coefficient for calculating the maximum gap.
  4324. */
  4325. Obstacle.MAX_GAP_COEFFICIENT = 1.5;
  4326.  
  4327. /**
  4328. * Maximum obstacle grouping count.
  4329. */
  4330. Obstacle.MAX_OBSTACLE_LENGTH = 3;
  4331.  
  4332.  
  4333. Obstacle.prototype = {
  4334.  /**
  4335.   * Initialise the DOM for the obstacle.
  4336.   * @param {number} speed
  4337.   */
  4338.  init(speed) {
  4339.    this.cloneCollisionBoxes();
  4340.  
  4341.    // Only allow sizing if we're at the right speed.
  4342.    if (this.size > 1 && this.typeConfig.multipleSpeed > speed) {
  4343.      this.size = 1;
  4344.    }
  4345.  
  4346.    this.width = this.typeConfig.width * this.size;
  4347.  
  4348.    // Check if obstacle can be positioned at various heights.
  4349.    if (Array.isArray(this.typeConfig.yPos)) {
  4350.      const yPosConfig =
  4351.          IS_MOBILE ? this.typeConfig.yPosMobile : this.typeConfig.yPos;
  4352.      this.yPos = yPosConfig[getRandomNum(0, yPosConfig.length - 1)];
  4353.    } else {
  4354.      this.yPos = this.typeConfig.yPos;
  4355.    }
  4356.  
  4357.    this.draw();
  4358.  
  4359.    // Make collision box adjustments,
  4360.    // Central box is adjusted to the size as one box.
  4361.    //      ____        ______        ________
  4362.    //    _|   |-|    _|     |-|    _|       |-|
  4363.    //   | |<->| |   | |<--->| |   | |<----->| |
  4364.    //   | | 1 | |   | |  2  | |   | |   3   | |
  4365.    //   |_|___|_|   |_|_____|_|   |_|_______|_|
  4366.    //
  4367.    if (this.size > 1) {
  4368.      this.collisionBoxes[1].width = this.width - this.collisionBoxes[0].width -
  4369.          this.collisionBoxes[2].width;
  4370.      this.collisionBoxes[2].x = this.width - this.collisionBoxes[2].width;
  4371.    }
  4372.  
  4373.    // For obstacles that go at a different speed from the horizon.
  4374.    if (this.typeConfig.speedOffset) {
  4375.      this.speedOffset = Math.random() > 0.5 ? this.typeConfig.speedOffset :
  4376.                                               -this.typeConfig.speedOffset;
  4377.    }
  4378.  
  4379.    this.gap = this.getGap(this.gapCoefficient, speed);
  4380.  
  4381.    // Increase gap for audio cues enabled.
  4382.    if (Runner.audioCues) {
  4383.      this.gap *= 2;
  4384.    }
  4385.  },
  4386.  
  4387.  /**
  4388.   * Draw and crop based on size.
  4389.   */
  4390.  draw() {
  4391.    let sourceWidth = this.typeConfig.width;
  4392.    let sourceHeight = this.typeConfig.height;
  4393.  
  4394.    if (IS_HIDPI) {
  4395.      sourceWidth = sourceWidth * 2;
  4396.      sourceHeight = sourceHeight * 2;
  4397.    }
  4398.  
  4399.    // X position in sprite.
  4400.    let sourceX =
  4401.        (sourceWidth * this.size) * (0.5 * (this.size - 1)) + this.spritePos.x;
  4402.  
  4403.    // Animation frames.
  4404.    if (this.currentFrame > 0) {
  4405.      sourceX += sourceWidth * this.currentFrame;
  4406.    }
  4407.  
  4408.    this.canvasCtx.drawImage(
  4409.        this.imageSprite, sourceX, this.spritePos.y, sourceWidth * this.size,
  4410.        sourceHeight, this.xPos, this.yPos, this.typeConfig.width * this.size,
  4411.        this.typeConfig.height);
  4412.  },
  4413.  
  4414.  /**
  4415.   * Obstacle frame update.
  4416.   * @param {number} deltaTime
  4417.   * @param {number} speed
  4418.   */
  4419.  update(deltaTime, speed) {
  4420.    if (!this.remove) {
  4421.      if (this.typeConfig.speedOffset) {
  4422.        speed += this.speedOffset;
  4423.      }
  4424.      this.xPos -= Math.floor((speed * FPS / 1000) * deltaTime);
  4425.  
  4426.      // Update frame
  4427.      if (this.typeConfig.numFrames) {
  4428.        this.timer += deltaTime;
  4429.        if (this.timer >= this.typeConfig.frameRate) {
  4430.          this.currentFrame =
  4431.              this.currentFrame === this.typeConfig.numFrames - 1 ?
  4432.              0 :
  4433.              this.currentFrame + 1;
  4434.          this.timer = 0;
  4435.        }
  4436.      }
  4437.      this.draw();
  4438.  
  4439.      if (!this.isVisible()) {
  4440.        this.remove = true;
  4441.      }
  4442.    }
  4443.  },
  4444.  
  4445.  /**
  4446.   * Calculate a random gap size.
  4447.   * - Minimum gap gets wider as speed increses
  4448.   * @param {number} gapCoefficient
  4449.   * @param {number} speed
  4450.   * @return {number} The gap size.
  4451.   */
  4452.  getGap(gapCoefficient, speed) {
  4453.    const minGap = Math.round(
  4454.        this.width * speed + this.typeConfig.minGap * gapCoefficient);
  4455.    const maxGap = Math.round(minGap * Obstacle.MAX_GAP_COEFFICIENT);
  4456.    return getRandomNum(minGap, maxGap);
  4457.  },
  4458.  
  4459.  /**
  4460.   * Check if obstacle is visible.
  4461.   * @return {boolean} Whether the obstacle is in the game area.
  4462.   */
  4463.  isVisible() {
  4464.    return this.xPos + this.width > 0;
  4465.  },
  4466.  
  4467.  /**
  4468.   * Make a copy of the collision boxes, since these will change based on
  4469.   * obstacle type and size.
  4470.   */
  4471.  cloneCollisionBoxes() {
  4472.    const collisionBoxes = this.typeConfig.collisionBoxes;
  4473.  
  4474.    for (let i = collisionBoxes.length - 1; i >= 0; i--) {
  4475.      this.collisionBoxes[i] = new CollisionBox(
  4476.          collisionBoxes[i].x, collisionBoxes[i].y, collisionBoxes[i].width,
  4477.          collisionBoxes[i].height);
  4478.    }
  4479.  },
  4480. };
  4481.  
  4482.  
  4483. //******************************************************************************
  4484. /**
  4485. * T-rex game character.
  4486. * @param {HTMLCanvasElement} canvas
  4487. * @param {Object} spritePos Positioning within image sprite.
  4488. * @constructor
  4489. */
  4490. function Trex(canvas, spritePos) {
  4491.  this.canvas = canvas;
  4492.  this.canvasCtx =
  4493.      /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
  4494.  this.spritePos = spritePos;
  4495.  this.xPos = 0;
  4496.  this.yPos = 0;
  4497.  this.xInitialPos = 0;
  4498.  // Position when on the ground.
  4499.  this.groundYPos = 0;
  4500.  this.currentFrame = 0;
  4501.  this.currentAnimFrames = [];
  4502.  this.blinkDelay = 0;
  4503.  this.blinkCount = 0;
  4504.  this.animStartTime = 0;
  4505.  this.timer = 0;
  4506.  this.msPerFrame = 1000 / FPS;
  4507.  this.config = Object.assign(Trex.config, Trex.normalJumpConfig);
  4508.  // Current status.
  4509.  this.status = Trex.status.WAITING;
  4510.  this.jumping = false;
  4511.  this.ducking = false;
  4512.  this.jumpVelocity = 0;
  4513.  this.reachedMinHeight = false;
  4514.  this.speedDrop = false;
  4515.  this.jumpCount = 0;
  4516.  this.jumpspotX = 0;
  4517.  this.altGameModeEnabled = false;
  4518.  this.flashing = false;
  4519.  
  4520.  this.init();
  4521. }
  4522.  
  4523.  
  4524. /**
  4525. * T-rex player config.
  4526. */
  4527. Trex.config = {
  4528.  DROP_VELOCITY: -5,
  4529.  FLASH_OFF: 175,
  4530.  FLASH_ON: 100,
  4531.  HEIGHT: 47,
  4532.  HEIGHT_DUCK: 25,
  4533.  INTRO_DURATION: 1500,
  4534.  SPEED_DROP_COEFFICIENT: 3,
  4535.  SPRITE_WIDTH: 262,
  4536.  START_X_POS: 50,
  4537.  WIDTH: 44,
  4538.  WIDTH_DUCK: 59,
  4539. };
  4540.  
  4541. Trex.slowJumpConfig = {
  4542.  GRAVITY: 0.25,
  4543.  MAX_JUMP_HEIGHT: 50,
  4544.  MIN_JUMP_HEIGHT: 45,
  4545.  INITIAL_JUMP_VELOCITY: -20,
  4546. };
  4547.  
  4548. Trex.normalJumpConfig = {
  4549.  GRAVITY: 0.6,
  4550.  MAX_JUMP_HEIGHT: 30,
  4551.  MIN_JUMP_HEIGHT: 30,
  4552.  INITIAL_JUMP_VELOCITY: -10,
  4553. };
  4554.  
  4555. /**
  4556. * Used in collision detection.
  4557. * @enum {Array<CollisionBox>}
  4558. */
  4559. Trex.collisionBoxes = {
  4560.  DUCKING: [new CollisionBox(1, 18, 55, 25)],
  4561.  RUNNING: [
  4562.    new CollisionBox(22, 0, 17, 16),
  4563.    new CollisionBox(1, 18, 30, 9),
  4564.    new CollisionBox(10, 35, 14, 8),
  4565.    new CollisionBox(1, 24, 29, 5),
  4566.    new CollisionBox(5, 30, 21, 4),
  4567.    new CollisionBox(9, 34, 15, 4),
  4568.  ],
  4569. };
  4570.  
  4571.  
  4572. /**
  4573. * Animation states.
  4574. * @enum {string}
  4575. */
  4576. Trex.status = {
  4577.  CRASHED: 'CRASHED',
  4578.  DUCKING: 'DUCKING',
  4579.  JUMPING: 'JUMPING',
  4580.  RUNNING: 'RUNNING',
  4581.  WAITING: 'WAITING',
  4582. };
  4583.  
  4584. /**
  4585. * Blinking coefficient.
  4586. * @const
  4587. */
  4588. Trex.BLINK_TIMING = 7000;
  4589.  
  4590.  
  4591. /**
  4592. * Animation config for different states.
  4593. * @enum {Object}
  4594. */
  4595. Trex.animFrames = {
  4596.  WAITING: {
  4597.    frames: [44, 0],
  4598.    msPerFrame: 1000 / 3,
  4599.  },
  4600.  RUNNING: {
  4601.    frames: [88, 132],
  4602.    msPerFrame: 1000 / 12,
  4603.  },
  4604.  CRASHED: {
  4605.    frames: [220],
  4606.    msPerFrame: 1000 / 60,
  4607.  },
  4608.  JUMPING: {
  4609.    frames: [0],
  4610.    msPerFrame: 1000 / 60,
  4611.  },
  4612.  DUCKING: {
  4613.    frames: [264, 323],
  4614.    msPerFrame: 1000 / 8,
  4615.  },
  4616. };
  4617.  
  4618.  
  4619. Trex.prototype = {
  4620.  /**
  4621.   * T-rex player initaliser.
  4622.   * Sets the t-rex to blink at random intervals.
  4623.   */
  4624.  init() {
  4625.    this.groundYPos = Runner.defaultDimensions.HEIGHT - this.config.HEIGHT -
  4626.        Runner.config.BOTTOM_PAD;
  4627.    this.yPos = this.groundYPos;
  4628.    this.minJumpHeight = this.groundYPos - this.config.MIN_JUMP_HEIGHT;
  4629.  
  4630.    this.draw(0, 0);
  4631.    this.update(0, Trex.status.WAITING);
  4632.  },
  4633.  
  4634.  /**
  4635.   * Assign the appropriate jump parameters based on the game speed.
  4636.   */
  4637.  enableSlowConfig: function() {
  4638.    const jumpConfig =
  4639.        Runner.slowDown ? Trex.slowJumpConfig : Trex.normalJumpConfig;
  4640.    Trex.config = Object.assign(Trex.config, jumpConfig);
  4641.  
  4642.    this.adjustAltGameConfigForSlowSpeed();
  4643.  },
  4644.  
  4645.  /**
  4646.   * Enables the alternative game. Redefines the dino config.
  4647.   * @param {Object} spritePos New positioning within image sprite.
  4648.   */
  4649.  enableAltGameMode: function(spritePos) {
  4650.    this.altGameModeEnabled = true;
  4651.    this.spritePos = spritePos;
  4652.    const spriteDefinition = Runner.spriteDefinition['TREX'];
  4653.  
  4654.    // Update animation frames.
  4655.    Trex.animFrames.RUNNING.frames =
  4656.        [spriteDefinition.RUNNING_1.x, spriteDefinition.RUNNING_2.x];
  4657.    Trex.animFrames.CRASHED.frames = [spriteDefinition.CRASHED.x];
  4658.  
  4659.    if (typeof spriteDefinition.JUMPING.x == 'object') {
  4660.      Trex.animFrames.JUMPING.frames = spriteDefinition.JUMPING.x;
  4661.    } else {
  4662.      Trex.animFrames.JUMPING.frames = [spriteDefinition.JUMPING.x];
  4663.    }
  4664.  
  4665.    Trex.animFrames.DUCKING.frames =
  4666.        [spriteDefinition.RUNNING_1.x, spriteDefinition.RUNNING_2.x];
  4667.  
  4668.    // Update Trex config
  4669.    Trex.config.GRAVITY = spriteDefinition.GRAVITY || Trex.config.GRAVITY;
  4670.    Trex.config.HEIGHT = spriteDefinition.RUNNING_1.h,
  4671.    Trex.config.INITIAL_JUMP_VELOCITY = spriteDefinition.INITIAL_JUMP_VELOCITY;
  4672.    Trex.config.MAX_JUMP_HEIGHT = spriteDefinition.MAX_JUMP_HEIGHT;
  4673.    Trex.config.MIN_JUMP_HEIGHT = spriteDefinition.MIN_JUMP_HEIGHT;
  4674.    Trex.config.WIDTH = spriteDefinition.RUNNING_1.w;
  4675.    Trex.config.WIDTH_JUMP = spriteDefinition.JUMPING.w;
  4676.    Trex.config.INVERT_JUMP = spriteDefinition.INVERT_JUMP;
  4677.  
  4678.    this.adjustAltGameConfigForSlowSpeed(spriteDefinition.GRAVITY);
  4679.    this.config = Trex.config;
  4680.  
  4681.    // Adjust bottom horizon placement.
  4682.    this.groundYPos = Runner.defaultDimensions.HEIGHT - this.config.HEIGHT -
  4683.        Runner.spriteDefinition['BOTTOM_PAD'];
  4684.    this.yPos = this.groundYPos;
  4685.    this.reset();
  4686.  },
  4687.  
  4688.  /**
  4689.   * Slow speeds adjustments for the alt game modes.
  4690.   * @param {number=} opt_gravityValue
  4691.   */
  4692.  adjustAltGameConfigForSlowSpeed: function(opt_gravityValue) {
  4693.    if (Runner.slowDown) {
  4694.      if (opt_gravityValue) {
  4695.        Trex.config.GRAVITY = opt_gravityValue / 1.5;
  4696.      }
  4697.      Trex.config.MIN_JUMP_HEIGHT *= 1.5;
  4698.      Trex.config.MAX_JUMP_HEIGHT *= 1.5;
  4699.      Trex.config.INITIAL_JUMP_VELOCITY =
  4700.          Trex.config.INITIAL_JUMP_VELOCITY * 1.5;
  4701.    }
  4702.  },
  4703.  
  4704.  /**
  4705.   * Setter whether dino is flashing.
  4706.   * @param {boolean} status
  4707.   */
  4708.  setFlashing: function(status) {
  4709.    this.flashing = status;
  4710.  },
  4711.  
  4712.  /**
  4713.   * Setter for the jump velocity.
  4714.   * The approriate drop velocity is also set.
  4715.   * @param {number} setting
  4716.   */
  4717.  setJumpVelocity(setting) {
  4718.    this.config.INITIAL_JUMP_VELOCITY = -setting;
  4719.    this.config.DROP_VELOCITY = -setting / 2;
  4720.  },
  4721.  
  4722.  /**
  4723.   * Set the animation status.
  4724.   * @param {!number} deltaTime
  4725.   * @param {Trex.status=} opt_status Optional status to switch to.
  4726.   */
  4727.  update(deltaTime, opt_status) {
  4728.    this.timer += deltaTime;
  4729.  
  4730.    // Update the status.
  4731.    if (opt_status) {
  4732.      this.status = opt_status;
  4733.      this.currentFrame = 0;
  4734.      this.msPerFrame = Trex.animFrames[opt_status].msPerFrame;
  4735.      this.currentAnimFrames = Trex.animFrames[opt_status].frames;
  4736.  
  4737.      if (opt_status === Trex.status.WAITING) {
  4738.        this.animStartTime = getTimeStamp();
  4739.        this.setBlinkDelay();
  4740.      }
  4741.    }
  4742.    // Game intro animation, T-rex moves in from the left.
  4743.    if (this.playingIntro && this.xPos < this.config.START_X_POS) {
  4744.      this.xPos += Math.round((this.config.START_X_POS /
  4745.          this.config.INTRO_DURATION) * deltaTime);
  4746.      this.xInitialPos = this.xPos;
  4747.    }
  4748.  
  4749.    if (this.status === Trex.status.WAITING) {
  4750.      this.blink(getTimeStamp());
  4751.    } else {
  4752.      this.draw(this.currentAnimFrames[this.currentFrame], 0);
  4753.    }
  4754.  
  4755.    // Update the frame position.
  4756.    if (!this.flashing && this.timer >= this.msPerFrame) {
  4757.      this.currentFrame = this.currentFrame ==
  4758.          this.currentAnimFrames.length - 1 ? 0 : this.currentFrame + 1;
  4759.      this.timer = 0;
  4760.    }
  4761.  
  4762.    if (!this.altGameModeEnabled) {
  4763.      // Speed drop becomes duck if the down key is still being pressed.
  4764.      if (this.speedDrop && this.yPos === this.groundYPos) {
  4765.        this.speedDrop = false;
  4766.        this.setDuck(true);
  4767.      }
  4768.    }
  4769.  },
  4770.  
  4771.  /**
  4772.   * Draw the t-rex to a particular position.
  4773.   * @param {number} x
  4774.   * @param {number} y
  4775.   */
  4776.  draw(x, y) {
  4777.    let sourceX = x;
  4778.    let sourceY = y;
  4779.    let sourceWidth = this.ducking && this.status !== Trex.status.CRASHED ?
  4780.        this.config.WIDTH_DUCK :
  4781.        this.config.WIDTH;
  4782.    let sourceHeight = this.config.HEIGHT;
  4783.    const outputHeight = sourceHeight;
  4784.  
  4785.    let jumpOffset = Runner.spriteDefinition.TREX.JUMPING.xOffset;
  4786.  
  4787.    // Width of sprite changes on jump.
  4788.    if (this.altGameModeEnabled && this.jumping &&
  4789.        this.status !== Trex.status.CRASHED) {
  4790.      sourceWidth = this.config.WIDTH_JUMP;
  4791.    }
  4792.  
  4793.    if (IS_HIDPI) {
  4794.      sourceX *= 2;
  4795.      sourceY *= 2;
  4796.      sourceWidth *= 2;
  4797.      sourceHeight *= 2;
  4798.      jumpOffset *= 2;
  4799.    }
  4800.  
  4801.    // Adjustments for sprite sheet position.
  4802.    sourceX += this.spritePos.x;
  4803.    sourceY += this.spritePos.y;
  4804.  
  4805.    // Flashing.
  4806.    if (this.flashing) {
  4807.      if (this.timer < this.config.FLASH_ON) {
  4808.        this.canvasCtx.globalAlpha = 0.5;
  4809.      } else if (this.timer > this.config.FLASH_OFF) {
  4810.        this.timer = 0;
  4811.      }
  4812.    }
  4813.  
  4814.    // Ducking.
  4815.    if (!this.altGameModeEnabled && this.ducking &&
  4816.        this.status !== Trex.status.CRASHED) {
  4817.      this.canvasCtx.drawImage(Runner.imageSprite, sourceX, sourceY,
  4818.          sourceWidth, sourceHeight,
  4819.          this.xPos, this.yPos,
  4820.          this.config.WIDTH_DUCK, outputHeight);
  4821.    } else if (
  4822.        this.altGameModeEnabled && this.jumping &&
  4823.        this.status !== Trex.status.CRASHED) {
  4824.      // Jumping with adjustments.
  4825.      this.canvasCtx.drawImage(
  4826.          Runner.imageSprite, sourceX, sourceY, sourceWidth, sourceHeight,
  4827.          this.xPos - jumpOffset, this.yPos, this.config.WIDTH_JUMP,
  4828.          outputHeight);
  4829.    } else {
  4830.      // Crashed whilst ducking. Trex is standing up so needs adjustment.
  4831.      if (this.ducking && this.status === Trex.status.CRASHED) {
  4832.        this.xPos++;
  4833.      }
  4834.      // Standing / running
  4835.      this.canvasCtx.drawImage(Runner.imageSprite, sourceX, sourceY,
  4836.          sourceWidth, sourceHeight,
  4837.          this.xPos, this.yPos,
  4838.          this.config.WIDTH, outputHeight);
  4839.    }
  4840.    this.canvasCtx.globalAlpha = 1;
  4841.  },
  4842.  
  4843.  /**
  4844.   * Sets a random time for the blink to happen.
  4845.   */
  4846.  setBlinkDelay() {
  4847.    this.blinkDelay = Math.ceil(Math.random() * Trex.BLINK_TIMING);
  4848.  },
  4849.  
  4850.  /**
  4851.   * Make t-rex blink at random intervals.
  4852.   * @param {number} time Current time in milliseconds.
  4853.   */
  4854.  blink(time) {
  4855.    const deltaTime = time - this.animStartTime;
  4856.  
  4857.    if (deltaTime >= this.blinkDelay) {
  4858.      this.draw(this.currentAnimFrames[this.currentFrame], 0);
  4859.  
  4860.      if (this.currentFrame === 1) {
  4861.        // Set new random delay to blink.
  4862.        this.setBlinkDelay();
  4863.        this.animStartTime = time;
  4864.        this.blinkCount++;
  4865.      }
  4866.    }
  4867.  },
  4868.  
  4869.  /**
  4870.   * Initialise a jump.
  4871.   * @param {number} speed
  4872.   */
  4873.  startJump(speed) {
  4874.    if (!this.jumping) {
  4875.      this.update(0, Trex.status.JUMPING);
  4876.      // Tweak the jump velocity based on the speed.
  4877.      this.jumpVelocity = this.config.INITIAL_JUMP_VELOCITY - (speed / 10);
  4878.      this.jumping = true;
  4879.      this.reachedMinHeight = false;
  4880.      this.speedDrop = false;
  4881.  
  4882.      if (this.config.INVERT_JUMP) {
  4883.        this.minJumpHeight = this.groundYPos + this.config.MIN_JUMP_HEIGHT;
  4884.      }
  4885.    }
  4886.  },
  4887.  
  4888.  /**
  4889.   * Jump is complete, falling down.
  4890.   */
  4891.  endJump() {
  4892.    if (this.reachedMinHeight &&
  4893.        this.jumpVelocity < this.config.DROP_VELOCITY) {
  4894.      this.jumpVelocity = this.config.DROP_VELOCITY;
  4895.    }
  4896.  },
  4897.  
  4898.  /**
  4899.   * Update frame for a jump.
  4900.   * @param {number} deltaTime
  4901.   */
  4902.  updateJump(deltaTime) {
  4903.    const msPerFrame = Trex.animFrames[this.status].msPerFrame;
  4904.    const framesElapsed = deltaTime / msPerFrame;
  4905.  
  4906.    // Speed drop makes Trex fall faster.
  4907.    if (this.speedDrop) {
  4908.      this.yPos += Math.round(this.jumpVelocity *
  4909.          this.config.SPEED_DROP_COEFFICIENT * framesElapsed);
  4910.    } else if (this.config.INVERT_JUMP) {
  4911.      this.yPos -= Math.round(this.jumpVelocity * framesElapsed);
  4912.    } else {
  4913.      this.yPos += Math.round(this.jumpVelocity * framesElapsed);
  4914.    }
  4915.  
  4916.    this.jumpVelocity += this.config.GRAVITY * framesElapsed;
  4917.  
  4918.    // Minimum height has been reached.
  4919.    if (this.config.INVERT_JUMP && (this.yPos > this.minJumpHeight) ||
  4920.        !this.config.INVERT_JUMP && (this.yPos < this.minJumpHeight) ||
  4921.        this.speedDrop) {
  4922.      this.reachedMinHeight = true;
  4923.    }
  4924.  
  4925.    // Reached max height.
  4926.    if (this.config.INVERT_JUMP && (this.yPos > -this.config.MAX_JUMP_HEIGHT) ||
  4927.        !this.config.INVERT_JUMP && (this.yPos < this.config.MAX_JUMP_HEIGHT) ||
  4928.        this.speedDrop) {
  4929.      this.endJump();
  4930.    }
  4931.  
  4932.    // Back down at ground level. Jump completed.
  4933.    if ((this.config.INVERT_JUMP && this.yPos) < this.groundYPos ||
  4934.        (!this.config.INVERT_JUMP && this.yPos) > this.groundYPos) {
  4935.      this.reset();
  4936.      this.jumpCount++;
  4937.  
  4938.      if (Runner.audioCues) {
  4939.        Runner.generatedSoundFx.loopFootSteps();
  4940.      }
  4941.    }
  4942.  },
  4943.  
  4944.  /**
  4945.   * Set the speed drop. Immediately cancels the current jump.
  4946.   */
  4947.  setSpeedDrop() {
  4948.    this.speedDrop = true;
  4949.    this.jumpVelocity = 1;
  4950.  },
  4951.  
  4952.  /**
  4953.   * @param {boolean} isDucking
  4954.   */
  4955.  setDuck(isDucking) {
  4956.    if (isDucking && this.status !== Trex.status.DUCKING) {
  4957.      this.update(0, Trex.status.DUCKING);
  4958.      this.ducking = true;
  4959.    } else if (this.status === Trex.status.DUCKING) {
  4960.      this.update(0, Trex.status.RUNNING);
  4961.      this.ducking = false;
  4962.    }
  4963.  },
  4964.  
  4965.  /**
  4966.   * Reset the t-rex to running at start of game.
  4967.   */
  4968.  reset() {
  4969.    this.xPos = this.xInitialPos;
  4970.    this.yPos = this.groundYPos;
  4971.    this.jumpVelocity = 0;
  4972.    this.jumping = false;
  4973.    this.ducking = false;
  4974.    this.update(0, Trex.status.RUNNING);
  4975.    this.midair = false;
  4976.    this.speedDrop = false;
  4977.    this.jumpCount = 0;
  4978.  },
  4979. };
  4980.  
  4981.  
  4982. //******************************************************************************
  4983.  
  4984. /**
  4985. * Handles displaying the distance meter.
  4986. * @param {!HTMLCanvasElement} canvas
  4987. * @param {Object} spritePos Image position in sprite.
  4988. * @param {number} canvasWidth
  4989. * @constructor
  4990. */
  4991. function DistanceMeter(canvas, spritePos, canvasWidth) {
  4992.  this.canvas = canvas;
  4993.  this.canvasCtx =
  4994.      /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
  4995.  this.image = Runner.imageSprite;
  4996.  this.spritePos = spritePos;
  4997.  this.x = 0;
  4998.  this.y = 5;
  4999.  
  5000.  this.currentDistance = 0;
  5001.  this.maxScore = 0;
  5002.  this.highScore = '0';
  5003.  this.container = null;
  5004.  
  5005.  this.digits = [];
  5006.  this.achievement = false;
  5007.  this.defaultString = '';
  5008.  this.flashTimer = 0;
  5009.  this.flashIterations = 0;
  5010.  this.invertTrigger = false;
  5011.  this.flashingRafId = null;
  5012.  this.highScoreBounds = {};
  5013.  this.highScoreFlashing = false;
  5014.  
  5015.  this.config = DistanceMeter.config;
  5016.  this.maxScoreUnits = this.config.MAX_DISTANCE_UNITS;
  5017.  this.canvasWidth = canvasWidth;
  5018.  this.init(canvasWidth);
  5019. }
  5020.  
  5021.  
  5022. /**
  5023. * @enum {number}
  5024. */
  5025. DistanceMeter.dimensions = {
  5026.  WIDTH: 10,
  5027.  HEIGHT: 13,
  5028.  DEST_WIDTH: 11,
  5029. };
  5030.  
  5031.  
  5032. /**
  5033. * Y positioning of the digits in the sprite sheet.
  5034. * X position is always 0.
  5035. * @type {Array<number>}
  5036. */
  5037. DistanceMeter.yPos = [0, 13, 27, 40, 53, 67, 80, 93, 107, 120];
  5038.  
  5039.  
  5040. /**
  5041. * Distance meter config.
  5042. * @enum {number}
  5043. */
  5044. DistanceMeter.config = {
  5045.  // Number of digits.
  5046.  MAX_DISTANCE_UNITS: 5,
  5047.  
  5048.  // Distance that causes achievement animation.
  5049.  ACHIEVEMENT_DISTANCE: 100,
  5050.  
  5051.  // Used for conversion from pixel distance to a scaled unit.
  5052.  COEFFICIENT: 0.025,
  5053.  
  5054.  // Flash duration in milliseconds.
  5055.  FLASH_DURATION: 1000 / 4,
  5056.  
  5057.  // Flash iterations for achievement animation.
  5058.  FLASH_ITERATIONS: 3,
  5059.  
  5060.  // Padding around the high score hit area.
  5061.  HIGH_SCORE_HIT_AREA_PADDING: 4,
  5062. };
  5063.  
  5064.  
  5065. DistanceMeter.prototype = {
  5066.  /**
  5067.   * Initialise the distance meter to '00000'.
  5068.   * @param {number} width Canvas width in px.
  5069.   */
  5070.  init(width) {
  5071.    let maxDistanceStr = '';
  5072.  
  5073.    this.calcXPos(width);
  5074.    this.maxScore = this.maxScoreUnits;
  5075.    for (let i = 0; i < this.maxScoreUnits; i++) {
  5076.      this.draw(i, 0);
  5077.      this.defaultString += '0';
  5078.      maxDistanceStr += '9';
  5079.    }
  5080.  
  5081.    this.maxScore = parseInt(maxDistanceStr, 10);
  5082.  },
  5083.  
  5084.  /**
  5085.   * Calculate the xPos in the canvas.
  5086.   * @param {number} canvasWidth
  5087.   */
  5088.  calcXPos(canvasWidth) {
  5089.    this.x = canvasWidth - (DistanceMeter.dimensions.DEST_WIDTH *
  5090.        (this.maxScoreUnits + 1));
  5091.  },
  5092.  
  5093.  /**
  5094.   * Draw a digit to canvas.
  5095.   * @param {number} digitPos Position of the digit.
  5096.   * @param {number} value Digit value 0-9.
  5097.   * @param {boolean=} opt_highScore Whether drawing the high score.
  5098.   */
  5099.  draw(digitPos, value, opt_highScore) {
  5100.    let sourceWidth = DistanceMeter.dimensions.WIDTH;
  5101.    let sourceHeight = DistanceMeter.dimensions.HEIGHT;
  5102.    let sourceX = DistanceMeter.dimensions.WIDTH * value;
  5103.    let sourceY = 0;
  5104.  
  5105.    const targetX = digitPos * DistanceMeter.dimensions.DEST_WIDTH;
  5106.    const targetY = this.y;
  5107.    const targetWidth = DistanceMeter.dimensions.WIDTH;
  5108.    const targetHeight = DistanceMeter.dimensions.HEIGHT;
  5109.  
  5110.    // For high DPI we 2x source values.
  5111.    if (IS_HIDPI) {
  5112.      sourceWidth *= 2;
  5113.      sourceHeight *= 2;
  5114.      sourceX *= 2;
  5115.    }
  5116.  
  5117.    sourceX += this.spritePos.x;
  5118.    sourceY += this.spritePos.y;
  5119.  
  5120.    this.canvasCtx.save();
  5121.  
  5122.    if (IS_RTL) {
  5123.      if (opt_highScore) {
  5124.        this.canvasCtx.translate(
  5125.            this.canvasWidth -
  5126.                (DistanceMeter.dimensions.WIDTH * (this.maxScoreUnits + 3)),
  5127.            this.y);
  5128.      } else {
  5129.        this.canvasCtx.translate(
  5130.            this.canvasWidth - DistanceMeter.dimensions.WIDTH, this.y);
  5131.      }
  5132.      this.canvasCtx.scale(-1, 1);
  5133.    } else {
  5134.      const highScoreX =
  5135.          this.x - (this.maxScoreUnits * 2) * DistanceMeter.dimensions.WIDTH;
  5136.      if (opt_highScore) {
  5137.        this.canvasCtx.translate(highScoreX, this.y);
  5138.      } else {
  5139.        this.canvasCtx.translate(this.x, this.y);
  5140.      }
  5141.    }
  5142.  
  5143.    this.canvasCtx.drawImage(
  5144.        this.image,
  5145.        sourceX,
  5146.        sourceY,
  5147.        sourceWidth,
  5148.        sourceHeight,
  5149.        targetX,
  5150.        targetY,
  5151.        targetWidth,
  5152.        targetHeight,
  5153.    );
  5154.  
  5155.    this.canvasCtx.restore();
  5156.  },
  5157.  
  5158.  /**
  5159.   * Covert pixel distance to a 'real' distance.
  5160.   * @param {number} distance Pixel distance ran.
  5161.   * @return {number} The 'real' distance ran.
  5162.   */
  5163.  getActualDistance(distance) {
  5164.    return distance ? Math.round(distance * this.config.COEFFICIENT) : 0;
  5165.  },
  5166.  
  5167.  /**
  5168.   * Update the distance meter.
  5169.   * @param {number} distance
  5170.   * @param {number} deltaTime
  5171.   * @return {boolean} Whether the acheivement sound fx should be played.
  5172.   */
  5173.  update(deltaTime, distance) {
  5174.    let paint = true;
  5175.    let playSound = false;
  5176.  
  5177.    if (!this.achievement) {
  5178.      distance = this.getActualDistance(distance);
  5179.      // Score has gone beyond the initial digit count.
  5180.      if (distance > this.maxScore && this.maxScoreUnits ==
  5181.        this.config.MAX_DISTANCE_UNITS) {
  5182.        this.maxScoreUnits++;
  5183.        this.maxScore = parseInt(this.maxScore + '9', 10);
  5184.      } else {
  5185.        this.distance = 0;
  5186.      }
  5187.  
  5188.      if (distance > 0) {
  5189.        // Achievement unlocked.
  5190.        if (distance % this.config.ACHIEVEMENT_DISTANCE === 0) {
  5191.          // Flash score and play sound.
  5192.          this.achievement = true;
  5193.          this.flashTimer = 0;
  5194.          playSound = true;
  5195.        }
  5196.  
  5197.        // Create a string representation of the distance with leading 0.
  5198.        const distanceStr = (this.defaultString +
  5199.            distance).substr(-this.maxScoreUnits);
  5200.        this.digits = distanceStr.split('');
  5201.      } else {
  5202.        this.digits = this.defaultString.split('');
  5203.      }
  5204.    } else {
  5205.      // Control flashing of the score on reaching acheivement.
  5206.      if (this.flashIterations <= this.config.FLASH_ITERATIONS) {
  5207.        this.flashTimer += deltaTime;
  5208.  
  5209.        if (this.flashTimer < this.config.FLASH_DURATION) {
  5210.          paint = false;
  5211.        } else if (this.flashTimer > this.config.FLASH_DURATION * 2) {
  5212.          this.flashTimer = 0;
  5213.          this.flashIterations++;
  5214.        }
  5215.      } else {
  5216.        this.achievement = false;
  5217.        this.flashIterations = 0;
  5218.        this.flashTimer = 0;
  5219.      }
  5220.    }
  5221.  
  5222.    // Draw the digits if not flashing.
  5223.    if (paint) {
  5224.      for (let i = this.digits.length - 1; i >= 0; i--) {
  5225.        this.draw(i, parseInt(this.digits[i], 10));
  5226.      }
  5227.    }
  5228.  
  5229.    this.drawHighScore();
  5230.    return playSound;
  5231.  },
  5232.  
  5233.  /**
  5234.   * Draw the high score.
  5235.   */
  5236.  drawHighScore() {
  5237.    if (parseInt(this.highScore, 10) > 0) {
  5238.      this.canvasCtx.save();
  5239.      this.canvasCtx.globalAlpha = .8;
  5240.      for (let i = this.highScore.length - 1; i >= 0; i--) {
  5241.        this.draw(i, parseInt(this.highScore[i], 10), true);
  5242.      }
  5243.      this.canvasCtx.restore();
  5244.    }
  5245.  },
  5246.  
  5247.  /**
  5248.   * Set the highscore as a array string.
  5249.   * Position of char in the sprite: H - 10, I - 11.
  5250.   * @param {number} distance Distance ran in pixels.
  5251.   */
  5252.  setHighScore(distance) {
  5253.    distance = this.getActualDistance(distance);
  5254.    const highScoreStr = (this.defaultString +
  5255.        distance).substr(-this.maxScoreUnits);
  5256.  
  5257.    this.highScore = ['10', '11', ''].concat(highScoreStr.split(''));
  5258.  },
  5259.  
  5260.  
  5261.  /**
  5262.   * Whether a clicked is in the high score area.
  5263.   * @param {Event} e Event object.
  5264.   * @return {boolean} Whether the click was in the high score bounds.
  5265.   */
  5266.  hasClickedOnHighScore(e) {
  5267.    let x = 0;
  5268.    let y = 0;
  5269.  
  5270.    if (e.touches) {
  5271.      // Bounds for touch differ from pointer.
  5272.      const canvasBounds = this.canvas.getBoundingClientRect();
  5273.      x = e.touches[0].clientX - canvasBounds.left;
  5274.      y = e.touches[0].clientY - canvasBounds.top;
  5275.    } else {
  5276.      x = e.offsetX;
  5277.      y = e.offsetY;
  5278.    }
  5279.  
  5280.    this.highScoreBounds = this.getHighScoreBounds();
  5281.    return x >= this.highScoreBounds.x && x <=
  5282.        this.highScoreBounds.x + this.highScoreBounds.width &&
  5283.        y >= this.highScoreBounds.y && y <=
  5284.        this.highScoreBounds.y + this.highScoreBounds.height;
  5285.  },
  5286.  
  5287.  /**
  5288.   * Get the bounding box for the high score.
  5289.   * @return {Object} Object with x, y, width and height properties.
  5290.   */
  5291.  getHighScoreBounds() {
  5292.    return {
  5293.      x: (this.x - (this.maxScoreUnits * 2) * DistanceMeter.dimensions.WIDTH) -
  5294.          DistanceMeter.config.HIGH_SCORE_HIT_AREA_PADDING,
  5295.      y: this.y,
  5296.      width: DistanceMeter.dimensions.WIDTH * (this.highScore.length + 1) +
  5297.          DistanceMeter.config.HIGH_SCORE_HIT_AREA_PADDING,
  5298.      height: DistanceMeter.dimensions.HEIGHT +
  5299.          (DistanceMeter.config.HIGH_SCORE_HIT_AREA_PADDING * 2),
  5300.    };
  5301.  },
  5302.  
  5303.  /**
  5304.   * Animate flashing the high score to indicate ready for resetting.
  5305.   * The flashing stops following this.config.FLASH_ITERATIONS x 2 flashes.
  5306.   */
  5307.  flashHighScore() {
  5308.    const now = getTimeStamp();
  5309.    const deltaTime = now - (this.frameTimeStamp || now);
  5310.    let paint = true;
  5311.    this.frameTimeStamp = now;
  5312.  
  5313.    // Reached the max number of flashes.
  5314.    if (this.flashIterations > this.config.FLASH_ITERATIONS * 2) {
  5315.      this.cancelHighScoreFlashing();
  5316.      return;
  5317.    }
  5318.  
  5319.    this.flashTimer += deltaTime;
  5320.  
  5321.    if (this.flashTimer < this.config.FLASH_DURATION) {
  5322.      paint = false;
  5323.    } else if (this.flashTimer > this.config.FLASH_DURATION * 2) {
  5324.      this.flashTimer = 0;
  5325.      this.flashIterations++;
  5326.    }
  5327.  
  5328.    if (paint) {
  5329.      this.drawHighScore();
  5330.    } else {
  5331.      this.clearHighScoreBounds();
  5332.    }
  5333.    // Frame update.
  5334.    this.flashingRafId =
  5335.        requestAnimationFrame(this.flashHighScore.bind(this));
  5336.  },
  5337.  
  5338.  /**
  5339.   * Draw empty rectangle over high score.
  5340.   */
  5341.  clearHighScoreBounds() {
  5342.    this.canvasCtx.save();
  5343.    this.canvasCtx.fillStyle = '#fff';
  5344.    this.canvasCtx.rect(this.highScoreBounds.x, this.highScoreBounds.y,
  5345.        this.highScoreBounds.width, this.highScoreBounds.height);
  5346.    this.canvasCtx.fill();
  5347.    this.canvasCtx.restore();
  5348.  },
  5349.  
  5350.  /**
  5351.   * Starts the flashing of the high score.
  5352.   */
  5353.  startHighScoreFlashing() {
  5354.    this.highScoreFlashing = true;
  5355.    this.flashHighScore();
  5356.  },
  5357.  
  5358.  /**
  5359.   * Whether high score is flashing.
  5360.   * @return {boolean}
  5361.   */
  5362.  isHighScoreFlashing() {
  5363.    return this.highScoreFlashing;
  5364.  },
  5365.  
  5366.  /**
  5367.   * Stop flashing the high score.
  5368.   */
  5369.  cancelHighScoreFlashing() {
  5370.    if (this.flashingRafId) {
  5371.      cancelAnimationFrame(this.flashingRafId);
  5372.    }
  5373.    this.flashIterations = 0;
  5374.    this.flashTimer = 0;
  5375.    this.highScoreFlashing = false;
  5376.    this.clearHighScoreBounds();
  5377.    this.drawHighScore();
  5378.  },
  5379.  
  5380.  /**
  5381.   * Clear the high score.
  5382.   */
  5383.  resetHighScore() {
  5384.    this.setHighScore(0);
  5385.    this.cancelHighScoreFlashing();
  5386.  },
  5387.  
  5388.  /**
  5389.   * Reset the distance meter back to '00000'.
  5390.   */
  5391.  reset() {
  5392.    this.update(0, 0);
  5393.    this.achievement = false;
  5394.  },
  5395. };
  5396.  
  5397.  
  5398. //******************************************************************************
  5399.  
  5400. /**
  5401. * Cloud background item.
  5402. * Similar to an obstacle object but without collision boxes.
  5403. * @param {HTMLCanvasElement} canvas Canvas element.
  5404. * @param {Object} spritePos Position of image in sprite.
  5405. * @param {number} containerWidth
  5406. * @constructor
  5407. */
  5408. function Cloud(canvas, spritePos, containerWidth) {
  5409.  this.canvas = canvas;
  5410.  this.canvasCtx =
  5411.      /** @type {CanvasRenderingContext2D} */ (this.canvas.getContext('2d'));
  5412.  this.spritePos = spritePos;
  5413.  this.containerWidth = containerWidth;
  5414.  this.xPos = containerWidth;
  5415.  this.yPos = 0;
  5416.  this.remove = false;
  5417.  this.gap =
  5418.      getRandomNum(Cloud.config.MIN_CLOUD_GAP, Cloud.config.MAX_CLOUD_GAP);
  5419.  
  5420.  this.init();
  5421. }
  5422.  
  5423.  
  5424. /**
  5425. * Cloud object config.
  5426. * @enum {number}
  5427. */
  5428. Cloud.config = {
  5429.  HEIGHT: 14,
  5430.  MAX_CLOUD_GAP: 400,
  5431.  MAX_SKY_LEVEL: 30,
  5432.  MIN_CLOUD_GAP: 100,
  5433.  MIN_SKY_LEVEL: 71,
  5434.  WIDTH: 46,
  5435. };
  5436.  
  5437.  
  5438. Cloud.prototype = {
  5439.  /**
  5440.   * Initialise the cloud. Sets the Cloud height.
  5441.   */
  5442.  init() {
  5443.    this.yPos = getRandomNum(Cloud.config.MAX_SKY_LEVEL,
  5444.        Cloud.config.MIN_SKY_LEVEL);
  5445.    this.draw();
  5446.  },
  5447.  
  5448.  /**
  5449.   * Draw the cloud.
  5450.   */
  5451.  draw() {
  5452.    this.canvasCtx.save();
  5453.    let sourceWidth = Cloud.config.WIDTH;
  5454.    let sourceHeight = Cloud.config.HEIGHT;
  5455.    const outputWidth = sourceWidth;
  5456.    const outputHeight = sourceHeight;
  5457.    if (IS_HIDPI) {
  5458.      sourceWidth = sourceWidth * 2;
  5459.      sourceHeight = sourceHeight * 2;
  5460.    }
  5461.  
  5462.    this.canvasCtx.drawImage(Runner.imageSprite, this.spritePos.x,
  5463.        this.spritePos.y,
  5464.        sourceWidth, sourceHeight,
  5465.        this.xPos, this.yPos,
  5466.        outputWidth, outputHeight);
  5467.  
  5468.    this.canvasCtx.restore();
  5469.  },
  5470.  
  5471.  /**
  5472.   * Update the cloud position.
  5473.   * @param {number} speed
  5474.   */
  5475.  update(speed) {
  5476.    if (!this.remove) {
  5477.      this.xPos -= Math.ceil(speed);
  5478.      this.draw();
  5479.  
  5480.      // Mark as removeable if no longer in the canvas.
  5481.      if (!this.isVisible()) {
  5482.        this.remove = true;
  5483.      }
  5484.    }
  5485.  },
  5486.  
  5487.  /**
  5488.   * Check if the cloud is visible on the stage.
  5489.   * @return {boolean}
  5490.   */
  5491.  isVisible() {
  5492.    return this.xPos + Cloud.config.WIDTH > 0;
  5493.  },
  5494. };
  5495.  
  5496.  
  5497. /**
  5498. * Background item.
  5499. * Similar to cloud, without random y position.
  5500. * @param {HTMLCanvasElement} canvas Canvas element.
  5501. * @param {Object} spritePos Position of image in sprite.
  5502. * @param {number} containerWidth
  5503. * @param {string} type Element type.
  5504. * @constructor
  5505. */
  5506. function BackgroundEl(canvas, spritePos, containerWidth, type) {
  5507.  this.canvas = canvas;
  5508.  this.canvasCtx =
  5509.      /** @type {CanvasRenderingContext2D} */ (this.canvas.getContext('2d'));
  5510.  this.spritePos = spritePos;
  5511.  this.containerWidth = containerWidth;
  5512.  this.xPos = containerWidth;
  5513.  this.yPos = 0;
  5514.  this.remove = false;
  5515.  this.type = type;
  5516.  this.gap =
  5517.      getRandomNum(BackgroundEl.config.MIN_GAP, BackgroundEl.config.MAX_GAP);
  5518.  this.animTimer = 0;
  5519.  this.switchFrames = false;
  5520.  
  5521.  this.spriteConfig = {};
  5522.  this.init();
  5523. }
  5524.  
  5525. /**
  5526. * Background element object config.
  5527. * Real values assigned when game type changes.
  5528. * @enum {number}
  5529. */
  5530. BackgroundEl.config = {
  5531.  MAX_BG_ELS: 0,
  5532.  MAX_GAP: 0,
  5533.  MIN_GAP: 0,
  5534.  POS: 0,
  5535.  SPEED: 0,
  5536.  Y_POS: 0,
  5537.  MS_PER_FRAME: 0,  // only needed when BACKGROUND_EL.FIXED is true
  5538. };
  5539.  
  5540.  
  5541. BackgroundEl.prototype = {
  5542.  /**
  5543.   * Initialise the element setting the y position.
  5544.   */
  5545.  init() {
  5546.    this.spriteConfig = Runner.spriteDefinition.BACKGROUND_EL[this.type];
  5547.    if (this.spriteConfig.FIXED) {
  5548.      this.xPos = this.spriteConfig.FIXED_X_POS;
  5549.    }
  5550.    this.yPos = BackgroundEl.config.Y_POS - this.spriteConfig.HEIGHT +
  5551.        this.spriteConfig.OFFSET;
  5552.    this.draw();
  5553.  },
  5554.  
  5555.  /**
  5556.   * Draw the element.
  5557.   */
  5558.  draw() {
  5559.    this.canvasCtx.save();
  5560.    let sourceWidth = this.spriteConfig.WIDTH;
  5561.    let sourceHeight = this.spriteConfig.HEIGHT;
  5562.    let sourceX = this.spriteConfig.X_POS;
  5563.    const outputWidth = sourceWidth;
  5564.    const outputHeight = sourceHeight;
  5565.  
  5566.    if (IS_HIDPI) {
  5567.      sourceWidth *= 2;
  5568.      sourceHeight *= 2;
  5569.      sourceX *= 2;
  5570.    }
  5571.  
  5572.    this.canvasCtx.drawImage(
  5573.        Runner.imageSprite, sourceX, this.spritePos.y, sourceWidth,
  5574.        sourceHeight, this.xPos, this.yPos, outputWidth, outputHeight);
  5575.  
  5576.    this.canvasCtx.restore();
  5577.  },
  5578.  
  5579.  /**
  5580.   * Update the background element position.
  5581.   * @param {number} speed
  5582.   */
  5583.  update(speed) {
  5584.    if (!this.remove) {
  5585.      if (this.spriteConfig.FIXED) {
  5586.        this.animTimer += speed;
  5587.        if (this.animTimer > BackgroundEl.config.MS_PER_FRAME) {
  5588.          this.animTimer = 0;
  5589.          this.switchFrames = !this.switchFrames;
  5590.        }
  5591.  
  5592.        if (this.spriteConfig.FIXED_Y_POS_1 &&
  5593.            this.spriteConfig.FIXED_Y_POS_2) {
  5594.          this.yPos = this.switchFrames ? this.spriteConfig.FIXED_Y_POS_1 :
  5595.                                          this.spriteConfig.FIXED_Y_POS_2;
  5596.        }
  5597.      } else {
  5598.        // Fixed speed, regardless of actual game speed.
  5599.        this.xPos -= BackgroundEl.config.SPEED;
  5600.      }
  5601.      this.draw();
  5602.  
  5603.      // Mark as removable if no longer in the canvas.
  5604.      if (!this.isVisible()) {
  5605.        this.remove = true;
  5606.      }
  5607.    }
  5608.  },
  5609.  
  5610.  /**
  5611.   * Check if the element is visible on the stage.
  5612.   * @return {boolean}
  5613.   */
  5614.  isVisible() {
  5615.    return this.xPos + this.spriteConfig.WIDTH > 0;
  5616.  },
  5617. };
  5618.  
  5619.  
  5620.  
  5621. //******************************************************************************
  5622.  
  5623. /**
  5624. * Nightmode shows a moon and stars on the horizon.
  5625. * @param {HTMLCanvasElement} canvas
  5626. * @param {number} spritePos
  5627. * @param {number} containerWidth
  5628. * @constructor
  5629. */
  5630. function NightMode(canvas, spritePos, containerWidth) {
  5631.  this.spritePos = spritePos;
  5632.  this.canvas = canvas;
  5633.  this.canvasCtx =
  5634.      /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
  5635.  this.xPos = containerWidth - 50;
  5636.  this.yPos = 30;
  5637.  this.currentPhase = 0;
  5638.  this.opacity = 0;
  5639.  this.containerWidth = containerWidth;
  5640.  this.stars = [];
  5641.  this.drawStars = false;
  5642.  this.placeStars();
  5643. }
  5644.  
  5645. /**
  5646. * @enum {number}
  5647. */
  5648. NightMode.config = {
  5649.  FADE_SPEED: 0.035,
  5650.  HEIGHT: 40,
  5651.  MOON_SPEED: 0.25,
  5652.  NUM_STARS: 2,
  5653.  STAR_SIZE: 9,
  5654.  STAR_SPEED: 0.3,
  5655.  STAR_MAX_Y: 70,
  5656.  WIDTH: 20,
  5657. };
  5658.  
  5659. NightMode.phases = [140, 120, 100, 60, 40, 20, 0];
  5660.  
  5661. NightMode.prototype = {
  5662.  /**
  5663.   * Update moving moon, changing phases.
  5664.   * @param {boolean} activated Whether night mode is activated.
  5665.   */
  5666.  update(activated) {
  5667.    // Moon phase.
  5668.    if (activated && this.opacity === 0) {
  5669.      this.currentPhase++;
  5670.  
  5671.      if (this.currentPhase >= NightMode.phases.length) {
  5672.        this.currentPhase = 0;
  5673.      }
  5674.    }
  5675.  
  5676.    // Fade in / out.
  5677.    if (activated && (this.opacity < 1 || this.opacity === 0)) {
  5678.      this.opacity += NightMode.config.FADE_SPEED;
  5679.    } else if (this.opacity > 0) {
  5680.      this.opacity -= NightMode.config.FADE_SPEED;
  5681.    }
  5682.  
  5683.    // Set moon positioning.
  5684.    if (this.opacity > 0) {
  5685.      this.xPos = this.updateXPos(this.xPos, NightMode.config.MOON_SPEED);
  5686.  
  5687.      // Update stars.
  5688.      if (this.drawStars) {
  5689.        for (let i = 0; i < NightMode.config.NUM_STARS; i++) {
  5690.          this.stars[i].x =
  5691.              this.updateXPos(this.stars[i].x, NightMode.config.STAR_SPEED);
  5692.        }
  5693.      }
  5694.      this.draw();
  5695.    } else {
  5696.      this.opacity = 0;
  5697.      this.placeStars();
  5698.    }
  5699.    this.drawStars = true;
  5700.  },
  5701.  
  5702.  updateXPos(currentPos, speed) {
  5703.    if (currentPos < -NightMode.config.WIDTH) {
  5704.      currentPos = this.containerWidth;
  5705.    } else {
  5706.      currentPos -= speed;
  5707.    }
  5708.    return currentPos;
  5709.  },
  5710.  
  5711.  draw() {
  5712.    let moonSourceWidth = this.currentPhase === 3 ? NightMode.config.WIDTH * 2 :
  5713.                                                    NightMode.config.WIDTH;
  5714.    let moonSourceHeight = NightMode.config.HEIGHT;
  5715.    let moonSourceX = this.spritePos.x + NightMode.phases[this.currentPhase];
  5716.    const moonOutputWidth = moonSourceWidth;
  5717.    let starSize = NightMode.config.STAR_SIZE;
  5718.    let starSourceX = Runner.spriteDefinitionByType.original.LDPI.STAR.x;
  5719.  
  5720.    if (IS_HIDPI) {
  5721.      moonSourceWidth *= 2;
  5722.      moonSourceHeight *= 2;
  5723.      moonSourceX = this.spritePos.x +
  5724.          (NightMode.phases[this.currentPhase] * 2);
  5725.      starSize *= 2;
  5726.      starSourceX = Runner.spriteDefinitionByType.original.HDPI.STAR.x;
  5727.    }
  5728.  
  5729.    this.canvasCtx.save();
  5730.    this.canvasCtx.globalAlpha = this.opacity;
  5731.  
  5732.    // Stars.
  5733.    if (this.drawStars) {
  5734.      for (let i = 0; i < NightMode.config.NUM_STARS; i++) {
  5735.        this.canvasCtx.drawImage(
  5736.            Runner.origImageSprite, starSourceX, this.stars[i].sourceY,
  5737.            starSize, starSize, Math.round(this.stars[i].x), this.stars[i].y,
  5738.            NightMode.config.STAR_SIZE, NightMode.config.STAR_SIZE);
  5739.      }
  5740.    }
  5741.  
  5742.    // Moon.
  5743.    this.canvasCtx.drawImage(
  5744.        Runner.origImageSprite, moonSourceX, this.spritePos.y, moonSourceWidth,
  5745.        moonSourceHeight, Math.round(this.xPos), this.yPos, moonOutputWidth,
  5746.        NightMode.config.HEIGHT);
  5747.  
  5748.    this.canvasCtx.globalAlpha = 1;
  5749.    this.canvasCtx.restore();
  5750.  },
  5751.  
  5752.  // Do star placement.
  5753.  placeStars() {
  5754.    const segmentSize = Math.round(this.containerWidth /
  5755.        NightMode.config.NUM_STARS);
  5756.  
  5757.    for (let i = 0; i < NightMode.config.NUM_STARS; i++) {
  5758.      this.stars[i] = {};
  5759.      this.stars[i].x = getRandomNum(segmentSize * i, segmentSize * (i + 1));
  5760.      this.stars[i].y = getRandomNum(0, NightMode.config.STAR_MAX_Y);
  5761.  
  5762.      if (IS_HIDPI) {
  5763.        this.stars[i].sourceY =
  5764.            Runner.spriteDefinitionByType.original.HDPI.STAR.y +
  5765.            NightMode.config.STAR_SIZE * 2 * i;
  5766.      } else {
  5767.        this.stars[i].sourceY =
  5768.            Runner.spriteDefinitionByType.original.LDPI.STAR.y +
  5769.            NightMode.config.STAR_SIZE * i;
  5770.      }
  5771.    }
  5772.  },
  5773.  
  5774.  reset() {
  5775.    this.currentPhase = 0;
  5776.    this.opacity = 0;
  5777.    this.update(false);
  5778.  },
  5779.  
  5780. };
  5781.  
  5782.  
  5783. //******************************************************************************
  5784.  
  5785. /**
  5786. * Horizon Line.
  5787. * Consists of two connecting lines. Randomly assigns a flat / bumpy horizon.
  5788. * @param {HTMLCanvasElement} canvas
  5789. * @param {Object} lineConfig Configuration object.
  5790. * @constructor
  5791. */
  5792. function HorizonLine(canvas, lineConfig) {
  5793.  let sourceX = lineConfig.SOURCE_X;
  5794.  let sourceY = lineConfig.SOURCE_Y;
  5795.  
  5796.  if (IS_HIDPI) {
  5797.    sourceX *= 2;
  5798.    sourceY *= 2;
  5799.  }
  5800.  
  5801.  this.spritePos = {x: sourceX, y: sourceY};
  5802.  this.canvas = canvas;
  5803.  this.canvasCtx =
  5804.      /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
  5805.  this.sourceDimensions = {};
  5806.  this.dimensions = lineConfig;
  5807.  
  5808.  this.sourceXPos = [this.spritePos.x, this.spritePos.x +
  5809.      this.dimensions.WIDTH];
  5810.  this.xPos = [];
  5811.  this.yPos = 0;
  5812.  this.bumpThreshold = 0.5;
  5813.  
  5814.  this.setSourceDimensions(lineConfig);
  5815.  this.draw();
  5816. }
  5817.  
  5818.  
  5819. /**
  5820. * Horizon line dimensions.
  5821. * @enum {number}
  5822. */
  5823. HorizonLine.dimensions = {
  5824.  WIDTH: 600,
  5825.  HEIGHT: 12,
  5826.  YPOS: 127,
  5827. };
  5828.  
  5829.  
  5830. HorizonLine.prototype = {
  5831.  /**
  5832.   * Set the source dimensions of the horizon line.
  5833.   */
  5834.  setSourceDimensions(newDimensions) {
  5835.    for (const dimension in newDimensions) {
  5836.      if (dimension !== 'SOURCE_X' && dimension !== 'SOURCE_Y') {
  5837.        if (IS_HIDPI) {
  5838.          if (dimension !== 'YPOS') {
  5839.            this.sourceDimensions[dimension] = newDimensions[dimension] * 2;
  5840.          }
  5841.        } else {
  5842.          this.sourceDimensions[dimension] = newDimensions[dimension];
  5843.        }
  5844.        this.dimensions[dimension] = newDimensions[dimension];
  5845.      }
  5846.    }
  5847.  
  5848.    this.xPos = [0, newDimensions.WIDTH];
  5849.    this.yPos = newDimensions.YPOS;
  5850.  },
  5851.  
  5852.  /**
  5853.   * Return the crop x position of a type.
  5854.   */
  5855.  getRandomType() {
  5856.    return Math.random() > this.bumpThreshold ? this.dimensions.WIDTH : 0;
  5857.  },
  5858.  
  5859.  /**
  5860.   * Draw the horizon line.
  5861.   */
  5862.  draw() {
  5863.    this.canvasCtx.drawImage(Runner.imageSprite, this.sourceXPos[0],
  5864.        this.spritePos.y,
  5865.        this.sourceDimensions.WIDTH, this.sourceDimensions.HEIGHT,
  5866.        this.xPos[0], this.yPos,
  5867.        this.dimensions.WIDTH, this.dimensions.HEIGHT);
  5868.  
  5869.    this.canvasCtx.drawImage(Runner.imageSprite, this.sourceXPos[1],
  5870.        this.spritePos.y,
  5871.        this.sourceDimensions.WIDTH, this.sourceDimensions.HEIGHT,
  5872.        this.xPos[1], this.yPos,
  5873.        this.dimensions.WIDTH, this.dimensions.HEIGHT);
  5874.  },
  5875.  
  5876.  /**
  5877.   * Update the x position of an indivdual piece of the line.
  5878.   * @param {number} pos Line position.
  5879.   * @param {number} increment
  5880.   */
  5881.  updateXPos(pos, increment) {
  5882.    const line1 = pos;
  5883.    const line2 = pos === 0 ? 1 : 0;
  5884.  
  5885.    this.xPos[line1] -= increment;
  5886.    this.xPos[line2] = this.xPos[line1] + this.dimensions.WIDTH;
  5887.  
  5888.    if (this.xPos[line1] <= -this.dimensions.WIDTH) {
  5889.      this.xPos[line1] += this.dimensions.WIDTH * 2;
  5890.      this.xPos[line2] = this.xPos[line1] - this.dimensions.WIDTH;
  5891.      this.sourceXPos[line1] = this.getRandomType() + this.spritePos.x;
  5892.    }
  5893.  },
  5894.  
  5895.  /**
  5896.   * Update the horizon line.
  5897.   * @param {number} deltaTime
  5898.   * @param {number} speed
  5899.   */
  5900.  update(deltaTime, speed) {
  5901.    const increment = Math.floor(speed * (FPS / 1000) * deltaTime);
  5902.  
  5903.    if (this.xPos[0] <= 0) {
  5904.      this.updateXPos(0, increment);
  5905.    } else {
  5906.      this.updateXPos(1, increment);
  5907.    }
  5908.    this.draw();
  5909.  },
  5910.  
  5911.  /**
  5912.   * Reset horizon to the starting position.
  5913.   */
  5914.  reset() {
  5915.    this.xPos[0] = 0;
  5916.    this.xPos[1] = this.dimensions.WIDTH;
  5917.  },
  5918. };
  5919.  
  5920.  
  5921. //******************************************************************************
  5922.  
  5923. /**
  5924. * Horizon background class.
  5925. * @param {HTMLCanvasElement} canvas
  5926. * @param {Object} spritePos Sprite positioning.
  5927. * @param {Object} dimensions Canvas dimensions.
  5928. * @param {number} gapCoefficient
  5929. * @constructor
  5930. */
  5931. function Horizon(canvas, spritePos, dimensions, gapCoefficient) {
  5932.  this.canvas = canvas;
  5933.  this.canvasCtx =
  5934.      /** @type {CanvasRenderingContext2D} */ (this.canvas.getContext('2d'));
  5935.  this.config = Horizon.config;
  5936.  this.dimensions = dimensions;
  5937.  this.gapCoefficient = gapCoefficient;
  5938.  this.obstacles = [];
  5939.  this.obstacleHistory = [];
  5940.  this.horizonOffsets = [0, 0];
  5941.  this.cloudFrequency = this.config.CLOUD_FREQUENCY;
  5942.  this.spritePos = spritePos;
  5943.  this.nightMode = null;
  5944.  this.altGameModeActive = false;
  5945.  
  5946.  // Cloud
  5947.  this.clouds = [];
  5948.  this.cloudSpeed = this.config.BG_CLOUD_SPEED;
  5949.  
  5950.  // Background elements
  5951.  this.backgroundEls = [];
  5952.  this.lastEl = null;
  5953.  this.backgroundSpeed = this.config.BG_CLOUD_SPEED;
  5954.  
  5955.  // Horizon
  5956.  this.horizonLine = null;
  5957.  this.horizonLines = [];
  5958.  this.init();
  5959. }
  5960.  
  5961.  
  5962. /**
  5963. * Horizon config.
  5964. * @enum {number}
  5965. */
  5966. Horizon.config = {
  5967.  BG_CLOUD_SPEED: 0.2,
  5968.  BUMPY_THRESHOLD: .3,
  5969.  CLOUD_FREQUENCY: .5,
  5970.  HORIZON_HEIGHT: 16,
  5971.  MAX_CLOUDS: 6,
  5972. };
  5973.  
  5974.  
  5975. Horizon.prototype = {
  5976.  /**
  5977.   * Initialise the horizon. Just add the line and a cloud. No obstacles.
  5978.   */
  5979.  init() {
  5980.    Obstacle.types = Runner.spriteDefinitionByType.original.OBSTACLES;
  5981.    this.addCloud();
  5982.    // Multiple Horizon lines
  5983.    for (let i = 0; i < Runner.spriteDefinition.LINES.length; i++) {
  5984.      this.horizonLines.push(
  5985.          new HorizonLine(this.canvas, Runner.spriteDefinition.LINES[i]));
  5986.    }
  5987.  
  5988.    this.nightMode = new NightMode(this.canvas, this.spritePos.MOON,
  5989.        this.dimensions.WIDTH);
  5990.  },
  5991.  
  5992.  /**
  5993.   * Update obstacle definitions based on the speed of the game.
  5994.   */
  5995.  adjustObstacleSpeed: function() {
  5996.    for (let i = 0; i < Obstacle.types.length; i++) {
  5997.      if (Runner.slowDown) {
  5998.        Obstacle.types[i].multipleSpeed = Obstacle.types[i].multipleSpeed / 2;
  5999.        Obstacle.types[i].minGap *= 1.5;
  6000.        Obstacle.types[i].minSpeed = Obstacle.types[i].minSpeed / 2;
  6001.  
  6002.        // Convert variable y position obstacles to fixed.
  6003.        if (typeof (Obstacle.types[i].yPos) == 'object') {
  6004.          Obstacle.types[i].yPos = Obstacle.types[i].yPos[0];
  6005.          Obstacle.types[i].yPosMobile = Obstacle.types[i].yPos[0];
  6006.        }
  6007.      }
  6008.    }
  6009.  },
  6010.  
  6011.  /**
  6012.   * Update sprites to correspond to change in sprite sheet.
  6013.   * @param {number} spritePos
  6014.   */
  6015.  enableAltGameMode: function(spritePos) {
  6016.    // Clear existing horizon objects.
  6017.    this.clouds = [];
  6018.    this.backgroundEls = [];
  6019.  
  6020.    this.altGameModeActive = true;
  6021.    this.spritePos = spritePos;
  6022.  
  6023.    Obstacle.types = Runner.spriteDefinition.OBSTACLES;
  6024.    this.adjustObstacleSpeed();
  6025.  
  6026.    Obstacle.MAX_GAP_COEFFICIENT = Runner.spriteDefinition.MAX_GAP_COEFFICIENT;
  6027.    Obstacle.MAX_OBSTACLE_LENGTH = Runner.spriteDefinition.MAX_OBSTACLE_LENGTH;
  6028.  
  6029.    BackgroundEl.config = Runner.spriteDefinition.BACKGROUND_EL_CONFIG;
  6030.  
  6031.    this.horizonLines = [];
  6032.    for (let i = 0; i < Runner.spriteDefinition.LINES.length; i++) {
  6033.      this.horizonLines.push(
  6034.          new HorizonLine(this.canvas, Runner.spriteDefinition.LINES[i]));
  6035.    }
  6036.    this.reset();
  6037.  },
  6038.  
  6039.  /**
  6040.   * @param {number} deltaTime
  6041.   * @param {number} currentSpeed
  6042.   * @param {boolean} updateObstacles Used as an override to prevent
  6043.   *     the obstacles from being updated / added. This happens in the
  6044.   *     ease in section.
  6045.   * @param {boolean} showNightMode Night mode activated.
  6046.   */
  6047.  update(deltaTime, currentSpeed, updateObstacles, showNightMode) {
  6048.    this.runningTime += deltaTime;
  6049.  
  6050.    if (this.altGameModeActive) {
  6051.      this.updateBackgroundEls(deltaTime, currentSpeed);
  6052.    }
  6053.  
  6054.    for (let i = 0; i < this.horizonLines.length; i++) {
  6055.      this.horizonLines[i].update(deltaTime, currentSpeed);
  6056.    }
  6057.  
  6058.    if (!this.altGameModeActive || Runner.spriteDefinition.HAS_CLOUDS) {
  6059.      this.nightMode.update(showNightMode);
  6060.      this.updateClouds(deltaTime, currentSpeed);
  6061.    }
  6062.  
  6063.    if (updateObstacles) {
  6064.      this.updateObstacles(deltaTime, currentSpeed);
  6065.    }
  6066.  },
  6067.  
  6068.  /**
  6069.   * Update background element positions. Also handles creating new elements.
  6070.   * @param {number} elSpeed
  6071.   * @param {Array<Object>} bgElArray
  6072.   * @param {number} maxBgEl
  6073.   * @param {Function} bgElAddFunction
  6074.   * @param {number} frequency
  6075.   */
  6076.  updateBackgroundEl(elSpeed, bgElArray, maxBgEl, bgElAddFunction, frequency) {
  6077.    const numElements = bgElArray.length;
  6078.  
  6079.    if (numElements) {
  6080.      for (let i = numElements - 1; i >= 0; i--) {
  6081.        bgElArray[i].update(elSpeed);
  6082.      }
  6083.  
  6084.      const lastEl = bgElArray[numElements - 1];
  6085.  
  6086.      // Check for adding a new element.
  6087.      if (numElements < maxBgEl &&
  6088.          (this.dimensions.WIDTH - lastEl.xPos) > lastEl.gap &&
  6089.          frequency > Math.random()) {
  6090.        bgElAddFunction();
  6091.      }
  6092.    } else {
  6093.      bgElAddFunction();
  6094.    }
  6095.  },
  6096.  
  6097.  /**
  6098.   * Update the cloud positions.
  6099.   * @param {number} deltaTime
  6100.   * @param {number} speed
  6101.   */
  6102.  updateClouds(deltaTime, speed) {
  6103.    const elSpeed = this.cloudSpeed / 1000 * deltaTime * speed;
  6104.    this.updateBackgroundEl(
  6105.        elSpeed, this.clouds, this.config.MAX_CLOUDS, this.addCloud.bind(this),
  6106.        this.cloudFrequency);
  6107.  
  6108.    // Remove expired elements.
  6109.    this.clouds = this.clouds.filter((obj) => !obj.remove);
  6110.  },
  6111.  
  6112.  /**
  6113.   * Update the background element positions.
  6114.   * @param {number} deltaTime
  6115.   * @param {number} speed
  6116.   */
  6117.  updateBackgroundEls(deltaTime, speed) {
  6118.    this.updateBackgroundEl(
  6119.        deltaTime, this.backgroundEls, BackgroundEl.config.MAX_BG_ELS,
  6120.        this.addBackgroundEl.bind(this), this.cloudFrequency);
  6121.  
  6122.    // Remove expired elements.
  6123.    this.backgroundEls = this.backgroundEls.filter((obj) => !obj.remove);
  6124.  },
  6125.  
  6126.  /**
  6127.   * Update the obstacle positions.
  6128.   * @param {number} deltaTime
  6129.   * @param {number} currentSpeed
  6130.   */
  6131.  updateObstacles(deltaTime, currentSpeed) {
  6132.    const updatedObstacles = this.obstacles.slice(0);
  6133.  
  6134.    for (let i = 0; i < this.obstacles.length; i++) {
  6135.      const obstacle = this.obstacles[i];
  6136.      obstacle.update(deltaTime, currentSpeed);
  6137.  
  6138.      // Clean up existing obstacles.
  6139.      if (obstacle.remove) {
  6140.        updatedObstacles.shift();
  6141.      }
  6142.    }
  6143.    this.obstacles = updatedObstacles;
  6144.  
  6145.    if (this.obstacles.length > 0) {
  6146.      const lastObstacle = this.obstacles[this.obstacles.length - 1];
  6147.  
  6148.      if (lastObstacle && !lastObstacle.followingObstacleCreated &&
  6149.          lastObstacle.isVisible() &&
  6150.          (lastObstacle.xPos + lastObstacle.width + lastObstacle.gap) <
  6151.          this.dimensions.WIDTH) {
  6152.        this.addNewObstacle(currentSpeed);
  6153.        lastObstacle.followingObstacleCreated = true;
  6154.      }
  6155.    } else {
  6156.      // Create new obstacles.
  6157.      this.addNewObstacle(currentSpeed);
  6158.    }
  6159.  },
  6160.  
  6161.  removeFirstObstacle() {
  6162.    this.obstacles.shift();
  6163.  },
  6164.  
  6165.  /**
  6166.   * Add a new obstacle.
  6167.   * @param {number} currentSpeed
  6168.   */
  6169.  addNewObstacle(currentSpeed) {
  6170.    const obstacleCount =
  6171.        Obstacle.types[Obstacle.types.length - 1].type != 'COLLECTABLE' ||
  6172.            (Runner.isAltGameModeEnabled() && !this.altGameModeActive ||
  6173.             this.altGameModeActive) ?
  6174.        Obstacle.types.length - 1 :
  6175.        Obstacle.types.length - 2;
  6176.    const obstacleTypeIndex =
  6177.        obstacleCount > 0 ? getRandomNum(0, obstacleCount) : 0;
  6178.    const obstacleType = Obstacle.types[obstacleTypeIndex];
  6179.  
  6180.    // Check for multiples of the same type of obstacle.
  6181.    // Also check obstacle is available at current speed.
  6182.    if ((obstacleCount > 0 && this.duplicateObstacleCheck(obstacleType.type)) ||
  6183.        currentSpeed < obstacleType.minSpeed) {
  6184.      this.addNewObstacle(currentSpeed);
  6185.    } else {
  6186.      const obstacleSpritePos = this.spritePos[obstacleType.type];
  6187.  
  6188.      this.obstacles.push(new Obstacle(
  6189.          this.canvasCtx, obstacleType, obstacleSpritePos, this.dimensions,
  6190.          this.gapCoefficient, currentSpeed, obstacleType.width,
  6191.          this.altGameModeActive));
  6192.  
  6193.      this.obstacleHistory.unshift(obstacleType.type);
  6194.  
  6195.      if (this.obstacleHistory.length > 1) {
  6196.        this.obstacleHistory.splice(Runner.config.MAX_OBSTACLE_DUPLICATION);
  6197.      }
  6198.    }
  6199.  },
  6200.  
  6201.  /**
  6202.   * Returns whether the previous two obstacles are the same as the next one.
  6203.   * Maximum duplication is set in config value MAX_OBSTACLE_DUPLICATION.
  6204.   * @return {boolean}
  6205.   */
  6206.  duplicateObstacleCheck(nextObstacleType) {
  6207.    let duplicateCount = 0;
  6208.  
  6209.    for (let i = 0; i < this.obstacleHistory.length; i++) {
  6210.      duplicateCount =
  6211.          this.obstacleHistory[i] === nextObstacleType ? duplicateCount + 1 : 0;
  6212.    }
  6213.    return duplicateCount >= Runner.config.MAX_OBSTACLE_DUPLICATION;
  6214.  },
  6215.  
  6216.  /**
  6217.   * Reset the horizon layer.
  6218.   * Remove existing obstacles and reposition the horizon line.
  6219.   */
  6220.  reset() {
  6221.    this.obstacles = [];
  6222.    for (let l = 0; l < this.horizonLines.length; l++) {
  6223.      this.horizonLines[l].reset();
  6224.    }
  6225.  
  6226.    this.nightMode.reset();
  6227.  },
  6228.  
  6229.  /**
  6230.   * Update the canvas width and scaling.
  6231.   * @param {number} width Canvas width.
  6232.   * @param {number} height Canvas height.
  6233.   */
  6234.  resize(width, height) {
  6235.    this.canvas.width = width;
  6236.    this.canvas.height = height;
  6237.  },
  6238.  
  6239.  /**
  6240.   * Add a new cloud to the horizon.
  6241.   */
  6242.  addCloud() {
  6243.    this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD,
  6244.        this.dimensions.WIDTH));
  6245.  },
  6246.  
  6247.  /**
  6248.   * Add a random background element to the horizon.
  6249.   */
  6250.  addBackgroundEl() {
  6251.    const backgroundElTypes =
  6252.        Object.keys(Runner.spriteDefinition.BACKGROUND_EL);
  6253.  
  6254.    if (backgroundElTypes.length > 0) {
  6255.      let index = getRandomNum(0, backgroundElTypes.length - 1);
  6256.      let type = backgroundElTypes[index];
  6257.  
  6258.      // Add variation if available.
  6259.      while (type == this.lastEl && backgroundElTypes.length > 1) {
  6260.        index = getRandomNum(0, backgroundElTypes.length - 1);
  6261.        type = backgroundElTypes[index];
  6262.      }
  6263.  
  6264.      this.lastEl = type;
  6265.      this.backgroundEls.push(new BackgroundEl(
  6266.          this.canvas, this.spritePos.BACKGROUND_EL, this.dimensions.WIDTH,
  6267.          type));
  6268.    }
  6269.  },
  6270. };
  6271. </script>
  6272.  <script>// Copyright 2021 The Chromium Authors
  6273. // Use of this source code is governed by a BSD-style license that can be
  6274. // found in the LICENSE file.
  6275.  
  6276. /* @const
  6277. * Add matching sprite definition and config to Runner.spriteDefinitionByType.
  6278. */
  6279. const GAME_TYPE = [];
  6280.  
  6281. /**
  6282. * Obstacle definitions.
  6283. * minGap: minimum pixel space between obstacles.
  6284. * multipleSpeed: Speed at which multiples are allowed.
  6285. * speedOffset: speed faster / slower than the horizon.
  6286. * minSpeed: Minimum speed which the obstacle can make an appearance.
  6287. *
  6288. * @typedef {{
  6289. *   type: string,
  6290. *   width: number,
  6291. *   height: number,
  6292. *   yPos: number,
  6293. *   multipleSpeed: number,
  6294. *   minGap: number,
  6295. *   minSpeed: number,
  6296. *   collisionBoxes: Array<CollisionBox>,
  6297. * }}
  6298. */
  6299. let ObstacleType;
  6300.  
  6301. /**
  6302. * T-Rex runner sprite definitions.
  6303. */
  6304. Runner.spriteDefinitionByType = {
  6305.  original: {
  6306.    LDPI: {
  6307.      BACKGROUND_EL: {x: 86, y: 2},
  6308.      CACTUS_LARGE: {x: 332, y: 2},
  6309.      CACTUS_SMALL: {x: 228, y: 2},
  6310.      OBSTACLE_2: {x: 332, y: 2},
  6311.      OBSTACLE: {x: 228, y: 2},
  6312.      CLOUD: {x: 86, y: 2},
  6313.      HORIZON: {x: 2, y: 54},
  6314.      MOON: {x: 484, y: 2},
  6315.      PTERODACTYL: {x: 134, y: 2},
  6316.      RESTART: {x: 2, y: 68},
  6317.      TEXT_SPRITE: {x: 655, y: 2},
  6318.      TREX: {x: 848, y: 2},
  6319.      STAR: {x: 645, y: 2},
  6320.      COLLECTABLE: {x: 2, y: 2},
  6321.      ALT_GAME_END: {x: 121, y: 2},
  6322.    },
  6323.    HDPI: {
  6324.      BACKGROUND_EL: {x: 166, y: 2},
  6325.      CACTUS_LARGE: {x: 652, y: 2},
  6326.      CACTUS_SMALL: {x: 446, y: 2},
  6327.      OBSTACLE_2: {x: 652, y: 2},
  6328.      OBSTACLE: {x: 446, y: 2},
  6329.      CLOUD: {x: 166, y: 2},
  6330.      HORIZON: {x: 2, y: 104},
  6331.      MOON: {x: 954, y: 2},
  6332.      PTERODACTYL: {x: 260, y: 2},
  6333.      RESTART: {x: 2, y: 130},
  6334.      TEXT_SPRITE: {x: 1294, y: 2},
  6335.      TREX: {x: 1678, y: 2},
  6336.      STAR: {x: 1276, y: 2},
  6337.      COLLECTABLE: {x: 4, y: 4},
  6338.      ALT_GAME_END: {x: 242, y: 4},
  6339.    },
  6340.    MAX_GAP_COEFFICIENT: 1.5,
  6341.    MAX_OBSTACLE_LENGTH: 3,
  6342.    HAS_CLOUDS: 1,
  6343.    BOTTOM_PAD: 10,
  6344.    TREX: {
  6345.      WAITING_1: {x: 44, w: 44, h: 47, xOffset: 0},
  6346.      WAITING_2: {x: 0, w: 44, h: 47, xOffset: 0},
  6347.      RUNNING_1: {x: 88, w: 44, h: 47, xOffset: 0},
  6348.      RUNNING_2: {x: 132, w: 44, h: 47, xOffset: 0},
  6349.      JUMPING: {x: 0, w: 44, h: 47, xOffset: 0},
  6350.      CRASHED: {x: 220, w: 44, h: 47, xOffset: 0},
  6351.      COLLISION_BOXES: [
  6352.        new CollisionBox(22, 0, 17, 16),
  6353.        new CollisionBox(1, 18, 30, 9),
  6354.        new CollisionBox(10, 35, 14, 8),
  6355.        new CollisionBox(1, 24, 29, 5),
  6356.        new CollisionBox(5, 30, 21, 4),
  6357.        new CollisionBox(9, 34, 15, 4),
  6358.      ],
  6359.    },
  6360.    /** @type {Array<ObstacleType>} */
  6361.    OBSTACLES: [
  6362.      {
  6363.        type: 'CACTUS_SMALL',
  6364.        width: 17,
  6365.        height: 35,
  6366.        yPos: 105,
  6367.        multipleSpeed: 4,
  6368.        minGap: 120,
  6369.        minSpeed: 0,
  6370.        collisionBoxes: [
  6371.          new CollisionBox(0, 7, 5, 27),
  6372.          new CollisionBox(4, 0, 6, 34),
  6373.          new CollisionBox(10, 4, 7, 14),
  6374.        ],
  6375.      },
  6376.      {
  6377.        type: 'CACTUS_LARGE',
  6378.        width: 25,
  6379.        height: 50,
  6380.        yPos: 90,
  6381.        multipleSpeed: 7,
  6382.        minGap: 120,
  6383.        minSpeed: 0,
  6384.        collisionBoxes: [
  6385.          new CollisionBox(0, 12, 7, 38),
  6386.          new CollisionBox(8, 0, 7, 49),
  6387.          new CollisionBox(13, 10, 10, 38),
  6388.        ],
  6389.      },
  6390.      {
  6391.        type: 'PTERODACTYL',
  6392.        width: 46,
  6393.        height: 40,
  6394.        yPos: [100, 75, 50],    // Variable height.
  6395.        yPosMobile: [100, 50],  // Variable height mobile.
  6396.        multipleSpeed: 999,
  6397.        minSpeed: 8.5,
  6398.        minGap: 150,
  6399.        collisionBoxes: [
  6400.          new CollisionBox(15, 15, 16, 5),
  6401.          new CollisionBox(18, 21, 24, 6),
  6402.          new CollisionBox(2, 14, 4, 3),
  6403.          new CollisionBox(6, 10, 4, 7),
  6404.          new CollisionBox(10, 8, 6, 9),
  6405.        ],
  6406.        numFrames: 2,
  6407.        frameRate: 1000 / 6,
  6408.        speedOffset: .8,
  6409.      },
  6410.    ],
  6411.    BACKGROUND_EL: {
  6412.      'CLOUD': {
  6413.        HEIGHT: 14,
  6414.        MAX_CLOUD_GAP: 400,
  6415.        MAX_SKY_LEVEL: 30,
  6416.        MIN_CLOUD_GAP: 100,
  6417.        MIN_SKY_LEVEL: 71,
  6418.        OFFSET: 4,
  6419.        WIDTH: 46,
  6420.        X_POS: 1,
  6421.        Y_POS: 120,
  6422.      },
  6423.    },
  6424.    BACKGROUND_EL_CONFIG: {
  6425.      MAX_BG_ELS: 1,
  6426.      MAX_GAP: 400,
  6427.      MIN_GAP: 100,
  6428.      POS: 0,
  6429.      SPEED: 0.5,
  6430.      Y_POS: 125,
  6431.    },
  6432.    LINES: [
  6433.      {SOURCE_X: 2, SOURCE_Y: 52, WIDTH: 600, HEIGHT: 12, YPOS: 127},
  6434.    ],
  6435.  },
  6436. };
  6437. </script>
  6438.  
  6439. </head>
  6440. <body id="t" class="neterror" style="font-family: &#39;Segoe UI&#39;,Arial,&#39;Microsoft Yahei&#39;,sans-serif; font-size: 75%" jstcache="0">
  6441.  <div id="main-frame-error" class="interstitial-wrapper" jstcache="0">
  6442.    <div id="main-content" jstcache="0">
  6443.      <div class="icon icon-generic" jstcache="0"></div>
  6444.      <div id="main-message" jstcache="0">
  6445.        <h1 jstcache="0">
  6446.          <span jsselect="heading" jsvalues=".innerHTML:msg" jstcache="9">无法访问此网站</span>
  6447.          <a id="error-information-button" class="hidden" onclick="toggleErrorInformationPopup();" jstcache="0"></a>
  6448.        </h1>
  6449.        <p jsselect="summary" jsvalues=".innerHTML:msg" jstcache="1">检查 <span jscontent="hostName" jstcache="22">网址</span> 中是否有拼写错误。</p>
  6450.        <!--The suggestion list and error code are normally presented inline,
  6451.          in which case error-information-popup-* divs have no effect. When
  6452.          error-information-popup-container has the use-popup-container class, this
  6453.          information is provided in a popup instead.-->
  6454.        <div id="error-information-popup-container" jstcache="0">
  6455.          <div id="error-information-popup" jstcache="0">
  6456.            <div id="error-information-popup-box" jstcache="0">
  6457.              <div id="error-information-popup-content" jstcache="0">
  6458.                <div id="suggestions-list" style="" jsdisplay="(suggestionsSummaryList &amp;&amp; suggestionsSummaryList.length)" jstcache="16">
  6459.                  <p jsvalues=".innerHTML:suggestionsSummaryListHeader" jstcache="18"></p>
  6460.                  <ul jsvalues=".className:suggestionsSummaryList.length == 1 ? &#39;single-suggestion&#39; : &#39;&#39;" jstcache="19" class="single-suggestion">
  6461.                    <li jsselect="suggestionsSummaryList" jsvalues=".innerHTML:summary" jstcache="21" jsinstance="*0">如果拼写无误,请<a href="javascript:diagnoseErrors()" id="diagnose-link" jstcache="0">尝试运行 Windows 网络诊断</a>。</li>
  6462.                  </ul>
  6463.                </div>
  6464.                <div class="error-code" jscontent="errorCode" jstcache="17">DNS_PROBE_FINISHED_NXDOMAIN</div>
  6465.                <p id="error-information-popup-close" jstcache="0">
  6466.                  <a class="link-button" jscontent="closeDescriptionPopup" onclick="toggleErrorInformationPopup();" jstcache="20">null</a>
  6467.                </p>
  6468.              </div>
  6469.            </div>
  6470.          </div>
  6471.        </div>
  6472.        <div id="download-links-wrapper" class="hidden" jstcache="0">
  6473.          <div id="download-link-wrapper" jstcache="0">
  6474.            <a id="download-link" class="link-button" onclick="downloadButtonClick()" jsselect="downloadButton" jscontent="msg" jsvalues=".disabledText:disabledMsg" jstcache="6" style="display: none;">
  6475.            </a>
  6476.          </div>
  6477.          <div id="download-link-clicked-wrapper" class="hidden" jstcache="0">
  6478.            <div id="download-link-clicked" class="link-button" jsselect="downloadButton" jscontent="disabledMsg" jstcache="11" style="display: none;">
  6479.            </div>
  6480.          </div>
  6481.        </div>
  6482.        <div id="save-page-for-later-button" class="hidden" jstcache="0">
  6483.          <a class="link-button" onclick="savePageLaterClick()" jsselect="savePageLater" jscontent="savePageMsg" jstcache="10" style="display: none;">
  6484.          </a>
  6485.        </div>
  6486.        <div id="cancel-save-page-button" class="hidden" onclick="cancelSavePageClick()" jsselect="savePageLater" jsvalues=".innerHTML:cancelMsg" jstcache="4" style="display: none;">
  6487.        </div>
  6488.        <div id="offline-content-list" class="list-hidden" hidden="" jstcache="0">
  6489.          <div id="offline-content-list-visibility-card" onclick="toggleOfflineContentListVisibility(true)" jstcache="0">
  6490.            <div id="offline-content-list-title" jsselect="offlineContentList" jscontent="title" jstcache="12" style="display: none;">
  6491.            </div>
  6492.            <div jstcache="0">
  6493.              <div id="offline-content-list-show-text" jsselect="offlineContentList" jscontent="showText" jstcache="14" style="display: none;">
  6494.              </div>
  6495.              <div id="offline-content-list-hide-text" jsselect="offlineContentList" jscontent="hideText" jstcache="15" style="display: none;">
  6496.              </div>
  6497.            </div>
  6498.          </div>
  6499.          <div id="offline-content-suggestions" jstcache="0"></div>
  6500.          <div id="offline-content-list-action" jstcache="0">
  6501.            <a class="link-button" onclick="launchDownloadsPage()" jsselect="offlineContentList" jscontent="actionText" jstcache="13" style="display: none;">
  6502.            </a>
  6503.          </div>
  6504.        </div>
  6505.      </div>
  6506.    </div>
  6507.    <div id="buttons" class="nav-wrapper suggested-left" jstcache="0">
  6508.      <div id="control-buttons" jstcache="0">
  6509.        <button id="reload-button" class="blue-button text-button" onclick="reloadButtonClick(this.url);" jsselect="reloadButton" jsvalues=".url:reloadUrl" jscontent="msg" jstcache="5">重新加载</button>
  6510.        <button id="download-button" class="blue-button text-button" onclick="downloadButtonClick()" jsselect="downloadButton" jscontent="msg" jsvalues=".disabledText:disabledMsg" jstcache="6" style="display: none;">
  6511.        </button>
  6512.      </div>
  6513.      <button id="details-button" class="secondary-button text-button small-link" onclick="detailsButtonClick(); toggleHelpBox()" jscontent="details" jsdisplay="(suggestionsDetails &amp;&amp; suggestionsDetails.length &gt; 0) || diagnose" jsvalues=".detailsText:details; .hideDetailsText:hideDetails;" jstcache="2" style="display: none;"></button>
  6514.    </div>
  6515.    <div id="details" class="hidden" jstcache="0">
  6516.      <div class="suggestions" jsselect="suggestionsDetails" jstcache="3" jsinstance="*0" style="display: none;">
  6517.        <div class="suggestion-header" jsvalues=".innerHTML:header" jstcache="7"></div>
  6518.        <div class="suggestion-body" jsvalues=".innerHTML:body" jstcache="8"></div>
  6519.      </div>
  6520.    </div>
  6521.  </div>
  6522.  <div id="sub-frame-error" jstcache="0">
  6523.    <!-- Show details when hovering over the icon, in case the details are
  6524.         hidden because they're too large. -->
  6525.    <div class="icon" jstcache="0"></div>
  6526.    <div id="sub-frame-error-details" jsselect="summary" jsvalues=".innerHTML:msg" jstcache="1">检查 <span jscontent="hostName" jstcache="22">网址</span> 中是否有拼写错误。</div>
  6527.  </div>
  6528.  
  6529.  <div id="offline-resources" jstcache="0">
  6530.    <img id="offline-resources-1x" src="data:image/png;base64,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" jstcache="0">
  6531.    <img id="offline-resources-2x" src="data:image/png;base64,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" jstcache="0">
  6532.    <template id="audio-resources" jstcache="0"></template>
  6533.  </div>
  6534.  
  6535.  
  6536. <script jstcache="0">(function(){function l(a,b,c){return Function.prototype.call.apply(Array.prototype.slice,arguments)}function m(a,b,c){var e=l(arguments,2);return function(){return b.apply(a,e)}}function n(a,b){var c=new p(b);for(c.h=[a];c.h.length;){var e=c,d=c.h.shift();e.i(d);for(d=d.firstChild;d;d=d.nextSibling)1==d.nodeType&&e.h.push(d)}}function p(a){this.i=a}function q(a){a.style.display=""}function r(a){a.style.display="none"};var t=/\s*;\s*/;function u(a,b){this.l.apply(this,arguments)}u.prototype.l=function(a,b){this.a||(this.a={});if(b){var c=this.a,e=b.a;for(d in e)c[d]=e[d]}else{var d=this.a;e=v;for(c in e)d[c]=e[c]}this.a.$this=a;this.a.$context=this;this.f="undefined"!=typeof a&&null!=a?a:"";b||(this.a.$top=this.f)};var v={$default:null},w=[];function x(a){for(var b in a.a)delete a.a[b];a.f=null;w.push(a)}function y(a,b,c){try{return b.call(c,a.a,a.f)}catch(e){return v.$default}}
  6537. u.prototype.clone=function(a,b,c){if(0<w.length){var e=w.pop();u.call(e,a,this);a=e}else a=new u(a,this);a.a.$index=b;a.a.$count=c;return a};var z;window.trustedTypes&&(z=trustedTypes.createPolicy("jstemplate",{createScript:function(a){return a}}));var A={};function B(a){if(!A[a])try{var b="(function(a_, b_) { with (a_) with (b_) return "+a+" })",c=window.trustedTypes?z.createScript(b):b;A[a]=window.eval(c)}catch(e){}return A[a]}
  6538. function E(a){var b=[];a=a.split(t);for(var c=0,e=a.length;c<e;++c){var d=a[c].indexOf(":");if(!(0>d)){var g=a[c].substr(0,d).replace(/^\s+/,"").replace(/\s+$/,"");d=B(a[c].substr(d+1));b.push(g,d)}}return b};function F(){}var G=0,H={0:{}},I={},J={},K=[];function L(a){a.__jstcache||n(a,function(b){M(b)})}var N=[["jsselect",B],["jsdisplay",B],["jsvalues",E],["jsvars",E],["jseval",function(a){var b=[];a=a.split(t);for(var c=0,e=a.length;c<e;++c)if(a[c]){var d=B(a[c]);b.push(d)}return b}],["transclude",function(a){return a}],["jscontent",B],["jsskip",B]];
  6539. function M(a){if(a.__jstcache)return a.__jstcache;var b=a.getAttribute("jstcache");if(null!=b)return a.__jstcache=H[b];b=K.length=0;for(var c=N.length;b<c;++b){var e=N[b][0],d=a.getAttribute(e);J[e]=d;null!=d&&K.push(e+"="+d)}if(0==K.length)return a.setAttribute("jstcache","0"),a.__jstcache=H[0];var g=K.join("&");if(b=I[g])return a.setAttribute("jstcache",b),a.__jstcache=H[b];var h={};b=0;for(c=N.length;b<c;++b){d=N[b];e=d[0];var f=d[1];d=J[e];null!=d&&(h[e]=f(d))}b=""+ ++G;a.setAttribute("jstcache",
  6540. b);H[b]=h;I[g]=b;return a.__jstcache=h}function P(a,b){a.j.push(b);a.o.push(0)}function Q(a){return a.c.length?a.c.pop():[]}
  6541. F.prototype.g=function(a,b){var c=R(b),e=c.transclude;if(e)(c=S(e))?(b.parentNode.replaceChild(c,b),e=Q(this),e.push(this.g,a,c),P(this,e)):b.parentNode.removeChild(b);else if(c=c.jsselect){c=y(a,c,b);var d=b.getAttribute("jsinstance");var g=!1;d&&("*"==d.charAt(0)?(d=parseInt(d.substr(1),10),g=!0):d=parseInt(d,10));var h=null!=c&&"object"==typeof c&&"number"==typeof c.length;e=h?c.length:1;var f=h&&0==e;if(h)if(f)d?b.parentNode.removeChild(b):(b.setAttribute("jsinstance","*0"),r(b));else if(q(b),
  6542. null===d||""===d||g&&d<e-1){g=Q(this);d=d||0;for(h=e-1;d<h;++d){var k=b.cloneNode(!0);b.parentNode.insertBefore(k,b);T(k,c,d);f=a.clone(c[d],d,e);g.push(this.b,f,k,x,f,null)}T(b,c,d);f=a.clone(c[d],d,e);g.push(this.b,f,b,x,f,null);P(this,g)}else d<e?(g=c[d],T(b,c,d),f=a.clone(g,d,e),g=Q(this),g.push(this.b,f,b,x,f,null),P(this,g)):b.parentNode.removeChild(b);else null==c?r(b):(q(b),f=a.clone(c,0,1),g=Q(this),g.push(this.b,f,b,x,f,null),P(this,g))}else this.b(a,b)};
  6543. F.prototype.b=function(a,b){var c=R(b),e=c.jsdisplay;if(e){if(!y(a,e,b)){r(b);return}q(b)}if(e=c.jsvars)for(var d=0,g=e.length;d<g;d+=2){var h=e[d],f=y(a,e[d+1],b);a.a[h]=f}if(e=c.jsvalues)for(d=0,g=e.length;d<g;d+=2)if(f=e[d],h=y(a,e[d+1],b),"$"==f.charAt(0))a.a[f]=h;else if("."==f.charAt(0)){f=f.substr(1).split(".");for(var k=b,O=f.length,C=0,U=O-1;C<U;++C){var D=f[C];k[D]||(k[D]={});k=k[D]}k[f[O-1]]=h}else f&&("boolean"==typeof h?h?b.setAttribute(f,f):b.removeAttribute(f):b.setAttribute(f,""+h));
  6544. if(e=c.jseval)for(d=0,g=e.length;d<g;++d)y(a,e[d],b);e=c.jsskip;if(!e||!y(a,e,b))if(c=c.jscontent){if(c=""+y(a,c,b),b.innerHTML!=c){for(;b.firstChild;)e=b.firstChild,e.parentNode.removeChild(e);b.appendChild(this.m.createTextNode(c))}}else{c=Q(this);for(e=b.firstChild;e;e=e.nextSibling)1==e.nodeType&&c.push(this.g,a,e);c.length&&P(this,c)}};function R(a){if(a.__jstcache)return a.__jstcache;var b=a.getAttribute("jstcache");return b?a.__jstcache=H[b]:M(a)}
  6545. function S(a,b){var c=document;if(b){var e=c.getElementById(a);if(!e){e=b();var d=c.getElementById("jsts");d||(d=c.createElement("div"),d.id="jsts",r(d),d.style.position="absolute",c.body.appendChild(d));var g=c.createElement("div");d.appendChild(g);g.innerHTML=e;e=c.getElementById(a)}c=e}else c=c.getElementById(a);return c?(L(c),c=c.cloneNode(!0),c.removeAttribute("id"),c):null}function T(a,b,c){c==b.length-1?a.setAttribute("jsinstance","*"+c):a.setAttribute("jsinstance",""+c)};window.jstGetTemplate=S;window.JsEvalContext=u;window.jstProcess=function(a,b){var c=new F;L(b);c.m=b?9==b.nodeType?b:b.ownerDocument||document:document;var e=m(c,c.g,a,b),d=c.j=[],g=c.o=[];c.c=[];e();for(var h,f,k;d.length;)h=d[d.length-1],e=g[g.length-1],e>=h.length?(e=c,f=d.pop(),f.length=0,e.c.push(f),g.pop()):(f=h[e++],k=h[e++],h=h[e++],g[g.length-1]=e,f.call(c,k,h))};
  6546. })()</script><script jstcache="0">"use strict";
  6547. // Copyright 2012 The Chromium Authors
  6548. // Use of this source code is governed by a BSD-style license that can be
  6549. // found in the LICENSE file.
  6550. /**
  6551. * @fileoverview
  6552. * NOTE: This file is deprecated, and provides only the minimal LoadTimeData
  6553. * functions for places in the code still not using JS modules. Use
  6554. * load_time_data.ts in all new code.
  6555. *
  6556. * This file defines a singleton which provides access to all data
  6557. * that is available as soon as the page's resources are loaded (before DOM
  6558. * content has finished loading). This data includes both localized strings and
  6559. * any data that is important to have ready from a very early stage (e.g. things
  6560. * that must be displayed right away).
  6561. *
  6562. * Note that loadTimeData is not guaranteed to be consistent between page
  6563. * refreshes (https://crbug.com/740629) and should not contain values that might
  6564. * change if the page is re-opened later.
  6565. */
  6566. /** @type {!LoadTimeData} */
  6567. // eslint-disable-next-line no-var
  6568. var loadTimeData;
  6569. class LoadTimeData {
  6570.    constructor() {
  6571.        /** @type {?Object} */
  6572.        this.data_ = null;
  6573.    }
  6574.    /**
  6575.     * Sets the backing object.
  6576.     *
  6577.     * Note that there is no getter for |data_| to discourage abuse of the form:
  6578.     *
  6579.     *     var value = loadTimeData.data()['key'];
  6580.     *
  6581.     * @param {Object} value The de-serialized page data.
  6582.     */
  6583.    set data(value) {
  6584.        expect(!this.data_, 'Re-setting data.');
  6585.        this.data_ = value;
  6586.    }
  6587.    /**
  6588.     * @param {string} id An ID of a value that might exist.
  6589.     * @return {boolean} True if |id| is a key in the dictionary.
  6590.     */
  6591.    valueExists(id) {
  6592.        return id in this.data_;
  6593.    }
  6594.    /**
  6595.     * Fetches a value, expecting that it exists.
  6596.     * @param {string} id The key that identifies the desired value.
  6597.     * @return {*} The corresponding value.
  6598.     */
  6599.    getValue(id) {
  6600.        expect(this.data_, 'No data. Did you remember to include strings.js?');
  6601.        const value = this.data_[id];
  6602.        expect(typeof value !== 'undefined', 'Could not find value for ' + id);
  6603.        return value;
  6604.    }
  6605.    /**
  6606.     * As above, but also makes sure that the value is a string.
  6607.     * @param {string} id The key that identifies the desired string.
  6608.     * @return {string} The corresponding string value.
  6609.     */
  6610.    getString(id) {
  6611.        const value = this.getValue(id);
  6612.        expectIsType(id, value, 'string');
  6613.        return /** @type {string} */ (value);
  6614.    }
  6615.    /**
  6616.     * Returns a formatted localized string where $1 to $9 are replaced by the
  6617.     * second to the tenth argument.
  6618.     * @param {string} id The ID of the string we want.
  6619.     * @param {...(string|number)} var_args The extra values to include in the
  6620.     *     formatted output.
  6621.     * @return {string} The formatted string.
  6622.     */
  6623.    getStringF(id, var_args) {
  6624.        const value = this.getString(id);
  6625.        if (!value) {
  6626.            return '';
  6627.        }
  6628.        const args = Array.prototype.slice.call(arguments);
  6629.        args[0] = value;
  6630.        return this.substituteString.apply(this, args);
  6631.    }
  6632.    /**
  6633.     * Returns a formatted localized string where $1 to $9 are replaced by the
  6634.     * second to the tenth argument. Any standalone $ signs must be escaped as
  6635.     * $$.
  6636.     * @param {string} label The label to substitute through.
  6637.     *     This is not an resource ID.
  6638.     * @param {...(string|number)} var_args The extra values to include in the
  6639.     *     formatted output.
  6640.     * @return {string} The formatted string.
  6641.     */
  6642.    substituteString(label, var_args) {
  6643.        const varArgs = arguments;
  6644.        return label.replace(/\$(.|$|\n)/g, function (m) {
  6645.            expect(m.match(/\$[$1-9]/), 'Unescaped $ found in localized string.');
  6646.            return m === '$$' ? '$' : varArgs[m[1]];
  6647.        });
  6648.    }
  6649.    /**
  6650.     * As above, but also makes sure that the value is a boolean.
  6651.     * @param {string} id The key that identifies the desired boolean.
  6652.     * @return {boolean} The corresponding boolean value.
  6653.     */
  6654.    getBoolean(id) {
  6655.        const value = this.getValue(id);
  6656.        expectIsType(id, value, 'boolean');
  6657.        return /** @type {boolean} */ (value);
  6658.    }
  6659.    /**
  6660.     * As above, but also makes sure that the value is an integer.
  6661.     * @param {string} id The key that identifies the desired number.
  6662.     * @return {number} The corresponding number value.
  6663.     */
  6664.    getInteger(id) {
  6665.        const value = this.getValue(id);
  6666.        expectIsType(id, value, 'number');
  6667.        expect(value === Math.floor(value), 'Number isn\'t integer: ' + value);
  6668.        return /** @type {number} */ (value);
  6669.    }
  6670.    /**
  6671.     * Override values in loadTimeData with the values found in |replacements|.
  6672.     * @param {Object} replacements The dictionary object of keys to replace.
  6673.     */
  6674.    overrideValues(replacements) {
  6675.        expect(typeof replacements === 'object', 'Replacements must be a dictionary object.');
  6676.        for (const key in replacements) {
  6677.            this.data_[key] = replacements[key];
  6678.        }
  6679.    }
  6680. }
  6681. /**
  6682. * Checks condition, throws error message if expectation fails.
  6683. * @param {*} condition The condition to check for truthiness.
  6684. * @param {string} message The message to display if the check fails.
  6685. */
  6686. function expect(condition, message) {
  6687.    if (!condition) {
  6688.        throw new Error('Unexpected condition on ' + document.location.href + ': ' + message);
  6689.    }
  6690. }
  6691. /**
  6692. * Checks that the given value has the given type.
  6693. * @param {string} id The id of the value (only used for error message).
  6694. * @param {*} value The value to check the type on.
  6695. * @param {string} type The type we expect |value| to be.
  6696. */
  6697. function expectIsType(id, value, type) {
  6698.    expect(typeof value === type, '[' + value + '] (' + id + ') is not a ' + type);
  6699. }
  6700. expect(!loadTimeData, 'should only include this file once');
  6701. loadTimeData = new LoadTimeData();
  6702. // Expose |loadTimeData| directly on |window|, since within a JS module the
  6703. // scope is local and not all files have been updated to import the exported
  6704. // |loadTimeData| explicitly.
  6705. window.loadTimeData = loadTimeData;
  6706. console.warn('crbug/1173575, non-JS module files deprecated.');
  6707. </script><script jstcache="0">const pageData = {"details":"详情","errorCode":"DNS_PROBE_POSSIBLE","fontfamily":"'Segoe UI',Arial,'Microsoft Yahei',sans-serif","fontsize":"75%","heading":{"hostName":"网址","msg":"无法访问此网站"},"hideDetails":"隐藏详细信息","iconClass":"icon-generic","language":"zh","reloadButton":{"msg":"重新加载","reloadUrl":"http://网址/"},"suggestionsDetails":[],"suggestionsSummaryList":[{"summary":"\u003Ca href=\"javascript:diagnoseErrors()\" id=\"diagnose-link\">尝试运行 Windows 网络诊断\u003C/a>。"}],"summary":{"failedUrl":"http://网址/","hostName":"网址","msg":"无法找到 \u003Cstrong jscontent=\"hostName\">\u003C/strong> 的 \u003Cabbr id=\"dnsDefinition\">DNS 地址\u003C/abbr>。正在诊断该问题。"},"textdirection":"ltr","title":"网址"};loadTimeData.data = pageData;var tp = document.getElementById('t');jstProcess(new JsEvalContext(pageData), tp);</script></body></html>
Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda