Geoguessr Unity Script

For a full list of features included in this script, see this document https://docs.google.com/document/d/18nLXSQQLOzl4WpUgZkM-mxhhQLY6P3FKonQGp-H0fqI/edit?usp=sharing

目前为 2022-02-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Geoguessr Unity Script
  3. // @description For a full list of features included in this script, see this document https://docs.google.com/document/d/18nLXSQQLOzl4WpUgZkM-mxhhQLY6P3FKonQGp-H0fqI/edit?usp=sharing
  4. // @version 4.6.1
  5. // @include https://www.geoguessr.com/*
  6. // @run-at document-start
  7. // @license MIT
  8. // @namespace https://greasyfork.org/users/838374
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. /**
  13. * For custom Battle Royale / Duels,
  14. * If you want to play a map that includes Kakao or Yandex locations,
  15. * please change "false" to "true" in either fields below.
  16. * Otherwise you would get a black screen.
  17. */
  18.  
  19. let BR_LOAD_KAKAO = false;
  20. let BR_LOAD_YANDEX = false;
  21.  
  22. /**
  23. * Custom your minimap here!
  24. */
  25.  
  26. /**
  27. * 1: replace "roadmap" in the customMode field with any of the options below:
  28. * "roadmap" displays the default road map view. This is the default map type.
  29. * "satellite" displays Google Earth satellite images.
  30. * "hybrid" displays a mixture of normal and satellite views.
  31. * "terrain" displays a physical map based on terrain information.
  32. */
  33.  
  34. let customMode = "terrain";
  35.  
  36. /**
  37. * 2: Go to https://mapstyle.withgoogle.com/ first click "No thanks, take me to the old style wizard"
  38. * then click "MORE OPTIONS" to hide or reveal certain features.
  39. * When you are done, click "FINISH", then "COPY JSON", and replace my settings in custom with your settings below.
  40. */
  41.  
  42. let custom =
  43.  
  44. [
  45. {
  46. "featureType": "administrative",
  47. "stylers": [
  48. {
  49. "visibility": "off"
  50. }
  51. ]
  52. }
  53. ]
  54.  
  55. /**
  56. * End of Minimap customization instruction section
  57. */
  58.  
  59. /**
  60. * Overlay anything on the minimap here!
  61. * 1. overlay an GeoJSON object
  62. * 2. overlay a custom image
  63. */
  64.  
  65. /**
  66. * Overlay an GeoJSON object:
  67. */
  68.  
  69. // change the GeoJson display style.
  70. // strokeOpacity, strokeWeight, fillOpacity takes a value between 0 and 1.
  71. // strokeColor and fillColor supports Hexadecimal color (#00FF00 is green)
  72. // If clickable is set to true, you would not be able to make a guess within the shape
  73.  
  74. let GEOJSON_STYLE =
  75. {
  76. strokeColor: "black",
  77. strokeOpacity: 1,
  78. strokeWeight: 0.2,
  79. fillColor: "#00FF00",
  80. fillOpacity: 0,
  81. clickable: false,
  82. }
  83.  
  84. // replace the URL with your desired link
  85. // For example, search "Germany GeoJson" on Github, find this link (https://github.com/isellsoap/deutschlandGeoJSON/blob/main/4_kreise/4_niedrig.geo.json)
  86. // Then click "Download" to get the raw.githubusercontent.com link (https://raw.githubusercontent.com/isellsoap/deutschlandGeoJSON/main/4_kreise/4_niedrig.geo.json)
  87. // and replace the URL below with that URL.
  88. // State zipcode: see this site https://github.com/OpenDataDE/State-zip-code-GeoJSON
  89.  
  90. let YOUR_URL = "https://raw.githubusercontent.com/severinlandolt/map-switzerland/main/02%20GeoJSON/CH_Kantonsgrenzen_100_geo.json"
  91.  
  92. // set it to true to add your custom GeoJSON by copy it to the code below (this is for
  93.  
  94. let GeoJsonCustomUser = false
  95.  
  96. // replace with your custom GeoJson, go to https://geojson.io/ to customize it then copy the Json to here
  97.  
  98. let CUSTOM_GEOJSON =
  99.  
  100. {
  101. "type": "FeatureCollection",
  102. "features": [
  103. {
  104. "type": "Feature",
  105. "properties": {},
  106. "geometry": {
  107. "type": "LineString",
  108. "coordinates": [
  109. [
  110. 2.493896484375,
  111. 52.7163309360463
  112. ],
  113. [
  114. 2.4609375,
  115. 53.15994678846807
  116. ],
  117. [
  118. 3.2025146484375,
  119. 53.179703893605385
  120. ],
  121. [
  122. 3.2080078125,
  123. 52.96518371955126
  124. ],
  125. [
  126. 2.48291015625,
  127. 52.948637884883205
  128. ]
  129. ]
  130. }
  131. },
  132. {
  133. "type": "Feature",
  134. "properties": {},
  135. "geometry": {
  136. "type": "LineString",
  137. "coordinates": [
  138. [
  139. 3.218994140625,
  140. 52.05586831074774
  141. ],
  142. [
  143. 3.218994140625,
  144. 52.13685974852633
  145. ],
  146. [
  147. 2.515869140625,
  148. 52.1267438596429
  149. ],
  150. [
  151. 2.515869140625,
  152. 51.77803705914517
  153. ],
  154. [
  155. 3.2354736328125,
  156. 51.78993084774129
  157. ],
  158. [
  159. 3.228607177734375,
  160. 51.96119237712624
  161. ],
  162. [
  163. 2.8571319580078125,
  164. 51.95230623740452
  165. ]
  166. ]
  167. }
  168. },
  169. {
  170. "type": "Feature",
  171. "properties": {
  172. "stroke": "#555555",
  173. "stroke-width": 2,
  174. "stroke-opacity": 1
  175. },
  176. "geometry": {
  177. "type": "LineString",
  178. "coordinates": [
  179. [
  180. 2.5048828125,
  181. 52.619725272670266
  182. ],
  183. [
  184. 2.5103759765625,
  185. 52.274880130680536
  186. ],
  187. [
  188. 2.867431640625,
  189. 52.284962354465726
  190. ],
  191. [
  192. 3.2299804687499996,
  193. 52.29504228453735
  194. ],
  195. [
  196. 3.2135009765625,
  197. 52.63973017532399
  198. ],
  199. [
  200. 2.5096893310546875,
  201. 52.621392697207625
  202. ]
  203. ]
  204. }
  205. }
  206. ]
  207. }
  208.  
  209. /**
  210. * Overlay a custom image:
  211. */
  212.  
  213. // set it to true to add your image overlay
  214.  
  215. let OverlayCustom = false
  216.  
  217. // replace the URL with your desired link
  218.  
  219. let OVERLAY_URL = "https://www.battleface.com/blog/wp-content/uploads/2020/10/patreon-profile-tom-geowizard.jpg"
  220.  
  221. // set the bounds for the image - latitude (North and South), longitude (North and South)
  222.  
  223. let OVERLAY_BOUNDS =
  224. {
  225. north: 53,
  226. west: -3,
  227. south: 51,
  228. east: 1,
  229. };
  230.  
  231. // change the image overlay display style.
  232.  
  233. let OVERLAY_STYLE =
  234. {
  235. fillOpacity: 0.2,
  236. clickable: false,
  237. }
  238.  
  239. /**
  240. * End of Minimap Overlay instruction section
  241. */
  242.  
  243. // API Keys
  244.  
  245. var YANDEX_API_KEY = "b704b5a9-3d67-4d19-b702-ec7807cecfc6";
  246. var KAKAO_API_KEY = "cbacbe41e3a223d794f321de4f3e247b";
  247. const MAPS_API_URL = "https://maps.googleapis.com/maps/api/js"; // removed "?" from the link
  248. var MAPILLARY_API_KEY_LIST =
  249. ["MLY|6723031704435203|5afd537469b114cf814881137ad74b7c",
  250. "MLY|6691659414239148|b45e7e82cde126044cbc2cf5d4a7c9b1",
  251. "MLY|5074369465929308|f7ad2802cbaf26c63f88046a292df68b",
  252. "MLY|7451643761528219|6477f2db0e3928b51e45ec9311983936",
  253. "MLY|4855256237866198|6d0464771831c8a4bf2be095e1e1aabc",
  254. "MLY|4772941976102161|8458d4f08d2e1970cdfe0a4e242c04ff",
  255. "MLY|4492067214235489|94c44703942362ad6f6b70b5d32c3a45",
  256. "MLY|4618251611628426|0cef71d6ec8b997a5ec06ecdeabf11ec",
  257. "MLY|4096846270415982|fa2ce29641503e6ef665f17459633570",
  258. "MLY|4231415756962414|fe353880fd246e8a4a6ae32152f7dbb0",]
  259.  
  260. var MAPILLARY_API_KEY = MAPILLARY_API_KEY_LIST[Math.floor(Math.random() * MAPILLARY_API_KEY_LIST.length)];
  261.  
  262. console.log("Geoguessr Unity Script v4.6.1 by Jupaoqq");
  263. // console.log(MAPILLARY_API_KEY);
  264.  
  265. // Store each player instance
  266.  
  267. let YandexPlayer, KakaoPlayer, GooglePlayer, MapillaryPlayer;
  268. let YANDEX_INJECTED = false;
  269. let BAIDU_INJECTED = false;
  270. let KAKAO_INJECTED = false;
  271. let MAPILLARY_INJECTED = false;
  272.  
  273. // Game mode detection
  274.  
  275. let isBattleRoyale = false;
  276. let isDuel = false;
  277.  
  278. // Player detection and coordinate conversion
  279.  
  280. let nextPlayer = "Google";
  281. let global_lat = 0;
  282. let global_lng = 0;
  283. let global_panoID = null;
  284. let global_BDID, global_BDAh, global_BDBh;
  285. let yId, yTime, yEnd, iId;
  286. let global_heading = null;
  287. let global_pitch = null;
  288.  
  289. let krCoordinates = [38.75292321084364, 124.2804539232574, 33.18509676203202, 129.597381999198]
  290. let global_radi = 100
  291.  
  292. // Callback variables
  293.  
  294. let eventListenerAttached = false;
  295. let povListenerAttached = false;
  296. let playerLoaded = false;
  297. let teleportLoaded = false;
  298. let syncLoaded = false;
  299.  
  300. // Minimize Yandex API use
  301.  
  302. let yandex_map = false;
  303. let Kakao_map = false;
  304.  
  305. // Mapillary Image Key
  306.  
  307. let mmKey = 0;
  308.  
  309. // Handle Yandex compass
  310.  
  311. let COMPASS = null;
  312.  
  313. // Handle undo
  314.  
  315. let locHistory = [];
  316. let defaultPanoIdChange = true;
  317.  
  318. // Round check
  319.  
  320. let ROUND = 0;
  321. let CURRENT_ROUND_DATA = null;
  322.  
  323. let switch_call = true;
  324. let one_reset = false;
  325. // let cnt = 0;
  326.  
  327. let cn_tips = false;
  328. var isFirefox = typeof InstallTrigger !== 'undefined';
  329.  
  330. let linksList = []
  331. let fire1 = true;
  332.  
  333. let CNBorder = false;
  334.  
  335. // let NEW_ROUND_LOADED = false;
  336.  
  337. // Geoguessr Canvas String
  338.  
  339. let GENERAL_CANVAS = ".game-layout__panorama-canvas";
  340. let BR_CANVAS = ".br-game-layout__panorama-canvas";
  341. let FAIL_TO_LOAD_CANVAS = ".game-layout__panorama-message";
  342. let DUEL_LAYOUT = ".game_layout__TO_jf";
  343. let DUELS_CANVAS = ".game-panorama_panorama__rdhFg";
  344. let DUELS_CANVAS2 = ".game-panorama_panoramaCanvas__PNKve";
  345. let DUELS_POPUP = ".overlay_overlay__AR02x"
  346. let BR_POPUP = ".popup__content"
  347.  
  348. /**
  349. * Helper Functions
  350. */
  351.  
  352. // Pretty print
  353.  
  354. function myHighlight(...args) {
  355. console.log(`%c${[...args]}`, "color: dodgerblue; font-size: 24px;");
  356. }
  357.  
  358. // Hex to number conversion for Baidu coordinate conversion
  359.  
  360. function hex2a(hexx) {
  361. var hex = hexx.toString();
  362. var str = '';
  363. for (var i = 0; i < hex.length; i += 2)
  364. {
  365. str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
  366. }
  367. return str;
  368. }
  369.  
  370. // Coordinate computation given heading, distance and current coordinates for teleport
  371.  
  372. function FindPointAtDistanceFrom(lat, lng, initialBearingRadians, distanceKilometres) {
  373. const radiusEarthKilometres = 6371.01;
  374. var distRatio = distanceKilometres / radiusEarthKilometres;
  375. var distRatioSine = Math.sin(distRatio);
  376. var distRatioCosine = Math.cos(distRatio);
  377.  
  378. var startLatRad = DegreesToRadians(lat);
  379. var startLonRad = DegreesToRadians(lng);
  380.  
  381. var startLatCos = Math.cos(startLatRad);
  382. var startLatSin = Math.sin(startLatRad);
  383.  
  384. var endLatRads = Math.asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.cos(initialBearingRadians)));
  385.  
  386. var endLonRads = startLonRad
  387. + Math.atan2(
  388. Math.sin(initialBearingRadians) * distRatioSine * startLatCos,
  389. distRatioCosine - startLatSin * Math.sin(endLatRads));
  390.  
  391. return { lat: RadiansToDegrees(endLatRads), lng: RadiansToDegrees(endLonRads) };
  392. }
  393.  
  394. function DegreesToRadians(degrees) {
  395. const degToRadFactor = Math.PI / 180;
  396. return degrees * degToRadFactor;
  397. }
  398.  
  399. function RadiansToDegrees(radians) {
  400. const radToDegFactor = 180 / Math.PI;
  401. return radians * radToDegFactor;
  402. }
  403.  
  404. // Check if two floating point numbers are really really really really close to each other (to 10 decimal points)
  405. function almostEqual (a, b) {
  406. return a.toFixed(10) === b.toFixed(10)
  407. }
  408.  
  409. function almostEqual2 (a, b) {
  410. return a.toFixed(3) === b.toFixed(3)
  411. }
  412.  
  413. // Script injection, extracted from extenssr:
  414. // https://gitlab.com/nonreviad/extenssr/-/blob/main/src/injected_scripts/maps_api_injecter.ts
  415.  
  416. function overrideOnLoad(googleScript, observer, overrider) {
  417. const oldOnload = googleScript.onload
  418. googleScript.onload = (event) => {
  419. const google = window.google
  420. if (google) {
  421. observer.disconnect()
  422. overrider(google)
  423. }
  424. if (oldOnload) {
  425. oldOnload.call(googleScript, event)
  426. }
  427. }
  428. }
  429.  
  430. function grabGoogleScript(mutations) {
  431. for (const mutation of mutations) {
  432. for (const newNode of mutation.addedNodes) {
  433. const asScript = newNode
  434. if (asScript && asScript.src && asScript.src.startsWith('https://maps.googleapis.com/')) {
  435. return asScript
  436. }
  437. }
  438. }
  439. return null
  440. }
  441.  
  442. function injecter(overrider) {
  443. if (document.documentElement)
  444. {
  445. injecterCallback(overrider);
  446. }
  447. else
  448. {
  449. alert("Script didn't load, refresh to try loading the script");
  450. }
  451. }
  452.  
  453. function injecterCallback(overrider)
  454. {
  455. new MutationObserver((mutations, observer) => {
  456. const googleScript = grabGoogleScript(mutations)
  457. if (googleScript) {
  458. overrideOnLoad(googleScript, observer, overrider)
  459. }
  460. }).observe(document.documentElement, { childList: true, subtree: true })
  461. }
  462.  
  463. // Getter function for the button elements
  464.  
  465. function setButtons()
  466. {
  467. return [document.getElementById("Teleport Button"), document.getElementById("plus"), document.getElementById("minus"), document.getElementById("reset"), document.getElementById("switch"), document.getElementById("Show Buttons"), document.getElementById("Date Button"), document.getElementById("minus year"), document.getElementById("plus year"), document.getElementById("Minimap Button"), document.getElementById("Overlay Button"), document.getElementById("Help Button"), document.getElementById("Teleport Options Button")];
  468. }
  469.  
  470. function resetBtnPos()
  471. {
  472. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  473. teleportBtn.style.top = "8.5em";
  474. teleportMoreBtn.style.top = "8.5em";
  475. teleportLessBtn.style.top = "8.5em";
  476. teleportDistResetBtn.style.top = "11em";
  477. switchCovergeButton.style.top = "6em";
  478. mainMenuBtn.style.top = "6em";
  479. timeMachineBtn.style.top = "13.5em";
  480. timeMachineOlderBtn.style.top = "13.5em";
  481. timeMachineNewerBtn.style.top = "13.5em";
  482. MinimapBtn.style.top = "16em";
  483. OverlayBtn.style.top = "16em";
  484. HelpBtn.style.top = "6em";
  485. TeleportArisBtn.style.top = "11em";
  486. document.getElementById("Youtube Button").style.top = "13.5em";
  487.  
  488. teleportBtn.style.right = "9.5em";
  489. teleportMoreBtn.style.right = "7em";
  490. teleportLessBtn.style.right = "20em";
  491. teleportDistResetBtn.style.right = "13em";
  492. switchCovergeButton.style.right = "7em";
  493. mainMenuBtn.style.right = "0.5em";
  494. timeMachineBtn.style.right = "9.5em";
  495. timeMachineOlderBtn.style.right = "20em";
  496. timeMachineNewerBtn.style.right = "7em";
  497. MinimapBtn.style.right = "14.75em";
  498. OverlayBtn.style.right = "7em";
  499. HelpBtn.style.right = "16em";
  500. TeleportArisBtn.style.right = "7em";
  501. document.getElementById("Youtube Button").style.right = "0.5em";
  502.  
  503. let hC = 0
  504. for (let mapDiv of document.getElementsByClassName("preset-minimap")){
  505. mapDiv.style.top = (18.1 + (hC * 1.6)).toString() + "em";
  506. mapDiv.style.right = "14.75em";
  507. hC++;
  508. }
  509. let hC2 = 0
  510. for (let mapDiv2 of document.getElementsByClassName("overlay-minimap")){
  511. mapDiv2.style.top = (18.1 + (hC2 * 1.6)).toString() + "em";
  512. mapDiv2.style.right = "7em";
  513. hC2++;
  514. }
  515. }
  516.  
  517. function AdjustBtnPos(top, right)
  518. {
  519. resetBtnPos();
  520. for (let element of document.getElementsByClassName("unity-btn")){
  521. let eTop = element.style.top;
  522. let eRight = element.style.right;
  523. element.style.top = "calc(" + top.toString() + " + " + eTop + ")";
  524. element.style.right = "calc(" + right.toString() + " + " + eRight + ")";
  525. // console.log(element.style.top)
  526. }
  527. }
  528.  
  529. /**
  530. * Creates teleportation and Kakao switch button
  531. *
  532. * @returns Promise
  533. */
  534.  
  535. function UnityInitiate() {
  536. const google = window.google;
  537. let curPosition;
  538. let kakao_enabled = true;
  539.  
  540. function svCheck(data, status) {
  541. if (status === 'OK') {
  542. console.log("STATUS OK");
  543. let l = data.location.latLng.toString().split(',');
  544. let lat = l[0].replaceAll('(', '');
  545. let lng = l[1].replaceAll(')', '');
  546. if (lat == curPosition.lat && lng == curPosition.lng && !switch_call)
  547. {
  548. console.log("Trying more distance");
  549. teleportBtn.distance += 100;
  550. teleportBtn.innerHTML = "Teleport " + teleportBtn.distance + " m";
  551. }
  552. else
  553. {
  554. console.log("Teleport Success");
  555. GooglePlayer.setPosition(data.location.latLng);
  556. GooglePlayer.setPov({
  557. heading: switchCovergeButton.heading,
  558. pitch: 0,
  559. })
  560. if (teleportBtn.distance > 150)
  561. {
  562. teleportBtn.distance = 100;
  563. teleportBtn.innerHTML = "Teleport " + teleportBtn.distance + " m";
  564. }
  565. }
  566. switch_call = false;
  567. }
  568. else {
  569. console.log("STATUS NOT OK");
  570. teleportBtn.distance += 100;
  571. teleportBtn.innerHTML = "Teleport " + teleportBtn.distance + " m";
  572. }
  573. }
  574.  
  575. google.maps.Map = class extends google.maps.Map {
  576. constructor(...args) {
  577. super(...args);
  578. if (GeoJsonCustomUser)
  579. {
  580. if (GeoJsonCustomUser)
  581. {
  582. this.data.addGeoJson(CUSTOM_GEOJSON);
  583. }
  584. this.data.setStyle(function(feature) {
  585. return GEOJSON_STYLE
  586. });
  587. }
  588. if (OverlayCustom)
  589. {
  590. let customOverlay = new google.maps.GroundOverlay(OVERLAY_URL, OVERLAY_BOUNDS, OVERLAY_STYLE);
  591. customOverlay.setMap(this);
  592. }
  593.  
  594. if (CNBorder)
  595. {
  596. this.data.loadGeoJson("https://raw.githubusercontent.com/Jupaoqq/Jupaoqq.github.io/main/10DD.json");
  597. this.data.setStyle(function(feature) {
  598. return {
  599. clickable: false,
  600. strokeWeight: 1
  601. }
  602. });
  603.  
  604. const imageBounds3 = {
  605. north: NW[0],
  606. west: NW[1],
  607. south: NW[2],
  608. east: NW[3],
  609. };
  610.  
  611. SEOverlay3 = new google.maps.GroundOverlay(
  612. "https://www.countryflags.com/wp-content/uploads/china-flag-png-large.png",
  613. imageBounds3, {clickable: false, opacity: 1}
  614. );
  615. SEOverlay3.setMap(this);
  616.  
  617. this.addListener("zoom_changed", () => {
  618. let zoomLevel = this.getZoom();
  619. let opacity = 1;
  620. if (SEOverlay)
  621. {
  622. SEOverlay.setMap(null);
  623. NWOverlay.setMap(null);
  624. }
  625. let borderSE = TW[0]
  626. let borderNW = TS[0]
  627. if (zoomLevel > 7 && zoomLevel < 14)
  628. {
  629. borderSE = TW[zoomLevel - 7];
  630. borderNW = TS[1];
  631. }
  632. if (zoomLevel >= 14)
  633. {
  634. opacity = 0;
  635. }
  636. const imageBounds = {
  637. north: borderSE[0],
  638. west: borderSE[1],
  639. south: borderSE[2],
  640. east: borderSE[3],
  641. };
  642. SEOverlay = new google.maps.GroundOverlay(
  643. "https://www.countryflags.com/wp-content/uploads/china-flag-png-large.png",
  644. imageBounds, {clickable: false, opacity: opacity}
  645. );
  646. SEOverlay.setMap(this);
  647. const imageBounds2 = {
  648. north: borderNW[0],
  649. west: borderNW[1],
  650. south: borderNW[2],
  651. east: borderNW[3],
  652. };
  653. NWOverlay = new google.maps.GroundOverlay(
  654. "https://www.countryflags.com/wp-content/uploads/china-flag-png-large.png",
  655. imageBounds2, {clickable: false, opacity: 1}
  656. );
  657. NWOverlay.setMap(this);
  658. });
  659. }
  660. for (let mapDiv of document.getElementsByClassName("preset-minimap")){
  661. google.maps.event.addDomListener(mapDiv, "click", () => {
  662. MinimapBtn.current = mapDiv.id;
  663. if (mapDiv.id == "Hybrid")
  664. {
  665. this.setMapTypeId('hybrid');
  666. }
  667. else if (mapDiv.id == "Terrain")
  668. {
  669. this.setMapTypeId('terrain');
  670. }
  671. else if (mapDiv.id == "Satellite")
  672. {
  673. this.setMapTypeId('satellite');
  674. }
  675. else if (mapDiv.id == "Custom")
  676. {
  677. this.setMapTypeId(customMode);
  678. }
  679. else
  680. {
  681. this.setMapTypeId('roadmap');
  682. }
  683. // this.setTilt(45);
  684. for (let ar of presetMinimap)
  685. {
  686. if (ar[1] == mapDiv.id)
  687. {
  688. this.set('styles', ar[0]);
  689. }
  690. }
  691. for (let element of document.getElementsByClassName("preset-minimap")){
  692. if (element.id == MinimapBtn.current)
  693. {
  694. element.style.background = "#ff6600";
  695. }
  696. else
  697. {
  698. element.style.background = "orange";
  699. }
  700. }
  701.  
  702. });
  703. }
  704. for (let mapDiv of document.getElementsByClassName("overlay-minimap")){
  705. google.maps.event.addDomListener(mapDiv, "click", () => {
  706. OverlayBtn.current = mapDiv.id;
  707. // console.log(mapDiv.url)
  708. // console.log(mapDiv.id)
  709. // console.log(mapDiv.loaded)
  710. if (!mapDiv.loaded)
  711. {
  712. this.data.loadGeoJson(mapDiv.url, {
  713. id: mapDiv.id
  714. });
  715. mapDiv.loaded = true;
  716. }
  717.  
  718. if (mapDiv.id !== "Default")
  719. {
  720. this.data.setStyle(function(feature) {
  721. return GEOJSON_STYLE
  722. });
  723. for (let element of document.getElementsByClassName("overlay-minimap")){
  724. if (element.id !== "Default" && element.loaded)
  725. {
  726. element.style.background = "#ff6600";
  727. }
  728. else
  729. {
  730. element.style.background = "orange";
  731. }
  732. }
  733. }
  734. else
  735. {
  736. this.data.setStyle(function(feature) {
  737. return GEOJSON_INVISIBLE
  738. });
  739. for (let element of document.getElementsByClassName("overlay-minimap")){
  740. if (element.id === "Default")
  741. {
  742. element.style.background = "#ff6600";
  743. }
  744. else
  745. {
  746. element.style.background = "orange";
  747. }
  748. }
  749. }
  750. });
  751. }
  752. }
  753.  
  754. }
  755.  
  756. const svService = new google.maps.StreetViewService();
  757. google.maps.StreetViewPanorama = class extends google.maps.StreetViewPanorama {
  758. constructor(...args) {
  759. super(...args);
  760. GooglePlayer = this;
  761.  
  762. const isGamePage = () => location.pathname.startsWith("/challenge/") || location.pathname.startsWith("/results/") || location.pathname.startsWith("/game/")|| location.pathname.startsWith("/battle-royale/") || location.pathname.startsWith("/duels/") || location.pathname.startsWith("/team-duels/");
  763.  
  764. this.addListener('position_changed', () => {
  765. // Maybe this could be used to update the position in the other players
  766. // so that they are always in sync
  767. try {
  768. if (!isGamePage()) return;
  769. // timeMachineBtn.panoId = GooglePlayer.pano;
  770. // timeMachineBtn.index = -1;
  771. const lat = this.getPosition().lat();
  772. const lng = this.getPosition().lng();
  773. const { heading } = this.getPov();
  774.  
  775. curPosition = { lat, lng, heading };
  776.  
  777. if (switchCovergeButton.useGoogle)
  778. {
  779. switchCovergeButton.lng = lng;
  780. switchCovergeButton.lat = lat;
  781. switchCovergeButton.heading = heading;
  782. if (!timeMachineBtn.list.some(row => row.includes(GooglePlayer.pano)))
  783. {
  784. timeMachineBtn.innerHTML = "Time Machine";
  785. timeMachineBtn.panoId = GooglePlayer.pano;
  786. timeMachineBtn.index = -1;
  787. timeMachineBtn.plusminusLock = true;
  788. timeMachineNewerBtn.style.backgroundColor = "red";
  789. timeMachineNewerBtn.disabled = true;
  790. timeMachineOlderBtn.style.backgroundColor = "red";
  791. timeMachineOlderBtn.disabled = true;
  792. }
  793. }
  794. switchCovergeButton.useGoogle = true;
  795. teleportBtn.google = true;
  796. // console.log("also run");
  797.  
  798. // switchCovergeButton.heading = position.lat;
  799. // console.log(position.heading);
  800. // console.log(switchCovergeButton.lng);
  801. }
  802. catch (e) {
  803. console.error("GeoGuessr Path Logger Error:", e);
  804. }
  805. });
  806. this.addListener('pov_changed', () => {
  807. const { heading, pitch } = this.getPov();
  808. if (KakaoPlayer) {
  809. if (typeof KakaoPlayer !== 'string' )
  810. {
  811. const vp = KakaoPlayer.getViewpoint();
  812. // Prevent a recursive loop: only update kakao's viewpoint if it got out of sync with google's
  813. if ((!almostEqual(vp.pan, heading) || !almostEqual(vp.tilt, pitch)) && nextPlayer == "Kakao") {
  814. KakaoPlayer.setViewpoint({ pan: heading, tilt: pitch, zoom: vp.zoom });
  815. }
  816. }
  817. }
  818. });
  819. }
  820. };
  821.  
  822.  
  823. var mainMenuBtn = document.createElement("Button");
  824. mainMenuBtn.classList.add("unity-btn");
  825. mainMenuBtn.id = "Show Buttons"
  826. mainMenuBtn.innerHTML = "Geoguessr Unity Script<br><font size=1>by Jupaoqq<br>v4.6.1</font>";
  827. mainMenuBtn.style =
  828. "visibility:hidden;width:6em;height:7em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  829. // document.querySelector(".game-layout__status").appendChild(mainMenuBtn)
  830. document.body.appendChild(mainMenuBtn);
  831. mainMenuBtn.addEventListener("click", () => {
  832. if (hide) {
  833. for (let element of document.getElementsByClassName("unity-btn")){
  834. if (!element.classList.contains("preset-minimap") && !element.classList.contains("overlay-minimap"))
  835. {
  836. element.style.visibility = "";
  837. if ((nextPlayer != "Youtube") && element.id == "Youtube Button")
  838. {
  839. element.style.visibility = "hidden";
  840. }
  841. }
  842. }
  843. hide = false;
  844. }
  845. else {
  846. for (let element of document.getElementsByClassName("unity-btn")){
  847. if (element.id !== "Show Buttons")
  848. {
  849. element.style.visibility = "hidden";
  850. }
  851. }
  852. hide = true;
  853. }
  854. });
  855.  
  856. var teleportBtn = document.createElement("Button");
  857. teleportBtn.classList.add("unity-btn");
  858. teleportBtn.teleType = "default";
  859. teleportBtn.id = "Teleport Button";
  860. teleportBtn.distance = 100;
  861. teleportBtn.google = true;
  862. teleportBtn.innerHTML = "Teleport 100m";
  863. teleportBtn.style =
  864. "visibility:hidden;width:10em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  865. document.body.appendChild(teleportBtn);
  866. teleportBtn.addEventListener("click", () => {
  867. // console.log("Google Teleport");
  868. if (switchCovergeButton.init)
  869. {
  870. // console.log("run");
  871. switchCovergeButton.init = false;
  872. if (teleportBtn.google)
  873. {
  874. switchCovergeButton.useGoogle = true;
  875. teleportBtn.google = true;
  876. }
  877. else
  878. {
  879. switchCovergeButton.useGoogle = false;
  880. teleportBtn.google = false;
  881. }
  882. }
  883. else
  884. {
  885. // console.log(teleportBtn.google)
  886. if (teleportBtn.google && GooglePlayer != null)
  887. {
  888. let heading = GooglePlayer.getPov().heading;
  889. let place = FindPointAtDistanceFrom(curPosition.lat, curPosition.lng , DegreesToRadians(heading), teleportBtn.distance * 0.001)
  890. svService.getPanorama({ location: place, radius: 1000, source: teleportBtn.teleType}, svCheck);
  891. }
  892. }
  893. });
  894.  
  895. var teleportMoreBtn = document.createElement("Button");
  896. teleportMoreBtn.classList.add("unity-btn");
  897. teleportMoreBtn.id = "plus"
  898. teleportMoreBtn.innerHTML = "+";
  899. teleportMoreBtn.style =
  900. "visibility:hidden;width:2em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  901. document.body.appendChild(teleportMoreBtn);
  902. teleportMoreBtn.addEventListener("click", () => {
  903. if (teleportBtn.distance > 21 && teleportBtn.distance < 149) {
  904. teleportBtn.distance = teleportBtn.distance + 25;
  905. }
  906. teleportBtn.innerHTML = "Teleport " + teleportBtn.distance + " m";
  907. });
  908.  
  909. var teleportLessBtn = document.createElement("Button");
  910. teleportLessBtn.classList.add("unity-btn");
  911. teleportLessBtn.id = "minus"
  912. teleportLessBtn.innerHTML = "-";
  913. teleportLessBtn.style =
  914. "visibility:hidden;width:2em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  915. document.body.appendChild(teleportLessBtn);
  916. teleportLessBtn.addEventListener("click", () => {
  917. if (teleportBtn.distance > 26) {
  918. teleportBtn.distance = teleportBtn.distance - 25;
  919. }
  920. teleportBtn.innerHTML = "Teleport " + teleportBtn.distance + " m";
  921. });
  922.  
  923. var teleportDistResetBtn = document.createElement("Button");
  924. teleportDistResetBtn.classList.add("unity-btn");
  925. teleportDistResetBtn.id = "reset"
  926. teleportDistResetBtn.innerHTML = "Reset Distance";
  927. teleportDistResetBtn.style =
  928. "visibility:hidden;width:9em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  929. document.body.appendChild(teleportDistResetBtn);
  930. teleportDistResetBtn.addEventListener("click", () => {
  931. teleportBtn.distance = 100;
  932. teleportBtn.innerHTML = "Teleport " + teleportBtn.distance + " m";
  933. });
  934.  
  935. var switchCovergeButton = document.createElement("Button");
  936. switchCovergeButton.classList.add("unity-btn");
  937. switchCovergeButton.id = "switch";
  938. switchCovergeButton.init = false;
  939. switchCovergeButton.nextPlayer = "Google";
  940. switchCovergeButton.useGoogle = false;
  941. switchCovergeButton.lng = 0
  942. switchCovergeButton.lat = 0
  943. switchCovergeButton.heading = 0
  944. switchCovergeButton.innerHTML = "Switch Coverage";
  945. switchCovergeButton.small_canvas = false;
  946. switchCovergeButton.style =
  947. "visibility:hidden;width:8.5em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  948. document.body.appendChild(switchCovergeButton);
  949. switchCovergeButton.addEventListener("click", () => {
  950. let GOOGLE_MAPS_CANVAS1 = document.querySelector(".game-layout__panorama-canvas");
  951. let GOOGLE_MAPS_CANVAS2 = document.querySelector(".br-game-layout__panorama-canvas");
  952. let GOOGLE_MAPS_CANVAS3 = document.querySelector(".inactive");
  953. let duel = false;
  954.  
  955. let GOOGLE_MAPS_CANVAS = null;
  956. if (GOOGLE_MAPS_CANVAS1 !== null)
  957. {
  958. GOOGLE_MAPS_CANVAS = GOOGLE_MAPS_CANVAS1;
  959. }
  960. else if (GOOGLE_MAPS_CANVAS2 !== null)
  961. {
  962. GOOGLE_MAPS_CANVAS = GOOGLE_MAPS_CANVAS2;
  963. }
  964. if (GOOGLE_MAPS_CANVAS3 !== null)
  965. {
  966. duel = true;
  967. }
  968.  
  969. let KAKAO_MAPS_CANVAS = document.getElementById("roadview");
  970. let YANDEX_MAPS_CANVAS = document.querySelector(".ymaps-2-1-79-panorama-screen");
  971. let MAPILLARY_MAPS_CANVAS = document.getElementById("mapillary-player")
  972. let BAIDU_MAPS_CANVAS = document.getElementById("i_container");
  973. // if (switchCovergeButton.nextPlayer !== "Baidu") {
  974. if (switchCovergeButton.useGoogle == false) {
  975. if (duel)
  976. {
  977. document.getElementById("default_player").className = "game-panorama_panoramaCanvas__PNKve";
  978. if (switchCovergeButton.nextPlayer == "Kakao")
  979. {
  980. document.getElementById("roadview").className = "inactive";
  981. }
  982. else
  983. {
  984. MAPILLARY_MAPS_CANVAS.className = "inactive";
  985. MAPILLARY_MAPS_CANVAS.style.visibility = "hidden";
  986. }
  987. }
  988. else
  989. {
  990. GOOGLE_MAPS_CANVAS.style.visibility = "";
  991. if (switchCovergeButton.nextPlayer == "Kakao")
  992. {
  993. KAKAO_MAPS_CANVAS.style.visibility = "hidden";
  994. }
  995. else if (switchCovergeButton.nextPlayer == "Yandex")
  996. {
  997. YANDEX_MAPS_CANVAS.style.visibility = "hidden";
  998. }
  999. else if (switchCovergeButton.nextPlayer == "Baidu")
  1000. {
  1001. BAIDU_MAPS_CANVAS.style.visibility = "hidden";
  1002. }
  1003. else if (switchCovergeButton.nextPlayer == "Mapillary" || switchCovergeButton.nextPlayer == "Google")
  1004. {
  1005. MAPILLARY_MAPS_CANVAS.style.visibility = "hidden";
  1006. }
  1007.  
  1008. }
  1009. const lat = GooglePlayer.getPosition().lat();
  1010. const lng = GooglePlayer.getPosition().lng();
  1011. switch_call = true;
  1012. if (!almostEqual2(lat, switchCovergeButton.lat) || !almostEqual2(lat, switchCovergeButton.lng)) {
  1013. svService.getPanorama({ location: { lat: switchCovergeButton.lat, lng: switchCovergeButton.lng }, radius: 1000 }, svCheck);
  1014. }
  1015. switchCovergeButton.useGoogle = true;
  1016. teleportBtn.google = true;
  1017. switchCovergeButton.init = false;
  1018. console.log("use Google");
  1019. }
  1020. else {
  1021. if (duel)
  1022. {
  1023. document.getElementById("default_player").className = "inactive";
  1024. if (switchCovergeButton.nextPlayer == "Kakao")
  1025. {
  1026. document.getElementById("roadview").className = "game-panorama_panoramaCanvas__PNKve";
  1027. }
  1028. else
  1029. {
  1030. MAPILLARY_MAPS_CANVAS.className = "game-panorama_panoramaCanvas__PNKve";
  1031. MAPILLARY_MAPS_CANVAS.style.visibility = "";
  1032. MapillaryPlayer.resize();
  1033. //window.dispatchEvent(new Event('resize'));
  1034. // document.querySelector(".mapillary-canvas").style.;
  1035. // mapillary-canvas
  1036. }
  1037.  
  1038. }
  1039. else
  1040. {
  1041. GOOGLE_MAPS_CANVAS.style.visibility = "hidden";
  1042. if (switchCovergeButton.nextPlayer == "Kakao")
  1043. {
  1044. KAKAO_MAPS_CANVAS.style.visibility = "";
  1045. }
  1046. else if (switchCovergeButton.nextPlayer == "Yandex")
  1047. {
  1048. YANDEX_MAPS_CANVAS.style.visibility = "";
  1049. }
  1050. else if (switchCovergeButton.nextPlayer == "Baidu")
  1051. {
  1052. BAIDU_MAPS_CANVAS.style.visibility = "";
  1053. }
  1054. else if (switchCovergeButton.nextPlayer == "Mapillary" || switchCovergeButton.nextPlayer == "Google" )
  1055. {
  1056. MAPILLARY_MAPS_CANVAS.style.visibility = "";
  1057. }
  1058. }
  1059. switchCovergeButton.useGoogle = false;
  1060. teleportBtn.google = false;
  1061. switchCovergeButton.init = true;
  1062. console.log("use Others");
  1063. }
  1064. // }
  1065. // else {
  1066. // switchCovergeButton.useGoogle = false;
  1067. // teleportBtn.google = false;
  1068. // console.log("use Others");
  1069. // }
  1070.  
  1071. });
  1072.  
  1073. var timeMachineNewerBtn = document.createElement("Button");
  1074. timeMachineNewerBtn.classList.add("unity-btn");
  1075. timeMachineNewerBtn.id = "plus year"
  1076. timeMachineNewerBtn.innerHTML = "+";
  1077. timeMachineNewerBtn.style =
  1078. "visibility:hidden;width:2em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1079. document.body.appendChild(timeMachineNewerBtn);
  1080. timeMachineNewerBtn.addEventListener("click", () => {
  1081. if (timeMachineBtn.index < timeMachineBtn.list.length - 1 && !timeMachineBtn.plusminusLock) {
  1082. timeMachineBtn.index = timeMachineBtn.index + 1;
  1083. GooglePlayer.setPano(timeMachineBtn.list[timeMachineBtn.index][0]);
  1084. timeMachineBtn.innerHTML = "<font size=2>[" + (timeMachineBtn.index + 1) + "] " + timeMachineBtn.list[timeMachineBtn.index][1] + "</font>";
  1085. // console.log(timeMachineBtn.index)
  1086. }
  1087. GenBtnColor();
  1088.  
  1089. });
  1090.  
  1091. var timeMachineOlderBtn = document.createElement("Button");
  1092. timeMachineOlderBtn.classList.add("unity-btn");
  1093. timeMachineOlderBtn.id = "minus year"
  1094. timeMachineOlderBtn.innerHTML = "-";
  1095. timeMachineOlderBtn.style =
  1096. "visibility:hidden;width:2em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1097. document.body.appendChild(timeMachineOlderBtn);
  1098. timeMachineOlderBtn.addEventListener("click", () => {
  1099. if (timeMachineBtn.index > 0 && !timeMachineBtn.plusminusLock) {
  1100. timeMachineBtn.index = timeMachineBtn.index - 1;
  1101. GooglePlayer.setPano(timeMachineBtn.list[timeMachineBtn.index][0]);
  1102. timeMachineBtn.innerHTML = "<font size=2>[" + (timeMachineBtn.index + 1) + "] " + timeMachineBtn.list[timeMachineBtn.index][1] + "</font>";
  1103. // console.log(timeMachineBtn.index)
  1104. }
  1105. GenBtnColor();
  1106. });
  1107.  
  1108. function svCheck2(data, status) {
  1109. let l = []
  1110. if (status === 'OK') {
  1111. // console.log("OK for " + data.location.latLng + " at ID " + data.location.pano);
  1112. // console.log(data.time)
  1113. for (const alt of data.time) {
  1114. let date = Object.values(alt).find((value) => value instanceof Date)
  1115.  
  1116. l.push([alt.pano, date.toDateString()]);
  1117. }
  1118. // console.log(l);
  1119. timeMachineBtn.list = l
  1120. timeMachineBtn.index = l.length - 1;
  1121. timeMachineBtn.innerHTML = "<font size=2>[" + (timeMachineBtn.index + 1) + "] " + timeMachineBtn.list[timeMachineBtn.index][1] + "</font>";
  1122. GenBtnColor();
  1123. timeMachineBtn.plusminusLock = false;
  1124. // timeMachineOlderBtn.click()
  1125. // timeMachineBtn.innerHTML = "Default Date";
  1126. }
  1127. }
  1128.  
  1129. var timeMachineBtn = document.createElement("Button");
  1130. timeMachineBtn.classList.add("unity-btn");
  1131. timeMachineBtn.id = "Date Button";
  1132. timeMachineBtn.plusminusLock = true;
  1133. timeMachineBtn.panoId = 0;
  1134. timeMachineBtn.index = -1;
  1135. timeMachineBtn.list = [];
  1136. timeMachineBtn.innerHTML = "Time Machine";
  1137. timeMachineBtn.style =
  1138. "visibility:hidden;width:10em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1139. document.body.appendChild(timeMachineBtn);
  1140. timeMachineBtn.addEventListener("click", () => {
  1141. // console.log(timeMachineBtn.index)
  1142. if (timeMachineBtn.panoId != 0)
  1143. {
  1144. if(timeMachineBtn.index == -1)
  1145. {
  1146. svService.getPanorama({pano: timeMachineBtn.panoId}, svCheck2);
  1147. }
  1148. else
  1149. {
  1150. timeMachineBtn.index = timeMachineBtn.list.length - 1;
  1151. GooglePlayer.setPano(timeMachineBtn.list[timeMachineBtn.index][0]);
  1152. timeMachineBtn.innerHTML = "<font size=2>[" + (timeMachineBtn.index + 1) + "] " + timeMachineBtn.list[timeMachineBtn.index][1] + "</font>";
  1153. GenBtnColor();
  1154. }
  1155. }
  1156. else
  1157. {
  1158. timeMachineBtn.panoId = GooglePlayer.pano;
  1159. svService.getPanorama({pano: timeMachineBtn.panoId}, svCheck2);
  1160. }
  1161. });
  1162.  
  1163. // Battle Royale UI optimization
  1164.  
  1165. let hide = true;
  1166.  
  1167. var MinimapBtn = document.createElement("Button");
  1168. MinimapBtn.classList.add("unity-btn");
  1169. MinimapBtn.id = "Minimap Button";
  1170. MinimapBtn.innerHTML = "Minimap Style";
  1171. MinimapBtn.current = "Default";
  1172. MinimapBtn.childVisible = false;
  1173. MinimapBtn.style =
  1174. "visibility:hidden;width:7.25em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1175. document.body.appendChild(MinimapBtn);
  1176. MinimapBtn.addEventListener("click", () => {
  1177. if (MinimapBtn.childVisible)
  1178. {
  1179. for (let element of document.getElementsByClassName("preset-minimap")){
  1180. element.style.visibility="hidden";
  1181. }
  1182. MinimapBtn.childVisible = false;
  1183. }
  1184. else
  1185. {
  1186. for (let element of document.getElementsByClassName("preset-minimap")){
  1187. element.style.visibility="";
  1188. }
  1189. MinimapBtn.childVisible = true;
  1190. }
  1191.  
  1192. });
  1193.  
  1194.  
  1195. let HeightCount = 0
  1196. for (let a of presetMinimap)
  1197. {
  1198. let aButton = document.createElement("Button");
  1199. aButton.id = a[1];
  1200. aButton.classList.add("preset-minimap");
  1201. aButton.classList.add("unity-btn");
  1202. aButton.innerHTML = a[1];
  1203. aButton.style =
  1204. "visibility:hidden;width:7.25em;height:1.5em;position:absolute;z-index:99999;background-color: orange;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1205. document.body.appendChild(aButton);
  1206. HeightCount++;
  1207. }
  1208.  
  1209. var OverlayBtn = document.createElement("Button");
  1210. OverlayBtn.classList.add("unity-btn");
  1211. OverlayBtn.id = "Overlay Button";
  1212. OverlayBtn.innerHTML = "Overlay";
  1213. OverlayBtn.current = "Default";
  1214. OverlayBtn.childVisible = false;
  1215. OverlayBtn.style =
  1216. "visibility:hidden;width:7.25em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1217. document.body.appendChild(OverlayBtn);
  1218.  
  1219. OverlayBtn.addEventListener("click", () => {
  1220. if (OverlayBtn.childVisible)
  1221. {
  1222. for (let element of document.getElementsByClassName("overlay-minimap")){
  1223. element.style.visibility = "hidden";
  1224. }
  1225. OverlayBtn.childVisible = false;
  1226. }
  1227. else
  1228. {
  1229. for (let element of document.getElementsByClassName("overlay-minimap")){
  1230. element.style.visibility = "";
  1231. }
  1232. OverlayBtn.childVisible = true;
  1233. }
  1234.  
  1235. });
  1236.  
  1237. let HeightCount2 = 0
  1238. for (let b of presetOverlay)
  1239. {
  1240. let bButton = document.createElement("Button");
  1241. bButton.id = b[0];
  1242. bButton.url = b[1];
  1243. bButton.loaded = false;
  1244. bButton.classList.add("overlay-minimap");
  1245. bButton.classList.add("unity-btn");
  1246. bButton.innerHTML = b[0];
  1247. bButton.style =
  1248. "visibility:hidden;width:7.25em;height:1.5em;position:absolute;z-index:99999;background-color: orange;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1249. if (bButton.id == "Default")
  1250. {
  1251. bButton.loaded = true;
  1252. bButton.style.background = "#ff6600";
  1253. }
  1254. document.body.appendChild(bButton);
  1255. HeightCount2++;
  1256. }
  1257.  
  1258. var HelpBtn = document.createElement("Button");
  1259. HelpBtn.classList.add("unity-btn");
  1260. HelpBtn.id = "Help Button";
  1261. HelpBtn.innerHTML = "Script Help";
  1262. HelpBtn.style =
  1263. "visibility:hidden;width:6em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1264. document.body.appendChild(HelpBtn);
  1265. HelpBtn.addEventListener("click", () => {
  1266. window.open('https://docs.google.com/document/d/18nLXSQQLOzl4WpUgZkM-mxhhQLY6P3FKonQGp-H0fqI/edit?usp=sharing');
  1267. });
  1268.  
  1269. var TeleportArisBtn = document.createElement("Button");
  1270. TeleportArisBtn.classList.add("unity-btn");
  1271. TeleportArisBtn.id = "Teleport Options Button";
  1272. TeleportArisBtn.innerHTML = "Default";
  1273. TeleportArisBtn.style =
  1274. "visibility:hidden;width:5.5em;height:2em;position:absolute;z-index:99999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1275. document.body.appendChild(TeleportArisBtn);
  1276. TeleportArisBtn.addEventListener("click", () => {
  1277. if (teleportBtn.teleType == "default")
  1278. {
  1279. teleportBtn.teleType = "outdoor"
  1280. TeleportArisBtn.innerHTML = "Official";
  1281. }
  1282. else
  1283. {
  1284. teleportBtn.teleType = "default"
  1285. TeleportArisBtn.innerHTML = "Default";
  1286. }
  1287. });
  1288.  
  1289. var playYoutubeBtn = document.createElement("Button");
  1290. playYoutubeBtn.classList.add("unity-btn");
  1291. playYoutubeBtn.id = "Youtube Button";
  1292. playYoutubeBtn.innerHTML = "Play video";
  1293. playYoutubeBtn.style =
  1294. "visibility:hidden;width:6em;height:4.5em;position:absolute;z-index:999999;background-color: #4CAF50;border: none;color: white;padding: none;text-align: center;vertical-align: text-top;text-decoration: none;display: inline-block;font-size: 16px;";
  1295. document.body.appendChild(playYoutubeBtn);
  1296. playYoutubeBtn.addEventListener("click", () => {
  1297. let iframe = document.getElementById("i_container");
  1298. iframe.allow = "autoplay";
  1299. let srcString = "https://www.youtube.com/embed/" + yId + "?&playlist=" + yId + "&autoplay=1&modestbranding=1&controls=0&start=";
  1300. if (yTime == "0" && yEnd == "0")
  1301. {
  1302. }
  1303. else
  1304. {
  1305. srcString += yTime + "&end=" + yEnd;
  1306. }
  1307. iframe.src = srcString;
  1308. iframe.style.visibility = "";
  1309. playYoutubeBtn.innerHTML = "Play video from start";
  1310. });
  1311.  
  1312.  
  1313. console.log("Buttons Loaded");
  1314. }
  1315.  
  1316. function GenBtnColor()
  1317. {
  1318. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1319. if (timeMachineBtn.index == timeMachineBtn.list.length - 1)
  1320. {
  1321. timeMachineNewerBtn.style.backgroundColor = "red";
  1322. timeMachineNewerBtn.disabled = true;
  1323. }
  1324. else
  1325. {
  1326. timeMachineNewerBtn.style.backgroundColor = "#4CAF50";
  1327. timeMachineNewerBtn.disabled = false;
  1328. }
  1329. if (timeMachineBtn.index == 0)
  1330. {
  1331. timeMachineOlderBtn.style.backgroundColor = "red";
  1332. timeMachineOlderBtn.disabled = true;
  1333. }
  1334. else
  1335. {
  1336. timeMachineOlderBtn.style.backgroundColor = "#4CAF50";
  1337. timeMachineOlderBtn.disabled = false;
  1338. }
  1339. }
  1340.  
  1341. /**
  1342. * Handle Keyboard inputs
  1343. */
  1344.  
  1345. function kBoard()
  1346. {
  1347. document.addEventListener('keydown', logKey);
  1348. }
  1349.  
  1350. function logKey(e) {
  1351. // console.log(e.code);
  1352. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1353. if (e.code == "Space")
  1354. {
  1355. setHidden(true);
  1356. }
  1357. if (e.code == "Digit3")
  1358. {
  1359. teleportBtn.click();
  1360. }
  1361. else if (e.code == "Digit4")
  1362. {
  1363. timeMachineOlderBtn.click();
  1364. }
  1365. else if (e.code == "Digit5")
  1366. {
  1367. timeMachineBtn.click();
  1368. }
  1369. else if (e.code == "Digit6")
  1370. {
  1371. timeMachineNewerBtn.click();
  1372. }
  1373. else if (e.code == "Digit7")
  1374. {
  1375. if (mainMenuBtn.style.visibility == "hidden")
  1376. {
  1377. mainMenuBtn.style.visibility = "";
  1378. }
  1379. else
  1380. {
  1381. mainMenuBtn.style.visibility = "hidden";
  1382. }
  1383. }
  1384. }
  1385.  
  1386.  
  1387. /**
  1388. * Hide or reveal the buttons, and disable buttons if such feature is not available
  1389. */
  1390.  
  1391. function setHidden(cond)
  1392. {
  1393. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1394. if (cond)
  1395. {
  1396. if (mainMenuBtn != null)
  1397. {
  1398. if (teleportBtn != null)
  1399. {
  1400. for (let element of document.getElementsByClassName("unity-btn")){
  1401. element.style.visibility = "hidden";
  1402. }
  1403. }
  1404. let iframe = document.getElementById("i_container");
  1405. if (iframe != null)
  1406. {
  1407. if (!isBattleRoyale)
  1408. {
  1409. iframe.src = ""
  1410. }
  1411. else
  1412. {
  1413. // TODO
  1414. }
  1415. }
  1416. }
  1417. }
  1418. else
  1419. {
  1420. if (mainMenuBtn != null)
  1421. {
  1422. mainMenuBtn.style.visibility = "";
  1423. }
  1424. }
  1425. }
  1426.  
  1427. function setDisable(cond) {
  1428. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1429. if (teleportBtn != null) {
  1430. if (cond == "NMPZ") {
  1431. teleportMoreBtn.style.backgroundColor = "red";
  1432. teleportMoreBtn.disabled = true;
  1433. teleportLessBtn.style.backgroundColor = "red";
  1434. teleportLessBtn.disabled = true;
  1435. teleportDistResetBtn.style.backgroundColor = "red";
  1436. teleportDistResetBtn.disabled = true;
  1437. if (nextPlayer == "Kakao")
  1438. {
  1439. switchCovergeButton.style.backgroundColor = "#4CAF50";
  1440. switchCovergeButton.disabled = false;
  1441. }
  1442. else
  1443. {
  1444. switchCovergeButton.style.backgroundColor = "red";
  1445. switchCovergeButton.disabled = true;
  1446. }
  1447. teleportBtn.disabled = true;
  1448. teleportBtn.style.backgroundColor = "red";
  1449. TeleportArisBtn.style.backgroundColor = "red";
  1450. TeleportArisBtn.disabled = true;
  1451. timeMachineBtn.style.backgroundColor = "#4CAF50";
  1452. timeMachineBtn.disabled = false;
  1453. }
  1454. else if (cond == "Google") {
  1455. teleportMoreBtn.style.backgroundColor = "#4CAF50";
  1456. teleportMoreBtn.disabled = false;
  1457. teleportLessBtn.style.backgroundColor = "#4CAF50";
  1458. teleportLessBtn.disabled = false;
  1459. teleportDistResetBtn.style.backgroundColor = "#4CAF50";
  1460. teleportDistResetBtn.disabled = false;
  1461. switchCovergeButton.style.backgroundColor = "#4CAF50";
  1462. switchCovergeButton.disabled = false;
  1463. teleportBtn.disabled = false;
  1464. teleportBtn.style.backgroundColor = "#4CAF50";
  1465. TeleportArisBtn.disabled = false;
  1466. TeleportArisBtn.style.backgroundColor = "#4CAF50";
  1467. timeMachineBtn.style.backgroundColor = "#4CAF50";
  1468. timeMachineBtn.disabled = false;
  1469. }
  1470. else if (nextPlayer === "Baidu" || nextPlayer === "Youtube" || nextPlayer === "Image") {
  1471. teleportMoreBtn.style.backgroundColor = "red";
  1472. teleportMoreBtn.disabled = true;
  1473. teleportLessBtn.style.backgroundColor = "red";
  1474. teleportLessBtn.disabled = true;
  1475. teleportDistResetBtn.style.backgroundColor = "red";
  1476. teleportDistResetBtn.disabled = true;
  1477. switchCovergeButton.style.backgroundColor = "#4CAF50";
  1478. switchCovergeButton.disabled = false;
  1479. teleportBtn.disabled = true;
  1480. teleportBtn.style.backgroundColor = "red";
  1481. TeleportArisBtn.style.backgroundColor = "red";
  1482. TeleportArisBtn.disabled = true;
  1483. timeMachineBtn.style.backgroundColor = "red";
  1484. timeMachineBtn.disabled = true;
  1485. }
  1486. else if (cond == "Kakao" || cond == "Yandex" || cond == "Mapillary") {
  1487. teleportMoreBtn.style.backgroundColor = "#4CAF50";
  1488. teleportMoreBtn.disabled = false;
  1489. teleportLessBtn.style.backgroundColor = "#4CAF50";
  1490. teleportLessBtn.disabled = false;
  1491. teleportDistResetBtn.style.backgroundColor = "#4CAF50";
  1492. teleportDistResetBtn.disabled = false;
  1493. switchCovergeButton.style.backgroundColor = "#4CAF50";
  1494. switchCovergeButton.disabled = false;
  1495. teleportBtn.disabled = false;
  1496. teleportBtn.style.backgroundColor = "#4CAF50";
  1497. TeleportArisBtn.disabled = false;
  1498. TeleportArisBtn.style.backgroundColor = "#4CAF50";
  1499. timeMachineBtn.style.backgroundColor = "red";
  1500. timeMachineBtn.disabled = true;
  1501. }
  1502. timeMachineNewerBtn.style.backgroundColor = "red";
  1503. timeMachineNewerBtn.disabled = true;
  1504. timeMachineOlderBtn.style.backgroundColor = "red";
  1505. timeMachineOlderBtn.disabled = true;
  1506. }
  1507. }
  1508.  
  1509.  
  1510. /**
  1511. * This observer stays alive while the script is running
  1512. */
  1513.  
  1514. function launchObserver() {
  1515. UnityInitiate();
  1516. BYKTeleport();
  1517. SyncListener();
  1518. kBoard();
  1519. console.log("Main Observer");
  1520. const OBSERVER = new MutationObserver((mutations, observer) => {
  1521. detectGamePage();
  1522. });
  1523. observerCallback(OBSERVER)
  1524. }
  1525. function observerCallback(obs)
  1526. {
  1527. if (obs)
  1528. {
  1529. obs.observe(document.head, { attributes: true, childList: true, subtree: true });
  1530. }
  1531. else
  1532. {
  1533. setTimeout(observerCallback, 250);
  1534. }
  1535. }
  1536.  
  1537. /**
  1538. * Once the Google Maps API was loaded we can do more stuff
  1539. */
  1540.  
  1541. window.addEventListener('DOMContentLoaded', (event) => {
  1542. injecter(() => {
  1543. launchObserver();
  1544. })
  1545. });
  1546.  
  1547.  
  1548.  
  1549. /**
  1550. * Check whether the current page is a game, if so which game mode
  1551. */
  1552.  
  1553. function detectGamePage() {
  1554. if (document.querySelector(".game-layout__panorama-message") !== null && !one_reset)
  1555. {
  1556. one_reset = true;
  1557. console.log("Hide fail to load panorama canvas");
  1558. document.querySelector(".game-layout__panorama-message").style.visibility = "hidden";
  1559. }
  1560. function loadModule()
  1561. {
  1562. if (toLoad) {
  1563. initializeCanvas();
  1564. }
  1565. waitLoad();
  1566. }
  1567. let toLoad = !playerLoaded && !YandexPlayer && !KakaoPlayer && !MapillaryPlayer && !YANDEX_INJECTED && !KAKAO_INJECTED && !MAPILLARY_INJECTED
  1568. const PATHNAME = window.location.pathname;
  1569. if (PATHNAME.startsWith("/game/") || PATHNAME.startsWith("/challenge/")) {
  1570. // console.log("Game page");
  1571. isBattleRoyale = false;
  1572. isDuel = false;
  1573. loadModule();
  1574. }
  1575. else if (PATHNAME.startsWith("/battle-royale/")) {
  1576. if (document.querySelector(".br-game-layout") == null) {
  1577. // console.log("Battle Royale Lobby");
  1578. rstValues();
  1579. }
  1580. else {
  1581. // console.log("Battle Royale");
  1582. isBattleRoyale = true;
  1583. isDuel = false;
  1584. loadModule();
  1585. }
  1586. }
  1587. else if (PATHNAME.startsWith("/duels/") || PATHNAME.startsWith("/team-duels/")) {
  1588. if (document.querySelector(".game_layout__TO_jf") == null) {
  1589. // console.log("Battle Royale Lobby");
  1590. rstValues();
  1591. }
  1592. else {
  1593. // console.log("Duels");
  1594. isBattleRoyale = true;
  1595. isDuel = true;
  1596. loadModule();
  1597. }
  1598. }
  1599. else {
  1600. rstValues();
  1601. //console.log("Not a Game page");
  1602. }
  1603. }
  1604.  
  1605. function rstValues()
  1606. {
  1607. ROUND = 0;
  1608. YandexPlayer = null;
  1609. KakaoPlayer = null;
  1610. MapillaryPlayer = null;
  1611.  
  1612. BAIDU_INJECTED = false;
  1613. YANDEX_INJECTED = false;
  1614. KAKAO_INJECTED = false;
  1615. MAPILLARY_INJECTED = false;
  1616.  
  1617. nextPlayer = "Google"
  1618. global_lat = 0;
  1619. global_lng = 0;
  1620. global_panoID = null;
  1621. global_BDAh = null;
  1622. global_BDBh = null;
  1623. global_BDID = null;
  1624. yId = null;
  1625. yTime = null;
  1626. yEnd = null;
  1627. iId = null;
  1628.  
  1629. COMPASS = null;
  1630. eventListenerAttached = false;
  1631. povListenerAttached = false;
  1632. playerLoaded = false;
  1633. locHistory = [];
  1634. one_reset = false;
  1635. setHidden(true);
  1636. yandex_map = false;
  1637. Kakao_map = false;
  1638. mmKey = 0;
  1639. CURRENT_ROUND_DATA = null;
  1640.  
  1641. linksList = [];
  1642. }
  1643.  
  1644. /**
  1645. * Wait for various players to load
  1646. */
  1647.  
  1648. function waitLoad() {
  1649. if (!YandexPlayer || !KakaoPlayer || !MapillaryPlayer || !YANDEX_INJECTED || !KAKAO_INJECTED || !MAPILLARY_INJECTED) {
  1650. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1651. if (document.querySelector(".br-game-layout__panorama-canvas") != null)
  1652. {
  1653. AdjustBtnPos("-6em + 2px", "300px");
  1654. }
  1655. else if (document.querySelector(".game-panorama_panorama__rdhFg") != null)
  1656. {
  1657. AdjustBtnPos("2em", "0em");
  1658. }
  1659. else
  1660. {
  1661. AdjustBtnPos("0em", "0em");
  1662. }
  1663. setTimeout(waitLoad, 250);
  1664. } else {
  1665. checkRound();
  1666. }
  1667. }
  1668.  
  1669. /**
  1670. * Checks for round changes
  1671. */
  1672.  
  1673. function checkRound() {
  1674. // console.log("Check Round");
  1675. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1676.  
  1677. if (!isBattleRoyale) {
  1678. // console.log("Check Round");
  1679. let currentRound = getRoundFromPage();
  1680. if (ROUND != currentRound) {
  1681. fire1 = true;
  1682. switchCovergeButton.init = true;
  1683. console.log("New round");
  1684. ROUND = currentRound;
  1685. // NEW_ROUND_LOADED = true;
  1686. COMPASS = null;
  1687. locHistory = [];
  1688. one_reset = false;
  1689. getMapData();
  1690. nextButtonCallback();
  1691. }
  1692. }
  1693. else {
  1694. getMapData();
  1695. }
  1696. }
  1697.  
  1698. /**
  1699. * Add listeners if buttons have been created
  1700. */
  1701.  
  1702. function finalDetail()
  1703. {
  1704. let target = document.querySelector("a[data-qa='play-same-map']");
  1705. if (target)
  1706. {
  1707. var div = document.createElement("div");
  1708. div.classList.add("buttons_buttons__0B3SB")
  1709. document.querySelector('.result-layout_content__jAHfP').appendChild(div);
  1710. for (var rd of linksList)
  1711. {
  1712. console.log(rd)
  1713. let cl = target.cloneNode( true );
  1714. let tx = "View R" + rd[0] + " in " + rd[1];
  1715. cl.querySelector('.button_label__kpJrA').innerHTML = tx;
  1716. cl.removeAttribute('data-qa');
  1717. cl.removeAttribute('href');
  1718. cl.urlStr = rd[2];
  1719. cl.addEventListener("click", (e) => {
  1720. window.open(cl.urlStr);
  1721. })
  1722. cl.style = "top:10px;right:-10px;";
  1723. div.appendChild(cl);
  1724. }
  1725. }
  1726. else
  1727. {
  1728. setTimeout(finalDetail, 500);
  1729. }
  1730. }
  1731.  
  1732. function nextButtonCallback()
  1733. {
  1734. let nextButton = document.querySelector("button[data-qa='close-round-result']");
  1735. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1736. if (nextButton != null && fire1)
  1737. {
  1738. fire1 = false;
  1739. nextButton.addEventListener("click", (e) => {
  1740. if (mainMenuBtn != null && !cn_tips && ROUND !== 5)
  1741. {
  1742. console.log("try to show show buttons")
  1743. mainMenuBtn.style.visibility = "";
  1744. }
  1745. if (ROUND == 5)
  1746. {
  1747. console.log("Game Finished")
  1748. if (linksList)
  1749. {
  1750. finalDetail();
  1751. }
  1752. }
  1753. })
  1754. let urlStr = ""
  1755.  
  1756. if (nextPlayer !== "Google")
  1757. {
  1758. console.log("Clone buttons");
  1759. let clone = document.querySelector("button[data-qa='close-round-result']").cloneNode( true );
  1760. let tx = "View Location in " + nextPlayer;
  1761. clone.querySelector('.button_label__kpJrA').innerHTML = tx;
  1762. clone.setAttribute('id', "LinkBtn");
  1763. clone.removeAttribute('data-qa');
  1764. if (nextPlayer == "Baidu")
  1765. {
  1766. urlStr = "https://map.baidu.com/?panotype=street&pid=" + global_BDID + "&panoid=" + global_BDID + "&from=api";
  1767. }
  1768. else if (nextPlayer == "Youtube")
  1769. {
  1770. urlStr = "https://www.youtube.com/watch?v=" + yId;
  1771. }
  1772. else if (nextPlayer == "Image")
  1773. {
  1774. urlStr = iId;
  1775. }
  1776. else if (nextPlayer == "Kakao")
  1777. {
  1778. urlStr = "https://map.kakao.com/link/roadview/" + global_lat + "," + global_lng;
  1779. }
  1780. else if (nextPlayer == "Mapillary")
  1781. {
  1782. urlStr = "https://www.mapillary.com/app/?pKey=" + mmKey + "&focus=photo";
  1783. }
  1784. else if (nextPlayer == "Yandex")
  1785. {
  1786. urlStr = "https://yandex.com/maps/?&panorama%5Bdirection%5D=16%2C0&panorama%5Bpoint%5D=" + global_lng + "%2C" + global_lat;
  1787. }
  1788. clone.addEventListener("click", (e) => {
  1789. window.open(urlStr);
  1790. })
  1791. if (ROUND == 5)
  1792. {
  1793. clone.style = "top:10px;";
  1794. }
  1795. else
  1796. {
  1797. clone.style = "right:-10px;";
  1798. }
  1799. linksList.push([ROUND, nextPlayer, urlStr]);
  1800. document.querySelector('.round-result_actions__5j26U').appendChild(clone);
  1801. }
  1802. }
  1803. else
  1804. {
  1805. setTimeout(nextButtonCallback, 500);
  1806. }
  1807. }
  1808.  
  1809. function guessButtonCallback()
  1810. {
  1811. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1812. let guessButton = document.querySelector("button[data-qa='perform-guess']");
  1813. if (guessButton != null)
  1814. {
  1815.  
  1816. guessButton.addEventListener("click", (e) => {
  1817. if (mainMenuBtn != null)
  1818. {
  1819. console.log("try to hide show buttons")
  1820. mainMenuBtn.style.visibility = "hidden";
  1821. setHidden(true);
  1822. }
  1823. })
  1824. }
  1825. else
  1826. {
  1827. setTimeout(guessButtonCallback, 500);
  1828. }
  1829. }
  1830.  
  1831. /**
  1832. * Load different streetview players
  1833. */
  1834.  
  1835. function injectYandex()
  1836. {
  1837. injectYandexScript().then(() => {
  1838. console.log("Ready to inject Yandex player");
  1839. injectYandexPlayer();
  1840. }).catch((error) => {
  1841. console.log(error);
  1842. });
  1843. }
  1844.  
  1845. function loadPlayers() {
  1846. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  1847. playerLoaded = true;
  1848. injectContainer();
  1849. if (!isBattleRoyale)
  1850. {
  1851.  
  1852. getSeed().then((data) => {
  1853. // console.log(data);
  1854. if (data.mapName.includes("A United World") || data.mapName.includes("Unity Showcase"))
  1855. {
  1856. console.log("Complete Map");
  1857. injectYandex();
  1858. injectKakaoScript().then(() => {
  1859. console.log("Ready to inject Kakao player");
  1860. }).catch((error) => {
  1861. console.log(error);
  1862. });
  1863. }
  1864. else
  1865. {
  1866. if (data.mapName.includes("Yandex"))
  1867. {
  1868. console.log("Yandex Map");
  1869. yandex_map = true;
  1870. injectYandex();
  1871. }
  1872. else
  1873. {
  1874. console.log("Not Yandex map");
  1875. YANDEX_INJECTED = true;
  1876. YandexPlayer = "YD";
  1877. }
  1878.  
  1879. if (data.mapName.includes("Kakao"))
  1880. {
  1881. console.log("Kakao Map");
  1882. Kakao_map = true;
  1883. injectKakaoScript().then(() => {
  1884. console.log("Ready to inject Kakao player");
  1885. }).catch((error) => {
  1886. console.log(error);
  1887. });
  1888. }
  1889. else{
  1890. KAKAO_INJECTED = true;
  1891. KakaoPlayer = "KK";
  1892. console.log("Not Kakao map");
  1893. }
  1894. if (!data.mapName.includes("China Tips for each province"))
  1895. {
  1896. cn_tips = false;
  1897. mainMenuBtn.style.visibility = "";
  1898. setHidden(false);
  1899. }
  1900. else
  1901. {
  1902. cn_tips = true;
  1903. guaranteeUI();
  1904. }
  1905. }
  1906.  
  1907. }).catch((error) => {
  1908. console.log(error);
  1909. });
  1910. }
  1911. else
  1912. {
  1913. if (BR_LOAD_YANDEX)
  1914. {
  1915. console.log("BR load Yandex");
  1916. injectYandex();
  1917. }
  1918. else
  1919. {
  1920. console.log("BR not load Yandex");
  1921. YANDEX_INJECTED = true;
  1922. YandexPlayer = "YD";
  1923. }
  1924.  
  1925. if (BR_LOAD_KAKAO)
  1926. {
  1927. console.log("BR load Kakao");
  1928. injectKakaoScript().then(() => {
  1929. console.log("Ready to inject Kakao player");
  1930. }).catch((error) => {
  1931. console.log(error);
  1932. });
  1933. }
  1934. else{
  1935. KAKAO_INJECTED = true;
  1936. KakaoPlayer = "KK";
  1937. console.log("BR not load Kakao");
  1938. }
  1939. // injectYandex();
  1940. // injectKakaoScript().then(() => {
  1941. // console.log("Ready to inject Kakao player");
  1942. // }).catch((error) => {
  1943. // console.log(error);
  1944. // });
  1945. }
  1946. }
  1947.  
  1948. function guaranteeUI()
  1949. {
  1950. // console.log("UI")
  1951. if (document.getElementById("GH-ui") !== null)
  1952. {
  1953. document.getElementById("GH-ui").style.display = "block";
  1954. }
  1955. else
  1956. {
  1957. setTimeout(guaranteeUI, 500);
  1958. }
  1959. }
  1960.  
  1961. /**
  1962. * Handles Return to start and undo
  1963. */
  1964.  
  1965. function handleReturnToStart() {
  1966. let rtsButton = document.querySelector("button[data-qa='return-to-start']");
  1967. if (rtsButton != null) {
  1968. console.log("handleReturnToStart listener attached");
  1969. rtsButton.addEventListener("click", (e) => {
  1970. if (nextPlayer != "Baidu")
  1971. {
  1972. goToLocation();
  1973. }
  1974. else
  1975. {
  1976. document.getElementById("i_container").src = "https://map.baidu.com/?panotype=street&pid=" + global_BDID + "&panoid=" + global_BDID + "&from=api";
  1977. }
  1978. const elementClicked = e.target;
  1979. elementClicked.setAttribute('listener', 'true');
  1980. console.log("Return to start");
  1981. });
  1982. guessButtonCallback();
  1983. setTimeout(function () {goToLocation();}, 1000);
  1984. }
  1985. else
  1986. {
  1987. setTimeout(handleReturnToStart, 500);
  1988. }
  1989. }
  1990.  
  1991. function handleUndo() {
  1992. let undoButton = document.querySelector("button[data-qa='undo-move']");
  1993. if (undoButton != null)
  1994. {
  1995. console.log("Attach undo");
  1996. undoButton.addEventListener("click", (e) => {
  1997. if (locHistory.length > 0) {
  1998. goToUndoMove();
  1999. console.log("Undo Move");
  2000. }
  2001. })
  2002. }
  2003. else
  2004. {
  2005. setTimeout(handleUndo, 500);
  2006. }
  2007. }
  2008.  
  2009. /**
  2010. * Load game information
  2011. */
  2012.  
  2013. function getMapData() {
  2014. // myHighlight("Seed data");
  2015. getSeed().then((data) => {
  2016. // myHighlight("Seed data");
  2017. // console.log(data);
  2018. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2019. if (isBattleRoyale) {
  2020. if ((document.querySelector(".br-game-layout") == null && document.querySelector(".version3-in-game_layout__Hi_Iw") == null) || typeof data.gameId == typeof undefined) {
  2021. // console.log("Battle Royale Lobby");
  2022. }
  2023. else
  2024. {
  2025. let origin = false;
  2026. if (!CURRENT_ROUND_DATA) {
  2027. CURRENT_ROUND_DATA = data
  2028. origin = true;
  2029. }
  2030.  
  2031. if (origin || !(data.currentRoundNumber === CURRENT_ROUND_DATA.currentRoundNumber)) {
  2032. // myHighlight("Battle Royale New round");
  2033. switchCovergeButton.init = true;
  2034. // NEW_ROUND_LOADED = true;
  2035. COMPASS = null;
  2036. locHistory = [];
  2037. one_reset = false;
  2038. setHidden(false);
  2039. if (!origin) {
  2040. CURRENT_ROUND_DATA = data;
  2041. }
  2042. locationCheck(data);
  2043. // console.log(data);
  2044. if (data.currentRoundNumber == 1)
  2045. {
  2046. setTimeout(function () {goToLocation();}, 3000);
  2047. }
  2048. else
  2049. {
  2050. goToLocation();
  2051. }
  2052. handleReturnToStart();
  2053. if (isDuel)
  2054. {
  2055. handleUndo();
  2056. hideButtons();
  2057. }
  2058. handleMinimapCallback();
  2059.  
  2060. }
  2061. }
  2062. }
  2063. else {
  2064. if (!cn_tips)
  2065. {
  2066. mainMenuBtn.style.visibility = "";
  2067. }
  2068. else
  2069. {
  2070. mainMenuBtn.style.visibility = "hidden";
  2071. AdjustBtnPos("14em", "0em");
  2072. }
  2073. locationCheck(data);
  2074. if (data.currentRoundNumber == 1)
  2075. {
  2076. setTimeout(function () {goToLocation();}, 3000);
  2077. }
  2078. else
  2079. {
  2080. goToLocation();
  2081. }
  2082. handleReturnToStart();
  2083. handleUndo();
  2084. hideButtons();
  2085. handleMinimapCallback();
  2086. }
  2087. }).catch((error) => {
  2088. console.log(error);
  2089. });
  2090. }
  2091.  
  2092. function handleMinimapCallback()
  2093. {
  2094. let trueCond = true;
  2095. let timeoutTime = 250;
  2096. if (isBattleRoyale) {
  2097. if (isDuel)
  2098. {
  2099. if (document.querySelector(".overlay_overlay__AR02x"))
  2100. {
  2101. trueCond = false;
  2102. }
  2103. else
  2104. {
  2105. trueCond = true;
  2106. }
  2107. }
  2108. else
  2109. {
  2110. if (document.querySelector(".popup__content"))
  2111. {
  2112. trueCond = false;
  2113. }
  2114. else
  2115. {
  2116. trueCond = true;
  2117. }
  2118. }
  2119. timeoutTime = 2500;
  2120. }
  2121.  
  2122. if (trueCond)
  2123. {
  2124. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2125. let cur = MinimapBtn.current;
  2126. console.log(cur)
  2127. for (let mapDiv of document.getElementsByClassName("preset-minimap")){
  2128. if (cur == mapDiv.id)
  2129. {
  2130. setTimeout(function () {mapDiv.click();}, 500);
  2131. setTimeout(function () {mapDiv.click();}, 1000);
  2132. setTimeout(function () {mapDiv.click();}, 3000);
  2133. }
  2134. }
  2135. }
  2136. else
  2137. {
  2138. setTimeout(handleMinimapCallback, 250);
  2139. }
  2140. }
  2141.  
  2142. /**
  2143. * Hide unnecessary buttons for non-Google coverages
  2144. */
  2145.  
  2146. function hideButtons() {
  2147. let CHECKPOINT = document.querySelector("button[data-qa='set-checkpoint']");
  2148. let ZOOM_IN = document.querySelector("button[data-qa='pano-zoom-in']");
  2149. let ZOOM_OUT = document.querySelector("button[data-qa='pano-zoom-out']");
  2150.  
  2151. if (CHECKPOINT != null)
  2152. {
  2153. if (nextPlayer === "Google") {
  2154.  
  2155. CHECKPOINT.style.visibility = "";
  2156. ZOOM_IN.style.visibility = "";
  2157. ZOOM_OUT.style.visibility = "";
  2158. console.log("Buttons Unhidden");
  2159.  
  2160. }
  2161. else {
  2162.  
  2163. CHECKPOINT.style.visibility = "hidden";
  2164. ZOOM_IN.style.visibility = "hidden";
  2165. ZOOM_OUT.style.visibility = "hidden";
  2166. console.log("Buttons Hidden");
  2167.  
  2168. }
  2169. }
  2170. else
  2171. {
  2172. setTimeout(hideButtons, 250);
  2173. }
  2174. }
  2175.  
  2176. /**
  2177. * Check which player to use for the next location
  2178. */
  2179.  
  2180. function locationCheck(data) {
  2181. // console.log(data);
  2182. let round;
  2183. if (isBattleRoyale) {
  2184. if (isDuel)
  2185. {
  2186. round = data.rounds[data.currentRoundNumber - 1].panorama;
  2187. }
  2188. else
  2189. {
  2190. round = data.rounds[data.currentRoundNumber - 1];
  2191. }
  2192. }
  2193. else {
  2194. round = data.rounds[data.round - 1];
  2195. }
  2196. global_lat = round.lat;
  2197. global_lng = round.lng;
  2198. global_panoID = round.panoId;
  2199. global_heading = round.heading;
  2200. global_pitch = round.pitch;
  2201. // console.log(global_lat);
  2202. // console.log(global_lng);
  2203. // console.log(krCoordinates);
  2204.  
  2205. nextPlayer = "Google";
  2206. // console.log(global_panoID)
  2207.  
  2208. if (Kakao_map)
  2209. {
  2210. nextPlayer = "Kakao";
  2211. }
  2212. else if (yandex_map)
  2213. {
  2214. nextPlayer = "Yandex";
  2215. }
  2216. else
  2217. {
  2218. if (global_panoID) {
  2219. let locInfo = hex2a(global_panoID);
  2220. // console.log(locInfo)
  2221. let mapType = locInfo.substring(0, 5);
  2222. if (mapType === "BDMAP") {
  2223. nextPlayer = "Baidu";
  2224. let coord = locInfo.substring(5);
  2225.  
  2226. if(coord.includes('BDAh'))
  2227. {
  2228. global_BDID = coord.split('BDAh')[0].replace("panoId","");
  2229. let tem = coord.split('BDAh')[1];
  2230. global_BDAh = tem.split('BDBh')[0];
  2231. global_BDBh = tem.split('BDBh')[1];
  2232. }
  2233. else
  2234. {
  2235. global_BDID = coord.replace("panoId","");
  2236. }
  2237. // console.log(global_BDID)
  2238. // console.log(global_BDAh)
  2239. // console.log(global_BDBh)
  2240. // global_lat = coord.split(",")[0];
  2241. // global_lng = coord.split(",")[1];
  2242. // console.log(global_lat);
  2243. }
  2244. else if (mapType === "MLMAP") {
  2245. nextPlayer = "Mapillary";
  2246. mmKey = locInfo.substring(5);
  2247. }
  2248. else if (mapType === "YDMAP" ) {
  2249. nextPlayer = "Yandex";
  2250. }
  2251. else if (mapType === "KKMAP" ) {
  2252. nextPlayer = "Kakao";
  2253. }
  2254. else if (mapType === "YTUBE" )
  2255. {
  2256. nextPlayer = "Youtube";
  2257. let fullID = locInfo.substring(5).split('START');
  2258. yId = fullID[0];
  2259. yTime = fullID[1].split('END')[0];
  2260. yEnd = fullID[1].split('END')[1];
  2261. }
  2262. else if (mapType === "IMAGE" )
  2263. {
  2264. nextPlayer = "Image";
  2265. iId = locInfo.substring(5);
  2266. }
  2267. }
  2268. }
  2269.  
  2270. // if ( krCoordinates[0] > global_lat && krCoordinates[2] < global_lat && krCoordinates[1] < global_lng && krCoordinates[3] > global_lng)
  2271. // {
  2272. // nextSecondaryPlayer = "Kakao";
  2273. // }
  2274. // else if (nextPlayer = "Mapillary")
  2275. // {
  2276. // nextSecondaryPlayer = "Google";
  2277. // }
  2278. // else
  2279. // {
  2280. // nextSecondaryPlayer = "Mapillary";
  2281. // }
  2282.  
  2283. // Disable buttons if NM, NMPZ
  2284.  
  2285. if(!isBattleRoyale)
  2286. {
  2287. if (data.forbidMoving || data.forbidRotating || data.forbidZooming)
  2288. {
  2289. setDisable("NMPZ");
  2290. }
  2291. else
  2292. {
  2293. setDisable(nextPlayer);
  2294. }
  2295. }
  2296. else
  2297. {
  2298. if (data.movementOptions.forbidMoving || data.movementOptions.forbidRotating || data.movementOptions.forbidZooming)
  2299. {
  2300. setDisable("NMPZ");
  2301. }
  2302. else
  2303. {
  2304. setDisable(nextPlayer);
  2305. }
  2306. }
  2307.  
  2308. console.log(nextPlayer);
  2309. injectCanvas();
  2310. }
  2311.  
  2312.  
  2313. /**
  2314. * setID for canvas
  2315. */
  2316.  
  2317. function initializeCanvas() {
  2318. let GAME_CANVAS = "";
  2319. let DUEL_CANVAS = "";
  2320. //console.log("Is duels");
  2321. //console.log(duels);
  2322.  
  2323. if (isBattleRoyale) {
  2324. if (isDuel) {
  2325. GAME_CANVAS = document.querySelector(".game-panorama_panorama__rdhFg");
  2326. DUEL_CANVAS = document.querySelector(".game-panorama_panoramaCanvas__PNKve");
  2327. }
  2328. else
  2329. {
  2330. GAME_CANVAS = document.querySelector(".br-game-layout__panorama-wrapper");
  2331. DUEL_CANVAS = "dummy";
  2332. }
  2333. }
  2334. else {
  2335. GAME_CANVAS = document.querySelector(".game-layout__canvas");
  2336. DUEL_CANVAS = "dummy";
  2337. }
  2338. if (GAME_CANVAS && DUEL_CANVAS)
  2339. {
  2340. // console.log("Canvas injected");
  2341. GAME_CANVAS.id = "player";
  2342. if (isDuel) {
  2343. DUEL_CANVAS.id = "default_player";
  2344. }
  2345. loadPlayers();
  2346. injectMapillaryPlayer();
  2347. }
  2348. else
  2349. {
  2350. setTimeout(initializeCanvas, 250);
  2351. }
  2352.  
  2353. }
  2354.  
  2355. /**
  2356. * Hide or show players based on where the next location is
  2357. */
  2358.  
  2359. function injectCanvas() {
  2360. if (isDuel)
  2361. {
  2362. canvasSwitch();
  2363. }
  2364. else
  2365. {
  2366. Google();
  2367. Baidu();
  2368. Kakao();
  2369. Yandex();
  2370. Mapillary();
  2371. }
  2372. ZoomControls();
  2373. }
  2374.  
  2375. // for duels (class ID change)
  2376.  
  2377. function canvasSwitch()
  2378. {
  2379. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2380. if (document.querySelector(".compass") !== null && document.querySelector("button[data-qa='undo-move']") !== null)
  2381. {
  2382. let GOOGLE_MAPS_CANVAS = document.querySelector(".game-panorama_panoramaCanvas__PNKve");
  2383. document.querySelector(".ymaps-2-1-79-panorama-screen").style.position = "absolute";
  2384. if (nextPlayer === "Google") {
  2385. document.getElementById("default_player").className = "game-panorama_panoramaCanvas__PNKve";
  2386. document.getElementById("i_container").className = "inactive";
  2387. document.getElementById("roadview").className = "inactive";
  2388. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  2389. teleportBtn.google = true;
  2390. switchCovergeButton.nextPlayer = "Google";
  2391. switchCovergeButton.useGoogle = true;
  2392. document.getElementById("default_player").style.position = "absolute";
  2393. document.querySelector(".compass").style.visibility = "";
  2394. document.querySelector("button[data-qa='undo-move']").visibility = "";
  2395. console.log("Google Duel Canvas loaded");
  2396. }
  2397. else if (nextPlayer === "Baidu" || nextPlayer === "Youtube" || nextPlayer === "Image")
  2398. {
  2399. document.getElementById("default_player").className = "inactive";
  2400. document.getElementById("i_container").className = "game-panorama_panorama__rdhFg";
  2401. document.getElementById("roadview").className = "inactive";
  2402. document.getElementById("mapillary-player").style.visibility = "hidden";
  2403. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  2404. teleportBtn.google = false;
  2405. switchCovergeButton.nextPlayer = "Baidu";
  2406. switchCovergeButton.useGoogle = false;
  2407. document.getElementById("i_container").style.position = "absolute";
  2408. document.querySelector(".compass").style.visibility = "hidden";
  2409. document.querySelector("button[data-qa='undo-move']").visibility = "hidden";
  2410. console.log("Container Duel Canvas loaded");
  2411. }
  2412. else if (nextPlayer === "Kakao")
  2413. {
  2414. document.getElementById("default_player").className = "inactive";
  2415. document.getElementById("i_container").className = "inactive";
  2416. document.getElementById("roadview").className = "game-panorama_panorama__rdhFg";
  2417. document.getElementById("mapillary-player").style.visibility = "hidden";
  2418. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  2419. teleportBtn.google = false;
  2420. switchCovergeButton.nextPlayer = "Kakao";
  2421. switchCovergeButton.useGoogle = false;
  2422. document.getElementById("roadview").style.position = "absolute";
  2423. document.querySelector(".compass").style.visibility = "";
  2424. document.querySelector("button[data-qa='undo-move']").visibility = "";
  2425. console.log("Kakao Duel Canvas loaded");
  2426. }
  2427. else if (nextPlayer === "Yandex")
  2428. {
  2429. document.getElementById("default_player").className = "inactive";
  2430. document.getElementById("i_container").className = "inactive";
  2431. document.getElementById("roadview").className = "inactive";
  2432. document.getElementById("mapillary-player").style.visibility = "hidden";
  2433. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "";
  2434. teleportBtn.google = false;
  2435. switchCovergeButton.nextPlayer = "Yandex";
  2436. switchCovergeButton.useGoogle = false;
  2437. document.querySelector(".ymaps-2-1-79-panorama-screen").style.position = "absolute";
  2438. document.querySelector(".compass").style.visibility = "";
  2439. document.querySelector("button[data-qa='undo-move']").visibility = "";
  2440. console.log("Yandex Duel Canvas loaded");
  2441. }
  2442. else if (nextPlayer === "Mapillary")
  2443. {
  2444. document.getElementById("default_player").className = "inactive";
  2445. document.getElementById("i_container").className = "inactive";
  2446. document.getElementById("roadview").className = "inactive";
  2447. document.getElementById("mapillary-player").style.visibility = "";
  2448. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  2449. teleportBtn.google = false;
  2450. switchCovergeButton.nextPlayer = "Mapillary";
  2451. switchCovergeButton.useGoogle = false;
  2452. document.getElementById("mapillary-player").style.position = "absolute";
  2453. document.querySelector(".compass").style.visibility = "hidden";
  2454. document.querySelector("button[data-qa='undo-move']").visibility = "";
  2455. console.log("Mapillary Duel Canvas loaded");
  2456. }
  2457. }
  2458. else
  2459. {
  2460. setTimeout(canvasSwitch, 250);
  2461. }
  2462. }
  2463.  
  2464. // for Battle Royale and classic (change visibility)
  2465.  
  2466. function Google() {
  2467. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2468. let GOOGLE_MAPS_CANVAS = ""
  2469. if (isBattleRoyale) {
  2470. GOOGLE_MAPS_CANVAS = document.querySelector(".br-game-layout__panorama-canvas");
  2471. }
  2472. else {
  2473. GOOGLE_MAPS_CANVAS = document.querySelector(".game-layout__panorama-canvas");
  2474. }
  2475. if (nextPlayer === "Google") {
  2476. GOOGLE_MAPS_CANVAS.style.visibility = "";
  2477. teleportBtn.google = true;
  2478. switchCovergeButton.nextPlayer = "Google";
  2479. switchCovergeButton.useGoogle = true;
  2480. console.log("Google Canvas loaded");
  2481. }
  2482. else {
  2483. GOOGLE_MAPS_CANVAS.style.visibility = "hidden";
  2484. teleportBtn.google = false;
  2485. console.log("Google Canvas hidden");
  2486. }
  2487.  
  2488. }
  2489.  
  2490. function Baidu() {
  2491. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2492. let BAIDU_MAPS_CANVAS = document.getElementById("i_container");
  2493. // console.log("Baidu canvas");
  2494. if (BAIDU_MAPS_CANVAS !== null && document.querySelector(".compass") !== null && document.querySelector("button[data-qa='undo-move']") !== null)
  2495. {
  2496. BAIDU_MAPS_CANVAS.style.position = "absolute";
  2497. if (nextPlayer === "Baidu" || nextPlayer === "Youtube" || nextPlayer === "Image") {
  2498. BAIDU_MAPS_CANVAS.style.visibility = "";
  2499. switchCovergeButton.nextPlayer = "Baidu";
  2500. switchCovergeButton.useGoogle = false;
  2501. document.querySelector(".compass").style.visibility = "hidden";
  2502. document.querySelector("button[data-qa='undo-move']").style.visibility = "hidden";
  2503. console.log("Container Canvas loaded");
  2504. }
  2505. else {
  2506. document.querySelector(".compass").style.visibility = "";
  2507. document.querySelector("button[data-qa='undo-move']").style.visibility = "";
  2508. BAIDU_MAPS_CANVAS.style.visibility = "hidden";
  2509. console.log("Container Canvas hidden");
  2510. }
  2511. }
  2512. else
  2513. {
  2514. setTimeout(Baidu, 250);
  2515. }
  2516.  
  2517. }
  2518.  
  2519. function Kakao() {
  2520. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2521. let KAKAO_MAPS_CANVAS = document.getElementById("roadview");
  2522. // console.log("Kakao canvas");
  2523. if (KAKAO_MAPS_CANVAS != null)
  2524. {
  2525. KAKAO_MAPS_CANVAS.style.position = "absolute";
  2526. if (nextPlayer === "Kakao") {
  2527. KAKAO_MAPS_CANVAS.style.visibility = "";
  2528. switchCovergeButton.nextPlayer = "Kakao";
  2529. switchCovergeButton.useGoogle = false;
  2530. console.log("Kakao Canvas loaded");
  2531. }
  2532. else {
  2533. KAKAO_MAPS_CANVAS.style.visibility = "hidden";
  2534. console.log("Kakao Canvas hidden");
  2535. }
  2536. }
  2537. else
  2538. {
  2539. setTimeout(Kakao, 250);
  2540. }
  2541.  
  2542. }
  2543.  
  2544. function Yandex() {
  2545. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2546. let YANDEX_MAPS_CANVAS = document.querySelector(".ymaps-2-1-79-panorama-screen");
  2547. if (YANDEX_MAPS_CANVAS != null)
  2548. {
  2549. // console.log("Yandex canvas");
  2550. document.querySelector(".ymaps-2-1-79-panorama-screen").style.position = "absolute";
  2551. // console.log("Yandex canvas");
  2552. /* console.log(YANDEX_MAPS_CANVAS); */
  2553. if (nextPlayer === "Yandex") {
  2554. YANDEX_MAPS_CANVAS.style.visibility = "";
  2555. switchCovergeButton.nextPlayer = "Yandex";
  2556. switchCovergeButton.useGoogle = false;
  2557. console.log("Yandex Canvas loaded");
  2558. }
  2559. else {
  2560. YANDEX_MAPS_CANVAS.style.visibility = "hidden";
  2561. console.log("Yandex Canvas hidden");
  2562. }
  2563. }
  2564. else
  2565. {
  2566. setTimeout(Yandex, 250);
  2567. }
  2568.  
  2569. }
  2570.  
  2571. function Mapillary()
  2572. {
  2573. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2574. let MAPILLARY_MAPS_CANVAS = document.getElementById("mapillary-player");
  2575. if (MAPILLARY_MAPS_CANVAS != null)
  2576. {
  2577. // console.log("Mapillary canvas");
  2578. MAPILLARY_MAPS_CANVAS.style.position = "absolute";
  2579. if (nextPlayer === "Mapillary") {
  2580. MAPILLARY_MAPS_CANVAS.style.visibility = "";
  2581. switchCovergeButton.nextPlayer = "Mapillary";
  2582. switchCovergeButton.useGoogle = false;
  2583. console.log("Mapillary Canvas loaded");
  2584. }
  2585. else {
  2586. MAPILLARY_MAPS_CANVAS.style.visibility = "hidden";
  2587. console.log("Mapillary Canvas hidden");
  2588. }
  2589. }
  2590. else
  2591. {
  2592. setTimeout(Mapillary, 250);
  2593. }
  2594.  
  2595. }
  2596.  
  2597. /**
  2598. * Adjust button placement
  2599. */
  2600.  
  2601. function ZoomControls() {
  2602. let style = `
  2603. .ymaps-2-1-79-panorama-gotoymaps {display: none !important;}
  2604. .game-layout__controls {bottom: 8rem !important; left: 1rem !important;}
  2605. `;
  2606.  
  2607. let style_element = document.createElement("style");
  2608. style_element.innerHTML = style;
  2609. document.body.appendChild(style_element);
  2610. }
  2611.  
  2612. /**
  2613. * Updates the compass to match Yandex Panorama facing
  2614. */
  2615. function updateCompass() {
  2616. if (!COMPASS) {
  2617. let compass = document.querySelector("img.compass__indicator");
  2618. if (compass != null) {
  2619. COMPASS = compass;
  2620. let direction = YandexPlayer.getDirection()[0] * -1;
  2621. COMPASS.setAttribute("style", `transform: rotate(${direction}deg);`);
  2622. }
  2623. }
  2624. else {
  2625. let direction = YandexPlayer.getDirection()[0] * -1;
  2626. COMPASS.setAttribute("style", `transform: rotate(${direction}deg);`);
  2627. }
  2628. }
  2629.  
  2630. /**
  2631. * Open next location in streetview player given next player and next coordinate
  2632. */
  2633.  
  2634. function goToLocation() {
  2635. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2636. console.log("Going to location");
  2637. if (nextPlayer === "Yandex") {
  2638. let options = {};
  2639. YandexPlayer.moveTo([global_lat, global_lng], options);
  2640. YandexPlayer.setDirection([0, 16]);
  2641. YandexPlayer.setSpan([10, 67]);
  2642. }
  2643. else if (nextPlayer === "Baidu" || nextPlayer === "Youtube" || nextPlayer === "Image") {
  2644. if (document.getElementById("i_container") !== null)
  2645. {
  2646. let iframe = document.getElementById("i_container");
  2647. if (nextPlayer === "Baidu")
  2648. {
  2649. if (!isFirefox)
  2650. {
  2651. iframe.style.top = '-60px';
  2652. iframe.style.height = (window.innerHeight + 200) + 'px';
  2653. }
  2654. else
  2655. {
  2656. iframe.style.top = '-60px';
  2657. iframe.style.height = (window.innerHeight + 219) + 'px';
  2658. }
  2659.  
  2660. if (!isFirefox)
  2661. {
  2662. iframe.style.right = '-55px';
  2663. iframe.style.width = (window.innerWidth + 55) + 'px';
  2664. }
  2665. else
  2666. {
  2667. iframe.style.right = '-15px';
  2668. iframe.style.width = (window.innerWidth + 15) + 'px';
  2669. }
  2670. let urlStr2 = "https://map.baidu.com/?panotype=street&pid=" + global_BDID + "&panoid=" + global_BDID + "&from=api";
  2671. let urlStr = "https://map.baidu.com/@" + global_BDAh + "," + global_BDBh + "#panoid=" + global_BDID + "&panotype=street&l=12&tn=B_NORMAL_MAP&sc=0&newmap=1&shareurl=1&pid=" + global_BDID;
  2672. // console.log(urlStr)
  2673. if (global_BDAh != null)
  2674. {
  2675. iframe.src = urlStr;
  2676. }
  2677. else
  2678. {
  2679. iframe.src = urlStr2;
  2680. }
  2681. iframe.style.visibility = "";
  2682. }
  2683. else if (nextPlayer === "Youtube")
  2684. {
  2685. document.getElementById("Youtube Button").style.visibility = "";
  2686. document.getElementById("Youtube Button").innerHTML = "Play video";
  2687. iframe.allow = "autoplay";
  2688. iframe.style.visibility = "hidden";
  2689. iframe.style.top = '-60px';
  2690. iframe.style.height = (window.innerHeight + 235) + 'px';
  2691. }
  2692. else if (nextPlayer === "Image")
  2693. {
  2694. iframe.style.top = '0px';
  2695. iframe.style.height = (window.innerHeight) + 'px';
  2696. iframe.style.visibility = "";
  2697. iframe.src = iId;
  2698. }
  2699. }
  2700. else
  2701. {
  2702. setTimeout(goToLocation, 250);
  2703. }
  2704. // let a = new BMap.Point(global_lng, global_lat);
  2705. // BaiduPlayer.setPov({ heading: -40, pitch: 6 });
  2706. // BaiduPlayer.setPosition(a);
  2707. }
  2708. else if (nextPlayer === "Kakao") {
  2709. var roadviewClient = new kakao.maps.RoadviewClient();
  2710. var position = new kakao.maps.LatLng(global_lat, global_lng);
  2711. roadviewClient.getNearestPanoId(position, 500, function (panoId) {
  2712. KakaoPlayer.setPanoId(panoId, position);
  2713. KakaoPlayer.setViewpoint({ pan: global_heading, tilt: global_pitch, zoom: -3 })
  2714. });
  2715. }
  2716. else if (nextPlayer === "Mapillary") {
  2717. MapillaryPlayer.moveTo(mmKey).then(
  2718. image => { //console.log(image);
  2719. },
  2720. error => { console.log(error); });
  2721. }
  2722. else if (nextPlayer === "Google") {
  2723. handleMapillary({lat: global_lat, lng: global_lng}, {meters: 500, limit: 500});
  2724. }
  2725. switchCovergeButton.lat = global_lat;
  2726. switchCovergeButton.lng = global_lng;
  2727. }
  2728.  
  2729. /**
  2730. * Handle undo using the location history of the current round
  2731. */
  2732.  
  2733. function goToUndoMove(data) {
  2734. /* console.log(global_lat);
  2735. console.log(global_lng); */
  2736. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2737. let options = {};
  2738. let prevStep = null;
  2739. if (locHistory.length === 1) {
  2740. prevStep = locHistory[0];
  2741. }
  2742. else {
  2743. prevStep = locHistory.pop();
  2744. }
  2745. // console.log(prevStep);
  2746. // console.log(locHistory)
  2747. if (nextPlayer === "Yandex") {
  2748. defaultPanoIdChange = false;
  2749. YandexPlayer.moveTo([prevStep[0], prevStep[1]], options);
  2750. YandexPlayer.setDirection([prevStep[2], prevStep[3]]);
  2751. YandexPlayer.setSpan([10, 67]);
  2752. switchCovergeButton.lat = prevStep[0];
  2753. switchCovergeButton.lng = prevStep[1];
  2754. }
  2755. else if (nextPlayer === "Kakao") {
  2756. let btn = document.querySelector("button[data-qa='undo-move']");
  2757. btn.disabled = false;
  2758. btn.classList.remove('styles_disabled__W_k45');
  2759. defaultPanoIdChange = false;
  2760. let position = new kakao.maps.LatLng(prevStep[0], prevStep[1]);
  2761. KakaoPlayer.setPanoId(prevStep[2], position);
  2762. switchCovergeButton.lat = prevStep[0];
  2763. switchCovergeButton.lng = prevStep[1];
  2764. switchCovergeButton.useGoogle = false;
  2765. teleportBtn.google = false;
  2766. // console.log("Undo 1 step");
  2767. // console.log(locHistory);
  2768. }
  2769. else if (nextPlayer === "Mapillary" ) {
  2770. // console.log(prevStep[1]);
  2771.  
  2772. MapillaryPlayer.moveTo(prevStep[2]).then(
  2773. image => {
  2774. //console.log(image);
  2775. switchCovergeButton.lat = prevStep[1];
  2776. switchCovergeButton.lng = prevStep[0];
  2777. },
  2778. error => { console.log(error); });
  2779. }
  2780.  
  2781. }
  2782.  
  2783. function BYKTeleport()
  2784. {
  2785. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2786. let teleportBtnBYK = teleportBtn;
  2787. if (teleportBtnBYK)
  2788. {
  2789. teleportBtnBYK.addEventListener("click", () => {
  2790. if (!teleportBtnBYK.google)
  2791. {
  2792. // console.log("non-Google Teleport");
  2793. let prevStep = null;
  2794. if (locHistory.length === 1) {
  2795. prevStep = locHistory[0];
  2796. }
  2797. else {
  2798. prevStep = locHistory[locHistory.length - 1];
  2799. }
  2800. // console.log(prevStep);
  2801. let options = {};
  2802. let place, position, pID;
  2803. if (nextPlayer === "Yandex") {
  2804. place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[2]), teleportBtnBYK.distance * 0.001);
  2805. YandexPlayer.setDirection([prevStep[2], prevStep[3]]);
  2806. YandexPlayer.moveTo([place.lat, place.lng], options);
  2807. YandexPlayer.setSpan([10, 67]);
  2808. }
  2809. else if (nextPlayer === "Kakao") {
  2810. var roadviewClient = new kakao.maps.RoadviewClient();
  2811. place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[3]), teleportBtnBYK.distance * 0.001);
  2812. position = new kakao.maps.LatLng(place.lat, place.lng);
  2813. roadviewClient.getNearestPanoId(position, 500, function (panoId) {
  2814. KakaoPlayer.setPanoId(panoId, position);
  2815. });
  2816. }
  2817. else if (nextPlayer === "Mapillary" || nextPlayer === "Google") {
  2818. place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[2]), teleportBtnBYK.distance * 0.001);
  2819. handleMapillary(place, {meters: 500, limit: 500});
  2820. // locHistory.push([place.lat, place.lng, prevStep[2], prevStep[3]]);
  2821. }
  2822. switchCovergeButton.lat = place.lat;
  2823. switchCovergeButton.lng = place.lng;
  2824. if (teleportBtnBYK.distance > 150)
  2825. {
  2826. teleportBtnBYK.distance = 100;
  2827. teleportBtnBYK.innerHTML = "Teleport " + teleportBtnBYK.distance + " m";
  2828. }
  2829. }
  2830. });
  2831. }
  2832. else
  2833. {
  2834. }
  2835. }
  2836.  
  2837. function SyncListener()
  2838. {
  2839. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  2840. switchCovergeButton.addEventListener("click", () => {
  2841. if (switchCovergeButton.useGoogle == false) {
  2842. // switchCovergeButton.useGoogle = true;
  2843. if (switchCovergeButton.nextPlayer === "Yandex") {
  2844. let options = {};
  2845. YandexPlayer.moveTo([switchCovergeButton.lat, switchCovergeButton.lng], options);
  2846. YandexPlayer.setDirection([switchCovergeButton.heading, 0]);
  2847.  
  2848. // switchCovergeButton.nextPlayer = "Yandex";
  2849. }
  2850. else if (switchCovergeButton.nextPlayer === "Kakao") {
  2851. let roadviewClient = new kakao.maps.RoadviewClient();
  2852. // console.log(switchCovergeButton.lat);
  2853. let position = new kakao.maps.LatLng(switchCovergeButton.lat, switchCovergeButton.lng);
  2854. roadviewClient.getNearestPanoId(position, 500, function (panoId) {
  2855. KakaoPlayer.setPanoId(panoId, position);
  2856. });
  2857. KakaoPlayer.setViewpoint({
  2858. pan: switchCovergeButton.heading,
  2859. tilt: 0,
  2860. zoom: -3
  2861. });
  2862. // switchCovergeButton.nextPlayer = "Kakao";
  2863. }
  2864. else if (switchCovergeButton.nextPlayer === "Mapillary" || switchCovergeButton.nextPlayer === "Google") {
  2865. // switchCovergeButton.nextPlayer = "Kakao";
  2866. handleMapillary({lat: switchCovergeButton.lat, lng: switchCovergeButton.lng}, {meters: 100, limit: 100});
  2867. }
  2868. }
  2869. });
  2870.  
  2871. }
  2872.  
  2873. /**
  2874. * Gets the seed data for the current game
  2875. *
  2876. * @returns Promise with seed data as object
  2877. */
  2878. function getSeed() {
  2879. // console.log("getSeed called");
  2880. return new Promise((resolve, reject) => {
  2881. let token = getToken();
  2882. let URL;
  2883. let cred = ""
  2884.  
  2885. const PATHNAME = window.location.pathname;
  2886.  
  2887. if (PATHNAME.startsWith("/game/")) {
  2888. URL = `https://www.geoguessr.com/api/v3/games/${token}`;
  2889. }
  2890. else if (PATHNAME.startsWith("/challenge/")) {
  2891. URL = `https://www.geoguessr.com/api/v3/challenges/${token}/game`;
  2892. }
  2893. else if (PATHNAME.startsWith("/battle-royale/")) {
  2894. URL = `https://game-server.geoguessr.com/api/battle-royale/${token}`;
  2895. }
  2896. else if (PATHNAME.startsWith("/duels/") || PATHNAME.startsWith("/team-duels/")) {
  2897. URL = `https://game-server.geoguessr.com/api/duels/${token}`;
  2898. }
  2899. if (isBattleRoyale) {
  2900. fetch(URL, {
  2901. // Include credentials to GET from the endpoint
  2902. credentials: 'include'
  2903. })
  2904. .then((response) => response.json())
  2905. .then((data) => {
  2906. resolve(data);
  2907. })
  2908. .catch((error) => {
  2909. reject(error);
  2910. });
  2911. }
  2912. else {
  2913. fetch(URL)
  2914. .then((response) => response.json())
  2915. .then((data) => {
  2916. resolve(data);
  2917. })
  2918. .catch((error) => {
  2919. reject(error);
  2920. });
  2921. }
  2922. });
  2923. }
  2924.  
  2925. /**
  2926. * Gets the token from the current URL
  2927. *
  2928. * @returns token
  2929. */
  2930. function getToken() {
  2931. const PATHNAME = window.location.pathname;
  2932. if (PATHNAME.startsWith("/game/")) {
  2933. return PATHNAME.replace("/game/", "");
  2934. }
  2935. else if (PATHNAME.startsWith("/challenge/")) {
  2936. return PATHNAME.replace("/challenge/", "");
  2937. }
  2938. else if (PATHNAME.startsWith("/battle-royale/")) {
  2939. return PATHNAME.replace("/battle-royale/", "");
  2940. }
  2941. else if (PATHNAME.startsWith("/duels/")) {
  2942. return PATHNAME.replace("/duels/", "");
  2943. }
  2944. else if (PATHNAME.startsWith("/team-duels/")) {
  2945. return PATHNAME.replace("/team-duels/", "");
  2946. }
  2947. }
  2948.  
  2949. /**
  2950. * Gets the round number from the ongoing game from the page itself
  2951. *
  2952. * @returns Round number
  2953. */
  2954. function getRoundFromPage() {
  2955. const roundData = document.querySelector("div[data-qa='round-number']");
  2956. if (roundData) {
  2957. let roundElement = roundData.querySelector("div:last-child");
  2958. if (roundElement) {
  2959. let round = parseInt(roundElement.innerText.charAt(0));
  2960. if (!isNaN(round) && round >= 1 && round <= 5) {
  2961. return round;
  2962. }
  2963. }
  2964. }
  2965. else {
  2966. return ROUND;
  2967. }
  2968. }
  2969.  
  2970.  
  2971. /**
  2972. * Injects Yandex Script
  2973. */
  2974. function injectYandexScript() {
  2975. return new Promise((resolve, reject) => {
  2976. if (!YANDEX_INJECTED) {
  2977. if (YANDEX_API_KEY === "") {
  2978. console.log("No Yandex Key")
  2979. reject();
  2980. }
  2981. else {
  2982. const SCRIPT = document.createElement("script");
  2983. SCRIPT.type = "text/javascript";
  2984. SCRIPT.async = true;
  2985. SCRIPT.onload = () => {
  2986. ymaps.ready(() => {
  2987. YANDEX_INJECTED = true;
  2988. myHighlight("Yandex API Loaded");
  2989. resolve();
  2990. });
  2991. }
  2992. SCRIPT.src = `https://api-maps.yandex.ru/2.1/?lang=en_US&apikey=${YANDEX_API_KEY}`;
  2993. document.body.appendChild(SCRIPT);
  2994. }
  2995. }
  2996. else {
  2997. resolve();
  2998. }
  2999. });
  3000. }
  3001.  
  3002. /**
  3003. * Injects Yandex Player and calls handleReturnToStart
  3004. */
  3005. function injectYandexPlayer() {
  3006. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  3007. let lat = 41.321861;
  3008. let lng = 69.212920;
  3009.  
  3010. let options = {
  3011. "direction": [0, 16],
  3012. "span": [10, 67],
  3013. "controls": ["zoomControl"]
  3014. };
  3015. ymaps.panorama.createPlayer("player", [lat, lng], options)
  3016. .done((player) => {
  3017. YandexPlayer = player;
  3018. YandexPlayer.events.add("directionchange", (e) => {
  3019. updateCompass();
  3020. let pov = YandexPlayer.getDirection();
  3021. if (locHistory.length > 0 && nextPlayer == "Yandex") {
  3022. switchCovergeButton.heading = pov[0];
  3023. locHistory[locHistory.length - 1][2] = pov[0];
  3024. locHistory[locHistory.length - 1][3] = pov[1];
  3025. }
  3026. });
  3027. YandexPlayer.events.add("panoramachange", (e) => {
  3028. if (defaultPanoIdChange) {
  3029. let num = YandexPlayer.getPanorama().getPosition();
  3030. let pov = YandexPlayer.getDirection();
  3031. // console.log(num);
  3032. // console.log(pov);
  3033. if (nextPlayer == "Yandex")
  3034. {
  3035. locHistory.push([num[0], num[1], pov[0], pov[1]]);
  3036. switchCovergeButton.lat = num[0];
  3037. switchCovergeButton.lng = num[1];
  3038. }
  3039. let btn = document.querySelector("button[data-qa='undo-move']");
  3040. if (locHistory.length > 1) {
  3041. btn.disabled = false;
  3042. btn.classList.remove('styles_disabled__W_k45');
  3043. }
  3044. // console.log(locHistory);
  3045. }
  3046. defaultPanoIdChange = true;
  3047.  
  3048. });
  3049. console.log("Yandex Player injected");
  3050. });
  3051.  
  3052. }
  3053.  
  3054.  
  3055. /**
  3056. * Injects Baidu script
  3057. */
  3058.  
  3059. function reportWindowSize() {
  3060. let iframeC = document.getElementById("i_container");
  3061. if (iframeC)
  3062. {
  3063. if (nextPlayer == "Baidu")
  3064. {
  3065. iframeC.style.top = '-60px';
  3066. iframeC.style.height = (window.innerHeight + 200) + 'px';
  3067. iframeC.style.right = '-55px';
  3068. iframeC.style.width = (window.innerWidth + 55) + 'px';
  3069. }
  3070. else if (nextPlayer == "Youtube")
  3071. {
  3072. iframeC.style.top = '-60px';
  3073. iframeC.style.height = (window.innerHeight + 235) + 'px';
  3074. }
  3075. else if (nextPlayer == "Image")
  3076. {
  3077. iframeC.style.top = '0px';
  3078. iframeC.style.height = (window.innerHeight) + 'px';
  3079. }
  3080.  
  3081. }
  3082. }
  3083.  
  3084. window.onresize = reportWindowSize;
  3085.  
  3086. function injectContainer() {
  3087. myHighlight("Container loaded")
  3088. const iframe = document.createElement('iframe');
  3089. iframe.frameBorder = 0;
  3090. iframe.style.position = "absolute";
  3091. iframe.id = "i_container";
  3092. if (isBattleRoyale) {
  3093. if (isDuel)
  3094. {
  3095. iframe.className = "inactive"
  3096. }
  3097. else
  3098. {
  3099. iframe.className = "br-game-layout__panorama"
  3100. }
  3101. }
  3102. else {
  3103. iframe.className = "game-layout__panorama"
  3104. }
  3105. var div = document.getElementById("player");
  3106. div.style.overflow = "hidden";
  3107. div.appendChild(iframe);
  3108. }
  3109.  
  3110. // function injectMedia() {
  3111. // myHighlight("Baidu API loaded")
  3112. // const iframe = document.createElement('iframe');
  3113. // iframe.allow = "autoplay"
  3114. // iframe.src = "https://www.youtube.com/embed/72kRM86V-dw?&autoplay=1&modestbranding=1&controls=0&start=10"
  3115. // iframe.frameBorder = 0;
  3116. // iframe.style.position = "absolute";
  3117. // iframe.id = "media-player";
  3118. // iframe.style="position:fixed; top: -60px; left:0; bottom: calc(100% + 175px); right:0; width:100%; height:calc(100% + 235px); border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"
  3119. // if (isBattleRoyale) {
  3120. // if (isDuel)
  3121. // {
  3122. // iframe.className = "inactive"
  3123. // }
  3124. // else
  3125. // {
  3126. // iframe.className = "br-game-layout__panorama"
  3127. // }
  3128. // }
  3129. // else {
  3130. // iframe.className = "game-layout__panorama"
  3131. // }
  3132. // var div = document.getElementById("player");
  3133. // div.style.overflow = "hidden";
  3134. // div.appendChild(iframe);
  3135. // }
  3136.  
  3137. /**
  3138. * Injects Kakao script
  3139. */
  3140.  
  3141. function injectKakaoScript() {
  3142. return new Promise((resolve, reject) => {
  3143. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  3144. if (!KAKAO_INJECTED) {
  3145. if (KAKAO_API_KEY === "") {
  3146. console.log("No Kakao Key")
  3147. }
  3148. else {
  3149.  
  3150. let canvas = document.createElement("kmap");
  3151. if (isBattleRoyale) {
  3152. if (isDuel)
  3153. {
  3154. canvas.innerHTML = `
  3155. <div id="roadview" class="inactive" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  3156. `;
  3157. }
  3158. else
  3159. {
  3160. canvas.innerHTML = `
  3161. <div id="roadview" class="br-game-layout__panorama" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  3162. `;
  3163. }
  3164. }
  3165. else {
  3166. canvas.innerHTML = `
  3167. <div id="roadview" class="game-layout__panorama" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  3168. `;
  3169. }
  3170.  
  3171. var div = document.getElementById("player");
  3172. div.appendChild(canvas);
  3173.  
  3174. const SCRIPT = document.createElement("script");
  3175. SCRIPT.async = true;
  3176. // SCRIPT.type = "text/javascript";
  3177. SCRIPT.src = `//dapi.kakao.com/v2/maps/sdk.js?appkey=${KAKAO_API_KEY}&autoload=false`;
  3178. document.body.appendChild(SCRIPT);
  3179. SCRIPT.onload = () => {
  3180. kakao.maps.load(function () {
  3181. var position = new kakao.maps.LatLng(33.450701, 126.560667);
  3182. let roadviewContainer = document.getElementById('roadview');
  3183. KakaoPlayer = new kakao.maps.Roadview(roadviewContainer);
  3184. var panoId = 1023434522;
  3185. KakaoPlayer.setPanoId(panoId, position);
  3186. KAKAO_INJECTED = true;
  3187. // Remove the compass from Kakao
  3188. kakao.maps.event.addListener(KakaoPlayer, 'init', () => {
  3189. const compassContainer = roadviewContainer.querySelector('div[id*="_box_util_"]');
  3190. if (compassContainer) compassContainer.style.display = 'none';
  3191. });
  3192. kakao.maps.event.addListener(KakaoPlayer, 'panoid_changed', function() {
  3193. if (defaultPanoIdChange && KakaoPlayer) {
  3194. let latlng = KakaoPlayer.getPosition();
  3195. let lat = latlng.getLat();
  3196. let lng = latlng.getLng();
  3197. let pID = KakaoPlayer.getViewpointWithPanoId();
  3198. if (nextPlayer == "Kakao" && lat != 33.45047613915499)
  3199. {
  3200. // console.log("push");
  3201. locHistory.push([lat, lng, pID.panoId, pID.pan]);
  3202. switchCovergeButton.lat = lat;
  3203. switchCovergeButton.lng = lng;
  3204. switchCovergeButton.heading = pID.pan;
  3205. }
  3206. let btn = document.querySelector("button[data-qa='undo-move']");
  3207. if (locHistory.length > 1 && (btn != null)) {
  3208. btn.disabled = false;
  3209. btn.classList.remove('styles_disabled__W_k45');
  3210. }
  3211. // console.log(locHistory);
  3212. }
  3213. defaultPanoIdChange = true;
  3214. });
  3215. kakao.maps.event.addListener(KakaoPlayer, 'viewpoint_changed', function() {
  3216. // console.log("pov_listener attached");
  3217. let pID = KakaoPlayer.getViewpointWithPanoId();
  3218. if (locHistory.length > 0 && nextPlayer == "Kakao") {
  3219. switchCovergeButton.heading = pID.pan;
  3220. locHistory[locHistory.length - 1][3] = pID.pan;
  3221. }
  3222. if (GooglePlayer) {
  3223. const { heading, pitch } = GooglePlayer.getPov()
  3224. if ((!almostEqual(pID.pan, heading) || !almostEqual(pID.tilt, pitch)) && nextPlayer == "Kakao") {
  3225. // Updating the google street view POV will update the compass
  3226. GooglePlayer.setPov({ heading: pID.pan, pitch: pID.tilt })
  3227. }
  3228. }
  3229. // console.log(locHistory);
  3230. })
  3231. myHighlight("Kakao API Loaded");
  3232. resolve();
  3233. });
  3234. };
  3235.  
  3236. }
  3237. }
  3238. else {
  3239. resolve();
  3240. }
  3241. });
  3242. }
  3243.  
  3244.  
  3245.  
  3246. function injectMapillaryPlayer() {
  3247. return new Promise((resolve, reject) => {
  3248. if (!MAPILLARY_INJECTED) {
  3249. if (MAPILLARY_API_KEY === "") {
  3250. let canvas = document.getElementById("player");
  3251. console.log("No Mapillary Key")
  3252. }
  3253. else {
  3254. let [teleportBtn, teleportMoreBtn, teleportLessBtn, teleportDistResetBtn, switchCovergeButton, mainMenuBtn, timeMachineBtn, timeMachineOlderBtn, timeMachineNewerBtn, MinimapBtn, OverlayBtn, HelpBtn, TeleportArisBtn] = setButtons();
  3255.  
  3256. const SCRIPT = document.createElement("script");
  3257. SCRIPT.type = "text/javascript";
  3258. SCRIPT.async = true;
  3259. SCRIPT.src = `https://unpkg.com/mapillary-js@4.0.0/dist/mapillary.js`;
  3260. document.body.appendChild(SCRIPT);
  3261. document.querySelector('head').innerHTML += '<link href="https://unpkg.com/mapillary-js@4.0.0/dist/mapillary.css" rel="stylesheet"/>';
  3262. let canvas = document.createElement("mmap");
  3263. if (isBattleRoyale) {
  3264. if (isDuel)
  3265. {
  3266.  
  3267. canvas.innerHTML = `<div id="mapillary-player" class="inactive" style="zIndex: 99999, position: 'absolute', top: 0, left: 0, width: '100%', height: '100%'"></div>`;
  3268. }
  3269. else
  3270. {
  3271. canvas.innerHTML = `<div id="mapillary-player" class="br-game-layout__panorama" style="zIndex: 99999, position: 'absolute', top: 0, left: 0, width: '100%', height: '100%'"></div>`;
  3272. }
  3273. }
  3274. else {
  3275. canvas.innerHTML = `<div id="mapillary-player" class="game-layout__panorama" style="zIndex: 99999, position: 'absolute', top: 0, left: 0, width: '100%', height: '100%'"></div>`;
  3276. }
  3277.  
  3278. var div = document.getElementById("player");
  3279. div.appendChild(canvas);
  3280.  
  3281. SCRIPT.addEventListener('load', () => {
  3282. myHighlight("Mapillary API Loaded");
  3283. // resolve(BMap);
  3284. var {Viewer} = mapillary;
  3285.  
  3286. MapillaryPlayer = new Viewer({
  3287. accessToken: MAPILLARY_API_KEY,
  3288. container: 'mapillary-player', // the ID of our container defined in the HTML body
  3289. });
  3290.  
  3291. MapillaryPlayer.on('image', async (event) => {
  3292. // cnt = cnt + 1;
  3293. // console.log(cnt);
  3294. let image = event.image;
  3295. let pos = image.originalLngLat;
  3296. let cond = true;
  3297. for (const element of locHistory) {
  3298. if (element[2] == image.id)
  3299. {
  3300. cond = false;
  3301. }
  3302. }
  3303. if (cond)
  3304. {
  3305. switchCovergeButton.lat = pos.lat;
  3306. switchCovergeButton.lng = pos.lng;
  3307. switchCovergeButton.heading = image.compassAngle;
  3308. // console.log(pos);
  3309. locHistory.push([pos.lat, pos.lng, image.id, image.compassAngle]);
  3310. }
  3311. let btn = document.querySelector("button[data-qa='undo-move']");
  3312. if (btn !== null && locHistory.length > 1)
  3313. {
  3314. btn.disabled = false;
  3315. btn.classList.remove('styles_disabled__W_k45');
  3316. }
  3317. });
  3318.  
  3319. MAPILLARY_INJECTED = true;
  3320. resolve();
  3321. })
  3322. }
  3323. }
  3324. else {
  3325. resolve();
  3326. }
  3327. });
  3328. }
  3329.  
  3330.  
  3331. function handleMapillary(latlng, options)
  3332. {
  3333. console.log("handleMapillary")
  3334. handleMapillaryHelper(latlng, options).then((data) => {
  3335. //console.log(data.data)
  3336. let idToSet = 0;
  3337. let curDist = 100000000;
  3338. for (const element of data.data) {
  3339. // console.log(element)
  3340. if (element.hasOwnProperty("computed_geometry"))
  3341. {
  3342. try {
  3343. let rCord = element.computed_geometry["coordinates"];
  3344. let dist = distance(latlng.lat,latlng.lng,rCord[1],rCord[0])
  3345. if (dist < curDist)
  3346. {
  3347. idToSet = element.id;
  3348. curDist = dist
  3349. }
  3350. } catch (e) {
  3351. console.log("Error")
  3352. }
  3353. }
  3354. }
  3355. if (idToSet !== 0)
  3356. {
  3357. MapillaryPlayer.moveTo(idToSet).then(
  3358. image => { //console.log(image);
  3359. },
  3360. error => { console.log(error); });
  3361. }}).catch((error) => {
  3362. console.log(error);
  3363. });
  3364. }
  3365.  
  3366. function handleMapillaryHelper(latlng, options)
  3367. {
  3368. return new Promise((resolve, reject) => {
  3369. // console.log("1")
  3370. let bbox = getBBox(latlng, options.meters);
  3371. let URL = "https://graph.mapillary.com/images?access_token={0}&fields=id,computed_geometry&bbox={1}&limit={2}".replace('{0}', MAPILLARY_API_KEY).replace('{1}', bbox).replace('{2}', options.limit)
  3372. // console.log(URL)
  3373. fetch(URL)
  3374. .then((response) => {resolve(response.json())})
  3375. .catch((error) => {console.log(error);});
  3376. });
  3377. }
  3378.  
  3379. function moveFrom(coords, angle, distance){
  3380. const R_EARTH = 6378.137;
  3381. const M = (1 / ((2 * Math.PI / 360) * R_EARTH)) / 1000;
  3382. let radianAngle = -angle * Math.PI / 180;
  3383. let x = 0 + (distance * Math.cos(radianAngle));
  3384. let y = 0 + (distance * Math.sin(radianAngle));
  3385.  
  3386. let newLat = coords.lat + (y * M);
  3387. let newLng = coords.lng + (x * M) / Math.cos(coords.lat * (Math.PI / 180));
  3388. return { lat: newLat, lng: newLng };
  3389. }
  3390.  
  3391. function getBBox(coordinates, meters){
  3392. let SW = moveFrom(coordinates, 135, meters);
  3393. let NE = moveFrom(coordinates, 315, meters);
  3394. return `${SW.lng},${SW.lat},${NE.lng},${NE.lat}`;
  3395. }
  3396.  
  3397.  
  3398. function distance(lat1, lon1, lat2, lon2) {
  3399. var p = 0.017453292519943295; // Math.PI / 180
  3400. var c = Math.cos;
  3401. var a = 0.5 - c((lat2 - lat1) * p)/2 +
  3402. c(lat1 * p) * c(lat2 * p) *
  3403. (1 - c((lon2 - lon1) * p))/2;
  3404.  
  3405. return 1000 * 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
  3406. }
  3407.  
  3408.  
  3409. /**
  3410. * Minimap presets
  3411. */
  3412.  
  3413. let water_name_only =
  3414. [
  3415. {
  3416. "elementType": "geometry",
  3417. "stylers": [
  3418. {
  3419. "visibility": "off"
  3420. }
  3421. ]
  3422. },
  3423. {
  3424. "featureType": "administrative",
  3425. "stylers": [
  3426. {
  3427. "visibility": "off"
  3428. }
  3429. ]
  3430. },
  3431. {
  3432. "featureType": "landscape",
  3433. "stylers": [
  3434. {
  3435. "visibility": "off"
  3436. }
  3437. ]
  3438. },
  3439. {
  3440. "featureType": "poi",
  3441. "stylers": [
  3442. {
  3443. "visibility": "off"
  3444. }
  3445. ]
  3446. },
  3447. {
  3448. "featureType": "road",
  3449. "stylers": [
  3450. {
  3451. "visibility": "off"
  3452. }
  3453. ]
  3454. },
  3455. {
  3456. "featureType": "transit",
  3457. "stylers": [
  3458. {
  3459. "visibility": "off"
  3460. }
  3461. ]
  3462. }
  3463. ]
  3464. let country_name_only =
  3465. [
  3466. {
  3467. "elementType": "geometry",
  3468. "stylers": [
  3469. {
  3470. "visibility": "off"
  3471. }
  3472. ]
  3473. },
  3474. {
  3475. "featureType": "administrative",
  3476. "stylers": [
  3477. {
  3478. "visibility": "off"
  3479. }
  3480. ]
  3481. },
  3482. {
  3483. "featureType": "administrative.country",
  3484. "elementType": "labels",
  3485. "stylers": [
  3486. {
  3487. "visibility": "on"
  3488. }
  3489. ]
  3490. },
  3491. {
  3492. "featureType": "landscape",
  3493. "stylers": [
  3494. {
  3495. "visibility": "off"
  3496. }
  3497. ]
  3498. },
  3499. {
  3500. "featureType": "poi",
  3501. "stylers": [
  3502. {
  3503. "visibility": "off"
  3504. }
  3505. ]
  3506. },
  3507. {
  3508. "featureType": "road",
  3509. "stylers": [
  3510. {
  3511. "visibility": "off"
  3512. }
  3513. ]
  3514. },
  3515. {
  3516. "featureType": "transit",
  3517. "stylers": [
  3518. {
  3519. "visibility": "off"
  3520. }
  3521. ]
  3522. },
  3523. {
  3524. "featureType": "water",
  3525. "stylers": [
  3526. {
  3527. "visibility": "off"
  3528. }
  3529. ]
  3530. }
  3531. ]
  3532.  
  3533. let no_label_or_terrain =
  3534. [
  3535. {
  3536. "elementType": "geometry",
  3537. "stylers": [
  3538. {
  3539. "visibility": "off"
  3540. }
  3541. ]
  3542. },
  3543. {
  3544. "featureType": "administrative",
  3545. "stylers": [
  3546. {
  3547. "visibility": "off"
  3548. }
  3549. ]
  3550. },
  3551. {
  3552. "featureType": "landscape",
  3553. "stylers": [
  3554. {
  3555. "visibility": "off"
  3556. }
  3557. ]
  3558. },
  3559. {
  3560. "featureType": "poi",
  3561. "stylers": [
  3562. {
  3563. "visibility": "off"
  3564. }
  3565. ]
  3566. },
  3567. {
  3568. "featureType": "road",
  3569. "stylers": [
  3570. {
  3571. "visibility": "off"
  3572. }
  3573. ]
  3574. },
  3575. {
  3576. "featureType": "transit",
  3577. "stylers": [
  3578. {
  3579. "visibility": "off"
  3580. }
  3581. ]
  3582. },
  3583. {
  3584. "featureType": "water",
  3585. "stylers": [
  3586. {
  3587. "visibility": "on"
  3588. }
  3589. ]
  3590. },
  3591. {
  3592. "featureType": "water",
  3593. "elementType": "labels",
  3594. "stylers": [
  3595. {
  3596. "visibility": "off"
  3597. }
  3598. ]
  3599. }
  3600. ]
  3601.  
  3602. let no_label =
  3603. [
  3604. {
  3605. "elementType": "labels",
  3606. "stylers": [
  3607. {
  3608. "visibility": "off"
  3609. }
  3610. ]
  3611. },
  3612. {
  3613. "featureType": "administrative",
  3614. "stylers": [
  3615. {
  3616. "visibility": "off"
  3617. }
  3618. ]
  3619. }
  3620. ]
  3621.  
  3622. let blank =
  3623.  
  3624. [
  3625. {
  3626. "stylers": [
  3627. {
  3628. "visibility": "off"
  3629. }
  3630. ]
  3631. }
  3632. ]
  3633.  
  3634. let thick_border =
  3635.  
  3636. [
  3637. {
  3638. "featureType": "administrative.country",
  3639. "elementType": "geometry.stroke",
  3640. "stylers": [
  3641. {
  3642. "weight": 1.5
  3643. }
  3644. ]
  3645. },
  3646. {
  3647. "featureType": "administrative.province",
  3648. "elementType": "geometry.stroke",
  3649. "stylers": [
  3650. {
  3651. "weight": 3.5
  3652. }
  3653. ]
  3654. }
  3655. ]
  3656.  
  3657. let default_preset = []
  3658.  
  3659. let presetMinimap = [[default_preset, "Default"],
  3660. [blank, "Blank"],
  3661. [water_name_only, "Oceanman"],
  3662. [country_name_only, "Impossible"],
  3663. [no_label_or_terrain, "Streaks"],
  3664. [no_label, "Easy 5K"],
  3665. [thick_border, "Highlighted Borders"],
  3666. [default_preset, "Satellite"],
  3667. [default_preset, "Terrain"],
  3668. [default_preset, "Hybrid"],
  3669. [custom, "Custom", customMode]]
  3670.  
  3671. let GEOJSON_INVISIBLE =
  3672. {
  3673. strokeOpacity: 0,
  3674. fillOpacity: 0,
  3675. }
  3676.  
  3677. let presetOverlay = [["Default",""],
  3678. ["Longitude", "https://raw.githubusercontent.com/Jupaoqq/Jupaoqq.github.io/main/lonl.json"],
  3679. ["Latitude", "https://raw.githubusercontent.com/Jupaoqq/Jupaoqq.github.io/main/latl.json"],
  3680. ["US County","https://raw.githubusercontent.com/CodeForCary/CountyDataUSA5m/master/cb_2017_us_county_5m.json"],
  3681. ["France","https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements.geojson"],
  3682. ["Time Zone", "https://raw.githubusercontent.com/treyerl/timezones/master/timezones_wVVG8.geojson"],
  3683. ["UK Parliament", "https://raw.githubusercontent.com/martinjc/UK-GeoJSON/master/json/electoral/gb/wpc.json"],
  3684. ["Custom", YOUR_URL]]
  3685.  
  3686.  
  3687. /**
  3688. * Display map per local laws and regulations
  3689. */
  3690.  
  3691. let SEOverlay, NWOverlay, SEOverlay3;
  3692. let TW = [[24.80, 119.00, 22.00, 123.20],
  3693. [24.20, 119.90, 22.90, 121.85],
  3694. [24.00, 120.90, 23.80, 121.20],
  3695. [23.93, 121.03, 23.85, 121.15],
  3696. [23.92, 121.055, 23.89, 121.10],
  3697. [23.92, 121.055, 23.89, 121.10],
  3698. [23.92, 121.055, 23.89, 121.10],
  3699. ]
  3700.  
  3701. let TS = [[30.40, 93.40, 28, 97.20],
  3702. [29.40, 94.55, 28.20, 96.45]]
  3703.  
  3704. let NW = [36.20, 77.70, 34.40, 80.70]