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

As of 2022-01-30. See the latest version.

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