Geoguessr Unity Script

Play Geoguessr with Yandex, Baidu, Kakao, Mapillary streetviews, Aris coverage (with good movement), and avoid the gaps in official coverage. Credit to kommu, MrAmericanMike (Yandex) and xsanda (check location after movement) scripts. Thanks to Alok, Mapper for advise for map making.

2021-12-24 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Geoguessr Unity Script
  3. // @description Play Geoguessr with Yandex, Baidu, Kakao, Mapillary streetviews, Aris coverage (with good movement), and avoid the gaps in official coverage. Credit to kommu, MrAmericanMike (Yandex) and xsanda (check location after movement) scripts. Thanks to Alok, Mapper for advise for map making.
  4. // @version 4.0.0
  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. // API Keys
  12.  
  13. var YANDEX_API_KEY = "b704b5a9-3d67-4d19-b702-ec7807cecfc6";
  14. var BAIDU_API_KEY = "8dQ9hZPGEQnqg9r0O1C8Ate2N6P8Zk92";
  15. var KAKAO_API_KEY = "cbacbe41e3a223d794f321de4f3e247b";
  16. const MAPS_API_URL = "https://maps.googleapis.com/maps/api/js"; // removed "?" from the link
  17. var MAPILLARY_API_KEY = "MLY|6723031704435203|5afd537469b114cf814881137ad74b7c";
  18.  
  19. myLog("Geoguessr Unity Script V4.0.0");
  20.  
  21. // Store each player instance
  22.  
  23. let YandexPlayer, BaiduPlayer, KakaoPlayer, GooglePlayer, MapillaryPlayer;
  24. let YANDEX_INJECTED = false;
  25. let BAIDU_INJECTED = false;
  26. let KAKAO_INJECTED = false;
  27. let MAPILLARY_INJECTED = false;
  28.  
  29. // Game mode detection
  30.  
  31. let isBattleRoyale = false;
  32. let isDuel = false;
  33.  
  34. // Player detection and coordinate conversion
  35.  
  36. let nextPlayer = "Google";
  37. let global_lat = 0;
  38. let global_lng = 0;
  39. let global_panoID = null;
  40. let global_heading = null;
  41. let global_pitch = null;
  42.  
  43. let krCoordinates = [38.75292321084364, 124.2804539232574, 33.18509676203202, 129.597381999198]
  44. let global_radi = 100
  45.  
  46. // Callback variables
  47.  
  48. let eventListenerAttached = false;
  49. let povListenerAttached = false;
  50. let playerLoaded = false;
  51. let teleportLoaded = false;
  52. let syncLoaded = false;
  53.  
  54. // Minimize Yandex API use
  55.  
  56. let yandex_map = false;
  57.  
  58. // Mapillary Image Key
  59.  
  60. let mmKey = 0;
  61.  
  62. // Handle Yandex compass
  63.  
  64. let COMPASS = null;
  65.  
  66. // Handle undo
  67.  
  68. let locHistory = [];
  69. let defaultPanoIdChange = true;
  70.  
  71. // Round check
  72.  
  73. let ROUND = 0;
  74. let CURRENT_ROUND_DATA = null;
  75.  
  76. let switch_call = true;
  77.  
  78. // let NEW_ROUND_LOADED = false;
  79.  
  80. /**
  81. * Helper Functions
  82. */
  83.  
  84. // Pretty print
  85.  
  86. function myLog(...args) {
  87. console.log(...args);
  88. }
  89. function myHighlight(...args) {
  90. console.log(`%c${[...args]}`, "color: dodgerblue; font-size: 24px;");
  91. }
  92.  
  93. // Hex to number conversion for Baidu coordinate conversion
  94.  
  95. function hex2a(hexx) {
  96. var hex = hexx.toString();
  97. var str = '';
  98. for (var i = 0; i < hex.length; i += 2)
  99. str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
  100. return str;
  101. }
  102.  
  103. // Coordinate computation given heading, distance and current coordinates for teleport
  104.  
  105. function FindPointAtDistanceFrom(lat, lng, initialBearingRadians, distanceKilometres) {
  106. const radiusEarthKilometres = 6371.01;
  107. var distRatio = distanceKilometres / radiusEarthKilometres;
  108. var distRatioSine = Math.sin(distRatio);
  109. var distRatioCosine = Math.cos(distRatio);
  110.  
  111. var startLatRad = DegreesToRadians(lat);
  112. var startLonRad = DegreesToRadians(lng);
  113.  
  114. var startLatCos = Math.cos(startLatRad);
  115. var startLatSin = Math.sin(startLatRad);
  116.  
  117. var endLatRads = Math.asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.cos(initialBearingRadians)));
  118.  
  119. var endLonRads = startLonRad
  120. + Math.atan2(
  121. Math.sin(initialBearingRadians) * distRatioSine * startLatCos,
  122. distRatioCosine - startLatSin * Math.sin(endLatRads));
  123.  
  124. return { lat: RadiansToDegrees(endLatRads), lng: RadiansToDegrees(endLonRads) };
  125. }
  126.  
  127. function DegreesToRadians(degrees) {
  128. const degToRadFactor = Math.PI / 180;
  129. return degrees * degToRadFactor;
  130. }
  131.  
  132. function RadiansToDegrees(radians) {
  133. const radToDegFactor = 180 / Math.PI;
  134. return radians * radToDegFactor;
  135. }
  136.  
  137. // Check if two floating point numbers are really really really really close to each other (to 10 decimal points)
  138. function almostEqual (a, b) {
  139. return a.toFixed(10) === b.toFixed(10)
  140. }
  141.  
  142. function almostEqual2 (a, b) {
  143. return a.toFixed(3) === b.toFixed(3)
  144. }
  145.  
  146. // Script injection, extracted from extenssr:
  147. // https://gitlab.com/nonreviad/extenssr/-/blob/main/src/injected_scripts/maps_api_injecter.ts
  148.  
  149. function overrideOnLoad(googleScript, observer, overrider) {
  150. const oldOnload = googleScript.onload
  151. googleScript.onload = (event) => {
  152. const google = unsafeWindow.google
  153. if (google) {
  154. observer.disconnect()
  155. overrider(google)
  156. }
  157. if (oldOnload) {
  158. oldOnload.call(googleScript, event)
  159. }
  160. }
  161. }
  162.  
  163. function grabGoogleScript(mutations) {
  164. for (const mutation of mutations) {
  165. for (const newNode of mutation.addedNodes) {
  166. const asScript = newNode
  167. if (asScript && asScript.src && asScript.src.startsWith('https://maps.googleapis.com/')) {
  168. return asScript
  169. }
  170. }
  171. }
  172. return null
  173. }
  174.  
  175. function injecter(overrider) {
  176. new MutationObserver((mutations, observer) => {
  177. const googleScript = grabGoogleScript(mutations)
  178. if (googleScript) {
  179. overrideOnLoad(googleScript, observer, overrider)
  180. }
  181. }).observe(document.documentElement, { childList: true, subtree: true })
  182. }
  183.  
  184. /**
  185. * Creates teleportation and Kakao switch button
  186. *
  187. * @returns Promise
  188. */
  189.  
  190. function ArisKakao() {
  191. // let radi = 100;
  192. const google = unsafeWindow.google;
  193. // console.log(google);
  194. let curPosition;
  195. let kakao_enabled = true;
  196.  
  197. // Helper Functions
  198.  
  199. function FindPointAtDistanceFrom(startPoint, initialBearingRadians, distanceKilometres) {
  200. const radiusEarthKilometres = 6371.01;
  201. var distRatio = distanceKilometres / radiusEarthKilometres;
  202. var distRatioSine = Math.sin(distRatio);
  203. var distRatioCosine = Math.cos(distRatio);
  204.  
  205. var startLatRad = DegreesToRadians(startPoint.lat);
  206. var startLonRad = DegreesToRadians(startPoint.lng);
  207.  
  208. var startLatCos = Math.cos(startLatRad);
  209. var startLatSin = Math.sin(startLatRad);
  210.  
  211. var endLatRads = Math.asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.cos(initialBearingRadians)));
  212.  
  213. var endLonRads = startLonRad
  214. + Math.atan2(
  215. Math.sin(initialBearingRadians) * distRatioSine * startLatCos,
  216. distRatioCosine - startLatSin * Math.sin(endLatRads));
  217.  
  218. return { lat: RadiansToDegrees(endLatRads), lng: RadiansToDegrees(endLonRads) };
  219. }
  220.  
  221. function svCheck(data, status) {
  222. if (status === 'OK') {
  223. // console.log("OK for " + data.location.latLng + " at ID " + data.location.pano);
  224. let l = data.location.latLng.toString().split(',');
  225. let lat = l[0].replaceAll('(', '')
  226. let lng = l[1].replaceAll(')', '')
  227. if (lat == curPosition.lat && lng == curPosition.lng && !switch_call)
  228. {
  229. console.log("Trying more distance");
  230. teleportButton.distance += 100;
  231. teleportButton.innerHTML = "Teleport " + teleportButton.distance + " m";
  232. }
  233. else
  234. {
  235. console.log("Teleport Success");
  236. GooglePlayer.setPosition(data.location.latLng);
  237. GooglePlayer.setPov({
  238. heading: googleKakaoButton.heading,
  239. pitch: 0,
  240. })
  241. // console.log(teleportButton.distance);
  242. if (teleportButton.distance > 150)
  243. {
  244. teleportButton.distance = 100;
  245. teleportButton.innerHTML = "Teleport " + teleportButton.distance + " m";
  246. }
  247. }
  248. switch_call = false;
  249. }
  250. else {
  251. console.log("STATUS NOT OK");
  252. teleportButton.distance += 100;
  253. teleportButton.innerHTML = "Teleport " + teleportButton.distance + " m";
  254. }
  255. }
  256.  
  257. const svService = new google.maps.StreetViewService();
  258. google.maps.StreetViewPanorama = class extends google.maps.StreetViewPanorama {
  259. constructor(...args) {
  260. super(...args);
  261. GooglePlayer = this;
  262.  
  263. 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/");
  264.  
  265. this.addListener('position_changed', () => {
  266. // Maybe this could be used to update the position in the other players
  267. // so that they are always in sync
  268. try {
  269. if (!isGamePage()) return;
  270. const lat = this.getPosition().lat();
  271. const lng = this.getPosition().lng();
  272. const { heading } = this.getPov();
  273.  
  274. curPosition = { lat, lng, heading };
  275.  
  276. if (googleKakaoButton.useGoogle)
  277. {
  278. googleKakaoButton.lng = lng;
  279. googleKakaoButton.lat = lat;
  280. googleKakaoButton.heading = heading;
  281. }
  282. googleKakaoButton.useGoogle = true;
  283. teleportButton.google = true;
  284. // console.log("also run");
  285.  
  286. // googleKakaoButton.heading = position.lat;
  287. // console.log(position.heading);
  288. // console.log(googleKakaoButton.lng);
  289. }
  290. catch (e) {
  291. console.error("GeoGuessr Path Logger Error:", e);
  292. }
  293. });
  294. this.addListener('pov_changed', () => {
  295. const { heading, pitch } = this.getPov();
  296. if (KakaoPlayer) {
  297. const vp = KakaoPlayer.getViewpoint();
  298. // Prevent a recursive loop: only update kakao's viewpoint if it got out of sync with google's
  299. if (!almostEqual(vp.pan, heading) || !almostEqual(vp.tilt, pitch)) {
  300. KakaoPlayer.setViewpoint({ pan: heading, tilt: pitch, zoom: vp.zoom });
  301. }
  302. }
  303. });
  304. }
  305. };
  306.  
  307.  
  308. var showButtons = document.createElement("Button");
  309. showButtons.id = "Show Buttons"
  310. showButtons.innerHTML = "Script Buttons";
  311. showButtons.style =
  312. "top:6em;right:0.5em;width:6em;height:4.5em;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;";
  313. document.body.appendChild(showButtons);
  314. showButtons.addEventListener("click", () => {
  315. if (hide) {
  316. teleportButton.style.visibility = "";
  317. plusButton.style.visibility = "";
  318. minusButton.style.visibility = "";
  319. resetButton.style.visibility = "";
  320. googleKakaoButton.style.visibility = "";
  321. hide = false;
  322. }
  323. else {
  324. teleportButton.style.visibility = "hidden";
  325. plusButton.style.visibility = "hidden";
  326. minusButton.style.visibility = "hidden";
  327. resetButton.style.visibility = "hidden"
  328. googleKakaoButton.style.visibility = "hidden";
  329. hide = true;
  330. }
  331. });
  332.  
  333. var teleportButton = document.createElement("Button");
  334. teleportButton.id = "Main Button";
  335. teleportButton.distance = 100;
  336. teleportButton.google = true;
  337. teleportButton.innerHTML = "Teleport 100m";
  338. teleportButton.style =
  339. "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;";
  340. document.body.appendChild(teleportButton);
  341. teleportButton.addEventListener("click", () => {
  342. // console.log("Google Teleport");
  343. if (googleKakaoButton.init)
  344. {
  345. // console.log("run");
  346. googleKakaoButton.init = false;
  347. if (teleportButton.google)
  348. {
  349. googleKakaoButton.useGoogle = true;
  350. teleportButton.google = true;
  351. }
  352. else
  353. {
  354. googleKakaoButton.useGoogle = false;
  355. teleportButton.google = false;
  356. }
  357. }
  358. else
  359. {
  360. // myLog(teleportButton.google)
  361. if (teleportButton.google && GooglePlayer != null)
  362. {
  363. let heading = GooglePlayer.getPov().heading;
  364. let place = FindPointAtDistanceFrom(curPosition, DegreesToRadians(heading), teleportButton.distance * 0.001)
  365. svService.getPanorama({ location: place, radius: 1000 }, svCheck);
  366. }
  367. }
  368. });
  369.  
  370. var plusButton = document.createElement("Button");
  371. plusButton.id = "plus"
  372. plusButton.innerHTML = "+";
  373. plusButton.style =
  374. "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;";
  375. document.body.appendChild(plusButton);
  376. plusButton.addEventListener("click", () => {
  377. if (teleportButton.distance > 21 && teleportButton.distance < 149) {
  378. teleportButton.distance = teleportButton.distance + 25;
  379. }
  380. teleportButton.innerHTML = "Teleport " + teleportButton.distance + " m";
  381. });
  382.  
  383. var minusButton = document.createElement("Button");
  384. minusButton.id = "minus"
  385. minusButton.innerHTML = "-";
  386. minusButton.style =
  387. "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;";
  388. document.body.appendChild(minusButton);
  389. minusButton.addEventListener("click", () => {
  390. if (teleportButton.distance > 26) {
  391. teleportButton.distance = teleportButton.distance - 25;
  392. }
  393. teleportButton.innerHTML = "Teleport " + teleportButton.distance + " m";
  394. });
  395.  
  396. var resetButton = document.createElement("Button");
  397. resetButton.id = "reset"
  398. resetButton.innerHTML = "Reset";
  399. resetButton.style =
  400. "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;";
  401. document.body.appendChild(resetButton);
  402. resetButton.addEventListener("click", () => {
  403. teleportButton.distance = 100;
  404. teleportButton.innerHTML = "Teleport " + teleportButton.distance + " m";
  405. });
  406.  
  407. var googleKakaoButton = document.createElement("Button");
  408. googleKakaoButton.id = "switch";
  409. googleKakaoButton.init = false;
  410. googleKakaoButton.nextPlayer = "Google";
  411. googleKakaoButton.useGoogle = false;
  412. googleKakaoButton.lng = 0
  413. googleKakaoButton.lat = 0
  414. googleKakaoButton.heading = 0
  415. googleKakaoButton.innerHTML = "Switch coverage";
  416. googleKakaoButton.small_canvas = false;
  417. googleKakaoButton.style =
  418. "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;";
  419. document.body.appendChild(googleKakaoButton);
  420. googleKakaoButton.addEventListener("click", () => {
  421. let GOOGLE_MAPS_CANVAS1 = document.querySelector(".game-layout__panorama-canvas");
  422. let GOOGLE_MAPS_CANVAS2 = document.querySelector(".br-game-layout__panorama-canvas");
  423. let GOOGLE_MAPS_CANVAS3 = document.querySelector(".inactive");
  424. let duel = false;
  425.  
  426. let GOOGLE_MAPS_CANVAS = null;
  427. if (GOOGLE_MAPS_CANVAS1 !== null)
  428. {
  429. GOOGLE_MAPS_CANVAS = GOOGLE_MAPS_CANVAS1;
  430. }
  431. else if (GOOGLE_MAPS_CANVAS2 !== null)
  432. {
  433. GOOGLE_MAPS_CANVAS = GOOGLE_MAPS_CANVAS2;
  434. }
  435.  
  436.  
  437. if (GOOGLE_MAPS_CANVAS3 !== null)
  438. {
  439. duel = true;
  440. }
  441.  
  442. let KAKAO_MAPS_CANVAS = document.getElementById("roadview");
  443. let YANDEX_MAPS_CANVAS = document.querySelector(".ymaps-2-1-79-panorama-screen");
  444. let MAPILLARY_MAPS_CANVAS = document.getElementById("mly")
  445. if (googleKakaoButton.nextPlayer !== "Baidu") {
  446. if (googleKakaoButton.useGoogle == false) {
  447. if (duel)
  448. {
  449. document.getElementById("default_player").className = "game-panorama_panoramaCanvas__patp9";
  450. if (googleKakaoButton.nextPlayer == "Kakao")
  451. {
  452. document.getElementById("roadview").className = "inactive";
  453. }
  454. else
  455. {
  456. MAPILLARY_MAPS_CANVAS.className = "inactive";
  457. MAPILLARY_MAPS_CANVAS.style.visibility = "hidden";
  458. }
  459. }
  460. else
  461. {
  462. GOOGLE_MAPS_CANVAS.style.visibility = "";
  463. if (googleKakaoButton.nextPlayer == "Kakao")
  464. {
  465. KAKAO_MAPS_CANVAS.style.visibility = "hidden";
  466. }
  467. else if (googleKakaoButton.nextPlayer == "Yandex")
  468. {
  469. YANDEX_MAPS_CANVAS.style.visibility = "hidden";
  470. }
  471. else if (googleKakaoButton.nextPlayer == "Mapillary" || googleKakaoButton.nextPlayer == "Google")
  472. {
  473. MAPILLARY_MAPS_CANVAS.style.visibility = "hidden";
  474. }
  475.  
  476. }
  477. const lat = GooglePlayer.getPosition().lat();
  478. const lng = GooglePlayer.getPosition().lng();
  479. switch_call = true;
  480. if (!almostEqual2(lat, googleKakaoButton.lat) || !almostEqual2(lat, googleKakaoButton.lng)) {
  481. svService.getPanorama({ location: { lat: googleKakaoButton.lat, lng: googleKakaoButton.lng }, radius: 1000 }, svCheck);
  482. }
  483. googleKakaoButton.useGoogle = true;
  484. teleportButton.google = true;
  485. googleKakaoButton.init = false;
  486. console.log("use Google");
  487. }
  488. else {
  489. if (duel)
  490. {
  491. document.getElementById("default_player").className = "inactive";
  492. if (googleKakaoButton.nextPlayer == "Kakao")
  493. {
  494. document.getElementById("roadview").className = "game-panorama_panorama__3b2wI";
  495. }
  496. else
  497. {
  498. MAPILLARY_MAPS_CANVAS.className = "game-panorama_panorama__3b2wI";
  499. MAPILLARY_MAPS_CANVAS.style.visibility = "";
  500. MapillaryPlayer.resize();
  501. //window.dispatchEvent(new Event('resize'));
  502. // document.querySelector(".mapillary-canvas").style.;
  503. // mapillary-canvas
  504. }
  505.  
  506. }
  507. else
  508. {
  509. GOOGLE_MAPS_CANVAS.style.visibility = "hidden";
  510. if (googleKakaoButton.nextPlayer == "Kakao")
  511. {
  512. KAKAO_MAPS_CANVAS.style.visibility = "";
  513. }
  514. else if (googleKakaoButton.nextPlayer == "Yandex")
  515. {
  516. YANDEX_MAPS_CANVAS.style.visibility = "";
  517. }
  518. else if (googleKakaoButton.nextPlayer == "Mapillary" || googleKakaoButton.nextPlayer == "Google")
  519. {
  520. MAPILLARY_MAPS_CANVAS.style.visibility = "";
  521. }
  522. }
  523. googleKakaoButton.useGoogle = false;
  524. teleportButton.google = false;
  525. googleKakaoButton.init = true;
  526. console.log("use Others");
  527. }
  528. }
  529. else {
  530. googleKakaoButton.useGoogle = false;
  531. teleportButton.google = false;
  532. console.log("use Others");
  533. }
  534.  
  535. });
  536.  
  537. // function reportWindowSize() {
  538. // myLog("Resize")
  539. // svService.getPanorama({ location: { lat: googleKakaoButton.lat, lng: googleKakaoButton.lng }, radius: 1000 }, svCheck);
  540. // }
  541.  
  542. // window.onresize = reportWindowSize;
  543.  
  544. // Battle Royale UI optimization
  545.  
  546. let hide = true;
  547.  
  548. console.log("Buttons Loaded");
  549. }
  550.  
  551. /**
  552. * Handle Keyboard inputs
  553. */
  554.  
  555. function kBoard()
  556. {
  557. document.addEventListener('keydown', logKey);
  558. }
  559.  
  560. function logKey(e) {
  561. // myLog(e.code);
  562. if (e.code == "Space")
  563. {
  564. setHidden(true);
  565. }
  566. if (e.code == "Digit1")
  567. {
  568. setHidden(false);
  569. document.getElementById("Show Buttons").click();
  570. }
  571. else if (e.code == "Digit3")
  572. {
  573. document.getElementById("Main Button").click();
  574. }
  575. else if (e.code == "Digit2")
  576. {
  577. document.getElementById("minus").click();
  578. }
  579. else if (e.code == "Digit4")
  580. {
  581. document.getElementById("plus").click();
  582.  
  583. }
  584. else if (e.code == "Digit5")
  585. {
  586. document.getElementById("reset").click();
  587.  
  588. }
  589. else if (e.code == "Digit6")
  590. {
  591. document.getElementById("switch").click();
  592. }
  593. }
  594.  
  595.  
  596. /**
  597. * Hide or reveal the buttons, and disable buttons if such feature is not available
  598. */
  599.  
  600. function setHidden(cond)
  601. {
  602. if (cond)
  603. {
  604. if (document.getElementById("Show Buttons") != null)
  605. {
  606. document.getElementById("Show Buttons").style.visibility = "hidden";
  607. if (document.getElementById("Main Button") != null)
  608. {
  609. document.getElementById("plus").style.visibility = "hidden";
  610. document.getElementById("minus").style.visibility = "hidden";
  611. document.getElementById("reset").style.visibility = "hidden";
  612. document.getElementById("Main Button").style.visibility = "hidden";
  613. document.getElementById("switch").style.visibility = "hidden";
  614. }
  615. }
  616. }
  617. else
  618. {
  619. if (document.getElementById("Show Buttons") != null)
  620. {
  621. document.getElementById("Show Buttons").style.visibility = "";
  622. }
  623. }
  624. }
  625.  
  626. function setDisable(cond) {
  627. if (document.getElementById("Main Button") != null) {
  628. if (cond == "NMPZ") {
  629. document.getElementById("plus").style.backgroundColor = "red";
  630. document.getElementById("plus").disabled = true;
  631. document.getElementById("minus").style.backgroundColor = "red";
  632. document.getElementById("minus").disabled = true;
  633. document.getElementById("reset").style.backgroundColor = "red";
  634. document.getElementById("reset").disabled = true;
  635. if (nextPlayer == "Kakao")
  636. {
  637. document.getElementById("switch").style.backgroundColor = "#4CAF50";
  638. document.getElementById("switch").disabled = false;
  639. }
  640. else
  641. {
  642. document.getElementById("switch").style.backgroundColor = "red";
  643. document.getElementById("switch").disabled = true;
  644. }
  645. document.getElementById("switch").innerHTML = "Switch Coverage";
  646. document.getElementById("Main Button").disabled = true;
  647. document.getElementById("Main Button").style.backgroundColor = "red";
  648. }
  649. else if (cond == "Google") {
  650.  
  651. document.getElementById("plus").style.backgroundColor = "#4CAF50";
  652. document.getElementById("plus").disabled = false;
  653. document.getElementById("minus").style.backgroundColor = "#4CAF50";
  654. document.getElementById("minus").disabled = false;
  655. document.getElementById("reset").style.backgroundColor = "#4CAF50";
  656. document.getElementById("reset").disabled = false;
  657. document.getElementById("switch").style.backgroundColor = "#4CAF50";
  658. document.getElementById("switch").disabled = false;
  659. document.getElementById("switch").innerHTML = "Switch Coverage";
  660. document.getElementById("Main Button").disabled = false;
  661. document.getElementById("Main Button").style.backgroundColor = "#4CAF50";
  662. }
  663. else if (cond == "Baidu") {
  664. document.getElementById("plus").style.backgroundColor = "#4CAF50";
  665. document.getElementById("plus").disabled = false;
  666. document.getElementById("minus").style.backgroundColor = "#4CAF50";
  667. document.getElementById("minus").disabled = false;
  668. document.getElementById("reset").style.backgroundColor = "#4CAF50";
  669. document.getElementById("reset").disabled = false;
  670. document.getElementById("switch").style.backgroundColor = "#4CAF50";
  671. document.getElementById("switch").disabled = false;
  672. if (document.getElementById("switch").small_canvas) {
  673. document.getElementById("switch").innerHTML = "Widescreen";
  674. }
  675. else {
  676. document.getElementById("switch").innerHTML = "More Viewing Area";
  677. }
  678. document.getElementById("Main Button").disabled = false;
  679. document.getElementById("Main Button").style.backgroundColor = "#4CAF50";
  680. }
  681. else if (cond == "Kakao" || cond == "Yandex" || cond == "Mapillary") {
  682. document.getElementById("plus").style.backgroundColor = "#4CAF50";
  683. document.getElementById("plus").disabled = false;
  684. document.getElementById("minus").style.backgroundColor = "#4CAF50";
  685. document.getElementById("minus").disabled = false;
  686. document.getElementById("reset").style.backgroundColor = "#4CAF50";
  687. document.getElementById("reset").disabled = false;
  688. document.getElementById("switch").style.backgroundColor = "#4CAF50";
  689. document.getElementById("switch").disabled = false;
  690. document.getElementById("switch").innerHTML = "Switch Coverage";
  691. document.getElementById("Main Button").disabled = false;
  692. document.getElementById("Main Button").style.backgroundColor = "#4CAF50";
  693. }
  694. // else if (cond == "Mapillary") {
  695. // document.getElementById("plus").style.backgroundColor = "red";
  696. // document.getElementById("plus").disabled = true;
  697. // document.getElementById("minus").style.backgroundColor = "red";
  698. // document.getElementById("minus").disabled = true;
  699. // document.getElementById("reset").style.backgroundColor = "red";
  700. // document.getElementById("reset").disabled = true;
  701. // document.getElementById("switch").style.backgroundColor = "#4CAF50";
  702. // document.getElementById("switch").disabled = false
  703. // document.getElementById("switch").innerHTML = "Switch Coverage";
  704. // document.getElementById("Main Button").disabled = true;
  705. // document.getElementById("Main Button").style.backgroundColor = "red";
  706. // }
  707.  
  708. }
  709. }
  710.  
  711.  
  712. /**
  713. * This observer stays alive while the script is running
  714. */
  715.  
  716. function launchObserver() {
  717. ArisKakao();
  718. BYKTeleport();
  719. SyncListener();
  720. kBoard();
  721. myHighlight("Main Observer");
  722. const OBSERVER = new MutationObserver((mutations, observer) => {
  723. detectGamePage();
  724. });
  725. OBSERVER.observe(document.head, { attributes: true, childList: true, subtree: true });
  726. }
  727.  
  728. /**
  729. * Once the Google Maps API was loaded we can do more stuff
  730. */
  731.  
  732. injecter(() => {
  733. launchObserver();
  734. })
  735.  
  736.  
  737. /**
  738. * Check whether the current page is a game, if so which game mode
  739. */
  740.  
  741. function detectGamePage() {
  742. let toLoad = !playerLoaded && !YandexPlayer && !BaiduPlayer && !KakaoPlayer && !MapillaryPlayer && !YANDEX_INJECTED && !BAIDU_INJECTED && !KAKAO_INJECTED && !MAPILLARY_INJECTED
  743. const PATHNAME = window.location.pathname;
  744. if (PATHNAME.startsWith("/game/") || PATHNAME.startsWith("/challenge/")) {
  745. // myLog("Game page");
  746. isBattleRoyale = false;
  747. isDuel = false;
  748. if (toLoad) {
  749. loadPlayers();
  750. }
  751. waitLoad();
  752. }
  753. else if (PATHNAME.startsWith("/battle-royale/")) {
  754. if (document.querySelector(".br-game-layout") == null) {
  755. // myLog("Battle Royale Lobby");
  756. rstValues();
  757. }
  758. else {
  759. // myLog("Battle Royale");
  760. isBattleRoyale = true;
  761. isDuel = false;
  762. if (toLoad) {
  763. loadPlayers();
  764. }
  765. waitLoad();
  766. }
  767. }
  768. else if (PATHNAME.startsWith("/duels/") || PATHNAME.startsWith("/team-duels/")) {
  769. if (document.querySelector(".game_layout__1TqBM") == null) {
  770. // myLog("Battle Royale Lobby");
  771. rstValues();
  772. }
  773. else {
  774. // myLog("Duels");
  775. isBattleRoyale = true;
  776. isDuel = true;
  777. if (toLoad) {
  778. loadPlayers();
  779. }
  780. waitLoad();
  781. }
  782. }
  783. else {
  784. rstValues();
  785. //myLog("Not a Game page");
  786. }
  787. }
  788.  
  789. function rstValues()
  790. {
  791. ROUND = 0;
  792. YandexPlayer = null;
  793. BaiduPlayer = null;
  794. KakaoPlayer = null;
  795. MapillaryPlayer = null;
  796.  
  797. BAIDU_INJECTED = false;
  798. YANDEX_INJECTED = false;
  799. KAKAO_INJECTED = false;
  800. MAPILLARY_INJECTED = false;
  801.  
  802. nextPlayer = "Google"
  803. global_lat = 0;
  804. global_lng = 0;
  805. global_panoID = null;
  806.  
  807. COMPASS = null;
  808. eventListenerAttached = false;
  809. povListenerAttached = false;
  810. playerLoaded = false;
  811. locHistory = [];
  812. setHidden(true);
  813. yandex_map = false;
  814. mmKey = 0;
  815. CURRENT_ROUND_DATA = null;
  816. }
  817.  
  818. /**
  819. * Wait for various players to load
  820. */
  821.  
  822. function waitLoad() {
  823. if (!YandexPlayer || !BaiduPlayer || !KakaoPlayer || !MapillaryPlayer || !YANDEX_INJECTED || !BAIDU_INJECTED || !KAKAO_INJECTED || !MAPILLARY_INJECTED) {
  824. let teleportButton = document.getElementById("Main Button");
  825. let plusButton = document.getElementById("plus");
  826. let minusButton = document.getElementById("minus");
  827. let resetButton = document.getElementById("reset");
  828. let googleKakaoButton = document.getElementById("switch");
  829. let showButtons = document.getElementById("Show Buttons");
  830. if (document.querySelector(".br-game-layout__panorama-canvas") != null)
  831. {
  832. teleportButton.style.top = "2px";
  833. plusButton.style.top = "2px";
  834. minusButton.style.top = "2px";
  835. resetButton.style.top = "calc(2.5em + 2px)";
  836. googleKakaoButton.style.top = "calc(2.5em + 2px)";
  837. showButtons.style.top = "2px";
  838.  
  839. teleportButton.style.right = "calc(9.5em + 300px)";
  840. plusButton.style.right = "calc(7em + 300px)";
  841. minusButton.style.right = "calc(20em + 300px)";
  842. resetButton.style.right = "calc(17.5em + 300px)";
  843. googleKakaoButton.style.right = "calc(7em + 300px)";
  844. showButtons.style.right = "300px";
  845. }
  846.  
  847.  
  848. if (document.querySelector(".game-panorama_panorama__3b2wI") != null)
  849. {
  850. teleportButton.style.top = "8em";
  851. plusButton.style.top = "8em";
  852. minusButton.style.top = "8em";
  853. resetButton.style.top = "10.5em";
  854. googleKakaoButton.style.top = "10.5em";
  855. showButtons.style.top = "8em";
  856.  
  857. teleportButton.style.right = "9.5em";
  858. plusButton.style.right = "7em";
  859. minusButton.style.right = "20em";
  860. resetButton.style.right = "17.5em";
  861. googleKakaoButton.style.right = "7em";
  862. showButtons.style.right = "0.5em";
  863.  
  864. }
  865.  
  866. setTimeout(waitLoad, 250);
  867. } else {
  868. checkRound();
  869. }
  870. }
  871.  
  872. /**
  873. * Checks for round changes
  874. */
  875.  
  876. function checkRound() {
  877. // myLog("Check Round");
  878. if (!isBattleRoyale) {
  879. // myLog("Check Round");
  880. let currentRound = getRoundFromPage();
  881. if (ROUND != currentRound) {
  882. document.getElementById("switch").init = true;
  883. myHighlight("New round");
  884. ROUND = currentRound;
  885. // NEW_ROUND_LOADED = true;
  886. COMPASS = null;
  887. locHistory = [];
  888. getMapData();
  889. nextButtonCallback();
  890. }
  891. }
  892. else {
  893. getMapData();
  894. }
  895. }
  896.  
  897. /**
  898. * Add listeners if buttons have been created
  899. */
  900.  
  901. function nextButtonCallback()
  902. {
  903. let nextButton = document.querySelector("button[data-qa='close-round-result']");
  904. if (nextButton != null)
  905. {
  906. nextButton.addEventListener("click", (e) => {
  907. if (document.getElementById("Show Buttons") != null)
  908. {
  909. myLog("try to hide show buttons")
  910. document.getElementById("Show Buttons").style.visibility = "";
  911. }
  912. })
  913. }
  914. else
  915. {
  916. setTimeout(nextButtonCallback, 500);
  917. }
  918. }
  919.  
  920. function guessButtonCallback()
  921. {
  922. let guessButton = document.querySelector("button[data-qa='perform-guess']");
  923. if (guessButton != null)
  924. {
  925.  
  926. guessButton.addEventListener("click", (e) => {
  927. if (document.getElementById("Show Buttons") != null)
  928. {
  929. myLog("try to hide show buttons")
  930. document.getElementById("Show Buttons").style.visibility = "hidden";
  931. setHidden(true);
  932. }
  933. })
  934. }
  935. else
  936. {
  937. setTimeout(guessButtonCallback, 500);
  938. }
  939. }
  940.  
  941. /**
  942. * Load different streetview players
  943. */
  944.  
  945. function injectYandex()
  946. {
  947. injectYandexScript().then(() => {
  948. myLog("Ready to inject Yandex player");
  949. injectYandexPlayer();
  950. }).catch((error) => {
  951. myLog(error);
  952. });
  953. }
  954.  
  955. function loadPlayers() {
  956. playerLoaded = true;
  957. if (!isBattleRoyale)
  958. {
  959. getSeed().then((data) => {
  960. // myLog(data);
  961. if (data.mapName.includes("A United World") || data.mapName.includes("byk"))
  962. {
  963. myLog("A United World");
  964. injectYandex();
  965. }
  966. else if (data.mapName.includes("Yandex"))
  967. {
  968. yandex_map = true;
  969. myLog("Is Yandex Map");
  970. injectYandex();
  971. }
  972. else{
  973. // YANDEX_API_KEY = "";
  974. YANDEX_INJECTED = true;
  975. YandexPlayer = "YD";
  976. myLog("Not a Yandex map");
  977. }
  978. setHidden(false);
  979.  
  980. }).catch((error) => {
  981. myLog(error);
  982. });
  983. }
  984. else
  985. {
  986. injectYandex();
  987. }
  988.  
  989. initializeCanvas();
  990.  
  991.  
  992.  
  993.  
  994. }
  995.  
  996. /**
  997. * Handles Return to start and undo
  998. */
  999.  
  1000. function handleReturnToStart() {
  1001. let rtsButton = document.querySelector("button[data-qa='return-to-start']");
  1002. if (rtsButton != null) {
  1003. myLog("handleReturnToStart listener attached");
  1004. rtsButton.addEventListener("click", (e) => {
  1005. goToLocation();
  1006. const elementClicked = e.target;
  1007. elementClicked.setAttribute('listener', 'true');
  1008. myLog("Return to start");
  1009. });
  1010. guessButtonCallback();
  1011. setTimeout(function () {goToLocation();}, 1000);
  1012. }
  1013. else
  1014. {
  1015. setTimeout(handleReturnToStart, 500);
  1016. }
  1017. }
  1018.  
  1019. function handleUndo() {
  1020. let undoButton = document.querySelector("button[data-qa='undo-move']");
  1021. if (undoButton != null)
  1022. {
  1023. myLog("Attach undo");
  1024. undoButton.addEventListener("click", (e) => {
  1025. if (locHistory.length > 0) {
  1026. goToUndoMove();
  1027. myLog("Undo Move");
  1028. }
  1029. })
  1030. }
  1031. else
  1032. {
  1033. setTimeout(handleUndo, 500);
  1034. }
  1035.  
  1036. }
  1037.  
  1038. /**
  1039. * Load game information
  1040. */
  1041.  
  1042. function getMapData() {
  1043. // myHighlight("Seed data");
  1044. getSeed().then((data) => {
  1045. // myHighlight("Seed data");
  1046. // myLog(data);
  1047. if (isBattleRoyale) {
  1048. if ((document.querySelector(".br-game-layout") == null && document.querySelector(".version3-in-game_layout__13T8U") == null) || typeof data.gameId == typeof undefined) {
  1049. // myLog("Battle Royale Lobby");
  1050. }
  1051. else
  1052. {
  1053. let origin = false;
  1054. if (!CURRENT_ROUND_DATA) {
  1055. CURRENT_ROUND_DATA = data
  1056. origin = true;
  1057. }
  1058.  
  1059. if (origin || !(data.currentRoundNumber === CURRENT_ROUND_DATA.currentRoundNumber)) {
  1060. // myHighlight("Battle Royale New round");
  1061. document.getElementById("switch").init = true;
  1062. // NEW_ROUND_LOADED = true;
  1063. COMPASS = null;
  1064. locHistory = [];
  1065. setHidden(false);
  1066. if (!origin) {
  1067. CURRENT_ROUND_DATA = data;
  1068. }
  1069. locationCheck(data);
  1070. // myLog(data);
  1071. if (data.currentRoundNumber == 1)
  1072. {
  1073. setTimeout(function () {goToLocation();}, 3000);
  1074. }
  1075. else
  1076. {
  1077. goToLocation();
  1078. }
  1079. handleReturnToStart();
  1080. if (isDuel)
  1081. {
  1082. handleUndo();
  1083. hideButtons();
  1084. }
  1085.  
  1086. }
  1087. }
  1088. }
  1089. else {
  1090. locationCheck(data);
  1091. if (data.currentRoundNumber == 1)
  1092. {
  1093. setTimeout(function () {goToLocation();}, 3000);
  1094. }
  1095. else
  1096. {
  1097. goToLocation();
  1098. }
  1099. handleReturnToStart();
  1100. handleUndo();
  1101. hideButtons();
  1102. }
  1103. }).catch((error) => {
  1104. myLog(error);
  1105. });
  1106. }
  1107.  
  1108. /**
  1109. * Hide unnecessary buttons for non-Google coverages
  1110. */
  1111.  
  1112. function hideButtons() {
  1113. let CHECKPOINT = document.querySelector("button[data-qa='set-checkpoint']");
  1114. let ZOOM_IN = document.querySelector("button[data-qa='pano-zoom-in']");
  1115. let ZOOM_OUT = document.querySelector("button[data-qa='pano-zoom-out']");
  1116.  
  1117. if (CHECKPOINT != null)
  1118. {
  1119. if (nextPlayer === "Google") {
  1120.  
  1121. CHECKPOINT.style.visibility = "";
  1122. ZOOM_IN.style.visibility = "";
  1123. ZOOM_OUT.style.visibility = "";
  1124. myLog("Buttons Unhidden");
  1125.  
  1126. }
  1127. else {
  1128.  
  1129. CHECKPOINT.style.visibility = "hidden";
  1130. ZOOM_IN.style.visibility = "hidden";
  1131. ZOOM_OUT.style.visibility = "hidden";
  1132. myLog("Buttons Hidden");
  1133.  
  1134. }
  1135. }
  1136. else
  1137. {
  1138. setTimeout(hideButtons, 250);
  1139. }
  1140. }
  1141.  
  1142. /**
  1143. * Check which player to use for the next location
  1144. */
  1145.  
  1146. function locationCheck(data) {
  1147. // console.log(data);
  1148. let round;
  1149. if (isBattleRoyale) {
  1150. if (isDuel)
  1151. {
  1152. round = data.rounds[data.currentRoundNumber - 1].panorama;
  1153. }
  1154. else
  1155. {
  1156. round = data.rounds[data.currentRoundNumber - 1];
  1157. }
  1158. }
  1159. else {
  1160. round = data.rounds[data.round - 1];
  1161. }
  1162. global_lat = round.lat;
  1163. global_lng = round.lng;
  1164. global_panoID = round.panoId;
  1165. global_heading = round.heading;
  1166. global_pitch = round.pitch;
  1167. // myLog(global_lat);
  1168. // myLog(global_lng);
  1169. // myLog(krCoordinates);
  1170.  
  1171. nextPlayer = "Google";
  1172.  
  1173. if ( krCoordinates[0] > global_lat && krCoordinates[2] < global_lat && krCoordinates[1] < global_lng && krCoordinates[3] > global_lng)
  1174. {
  1175. nextPlayer = "Kakao";
  1176. }
  1177. else if (yandex_map)
  1178. {
  1179. nextPlayer = "Yandex";
  1180. }
  1181. else
  1182. {
  1183. if (global_panoID) {
  1184. let locInfo = hex2a(global_panoID);
  1185. let mapType = locInfo.substring(0, 5);
  1186. if (mapType === "BDMAP") {
  1187. nextPlayer = "Baidu";
  1188. let coord = locInfo.substring(5);
  1189. global_lat = coord.split(",")[0];
  1190. global_lng = coord.split(",")[1];
  1191. // myLog(global_lat);
  1192. }
  1193. else if (mapType === "MLMAP") {
  1194. nextPlayer = "Mapillary";
  1195. mmKey = locInfo.substring(5);
  1196. }
  1197. else if (mapType === "YDMAP" ) {
  1198. nextPlayer = "Yandex";
  1199. }
  1200. }
  1201. }
  1202.  
  1203. // Disable buttons if NM, NMPZ
  1204.  
  1205. if(!isBattleRoyale)
  1206. {
  1207. if (data.forbidMoving || data.forbidRotating || data.forbidZooming)
  1208. {
  1209. setDisable("NMPZ");
  1210. }
  1211. else
  1212. {
  1213. setDisable(nextPlayer);
  1214. }
  1215. }
  1216. else
  1217. {
  1218. if (data.movementOptions.forbidMoving || data.movementOptions.forbidRotating || data.movementOptions.forbidZooming)
  1219. {
  1220. setDisable("NMPZ");
  1221. }
  1222. else
  1223. {
  1224. setDisable(nextPlayer);
  1225. }
  1226. }
  1227.  
  1228. myLog(nextPlayer);
  1229. injectCanvas();
  1230. }
  1231.  
  1232.  
  1233. /**
  1234. * setID for canvas
  1235. */
  1236.  
  1237. function initializeCanvas() {
  1238. let GAME_CANVAS = "";
  1239. let DUEL_CANVAS = "";
  1240. //myLog("Is duels");
  1241. //myLog(duels);
  1242.  
  1243. if (isBattleRoyale) {
  1244. if (isDuel) {
  1245. GAME_CANVAS = document.querySelector(".game-panorama_panorama__3b2wI");
  1246. DUEL_CANVAS = document.querySelector(".game-panorama_panoramaCanvas__patp9");
  1247. }
  1248. else
  1249. {
  1250. GAME_CANVAS = document.querySelector(".br-game-layout__panorama-wrapper");
  1251. DUEL_CANVAS = "dummy";
  1252. }
  1253. }
  1254. else {
  1255. GAME_CANVAS = document.querySelector(".game-layout__canvas");
  1256. DUEL_CANVAS = "dummy";
  1257. }
  1258. if (GAME_CANVAS && DUEL_CANVAS)
  1259. {
  1260. myLog("Canvas injected");
  1261. GAME_CANVAS.id = "player";
  1262. if (isDuel) {
  1263. DUEL_CANVAS.id = "default_player";
  1264. }
  1265. injectBaiduPlayer();
  1266. injectMapillaryPlayer();
  1267. injectKakaoScript().then(() => {
  1268. myLog("Ready to inject Kakao player");
  1269. }).catch((error) => {
  1270. myLog(error);
  1271. });
  1272. }
  1273. else
  1274. {
  1275. setTimeout(initializeCanvas, 250);
  1276. }
  1277.  
  1278. }
  1279.  
  1280. /**
  1281. * Hide or show players based on where the next location is
  1282. */
  1283.  
  1284. function injectCanvas() {
  1285. if (isDuel)
  1286. {
  1287. canvasSwitch();
  1288. }
  1289. else
  1290. {
  1291. Google();
  1292. Baidu();
  1293. Kakao();
  1294. Yandex();
  1295. Mapillary();
  1296. }
  1297. ZoomControls();
  1298. }
  1299.  
  1300. // for duels (class ID change)
  1301.  
  1302. function canvasSwitch()
  1303. {
  1304. let GOOGLE_MAPS_CANVAS = document.querySelector(".game-panorama_panoramaCanvas__patp9");
  1305. if (nextPlayer === "Google") {
  1306. document.getElementById("default_player").className = "game-panorama_panoramaCanvas__patp9";
  1307. document.getElementById("PanoramaMap").className = "inactive";
  1308. document.getElementById("roadview").className = "inactive";
  1309. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  1310. document.getElementById("Main Button").google = true;
  1311. document.getElementById("switch").nextPlayer = "Google";
  1312. document.getElementById("switch").useGoogle = true;
  1313. document.getElementById("default_player").style.position = "absolute";
  1314. if (document.querySelector(".compass") !== null)
  1315. {
  1316. document.querySelector(".compass").style.visibility = "";
  1317. }
  1318. myLog("Google Duel Canvas loaded");
  1319. }
  1320. else if (nextPlayer === "Baidu")
  1321. {
  1322. document.getElementById("default_player").className = "inactive";
  1323. document.getElementById("PanoramaMap").className = "game-panorama_panorama__3b2wI";
  1324. document.getElementById("roadview").className = "inactive";
  1325. document.getElementById("mly").style.visibility = "hidden";
  1326. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  1327. document.getElementById("Main Button").google = false;
  1328. document.getElementById("switch").nextPlayer = "Baidu";
  1329. document.getElementById("switch").useGoogle = false;
  1330. document.getElementById("PanoramaMap").style.position = "absolute";
  1331. if (document.querySelector(".compass") !== null)
  1332. {
  1333. document.querySelector(".compass").style.visibility = "hidden";
  1334. }
  1335. myLog("Baidu Duel Canvas loaded");
  1336. }
  1337. else if (nextPlayer === "Kakao")
  1338. {
  1339. document.getElementById("default_player").className = "inactive";
  1340. document.getElementById("PanoramaMap").className = "inactive";
  1341. document.getElementById("roadview").className = "game-panorama_panorama__3b2wI";
  1342. document.getElementById("mly").style.visibility = "hidden";
  1343. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  1344. document.getElementById("Main Button").google = false;
  1345. document.getElementById("switch").nextPlayer = "Kakao";
  1346. document.getElementById("switch").useGoogle = false;
  1347. document.getElementById("roadview").style.position = "absolute";
  1348. if (document.querySelector(".compass") !== null)
  1349. {
  1350. document.querySelector(".compass").style.visibility = "";
  1351. }
  1352. myLog("Kakao Duel Canvas loaded");
  1353. }
  1354. else if (nextPlayer === "Yandex")
  1355. {
  1356. document.getElementById("default_player").className = "inactive";
  1357. document.getElementById("PanoramaMap").className = "inactive";
  1358. document.getElementById("roadview").className = "inactive";
  1359. document.getElementById("mly").style.visibility = "hidden";
  1360. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "";
  1361. document.getElementById("Main Button").google = false;
  1362. document.getElementById("switch").nextPlayer = "Yandex";
  1363. document.getElementById("switch").useGoogle = false;
  1364. document.querySelector(".ymaps-2-1-79-panorama-screen").style.position = "absolute";
  1365. if (document.querySelector(".compass") !== null)
  1366. {
  1367. document.querySelector(".compass").style.visibility = "";
  1368. }
  1369. myLog("Yandex Duel Canvas loaded");
  1370. }
  1371. else if (nextPlayer === "Mapillary")
  1372. {
  1373. document.getElementById("default_player").className = "inactive";
  1374. document.getElementById("PanoramaMap").className = "inactive";
  1375. document.getElementById("roadview").className = "inactive";
  1376. document.getElementById("mly").style.visibility = "";
  1377. document.querySelector(".ymaps-2-1-79-panorama-screen").style.visibility = "hidden";
  1378. document.getElementById("Main Button").google = false;
  1379. document.getElementById("switch").nextPlayer = "Mapillary";
  1380. document.getElementById("switch").useGoogle = false;
  1381. document.getElementById("mly").style.position = "absolute";
  1382. if (document.querySelector(".compass") !== null)
  1383. {
  1384. document.querySelector(".compass").style.visibility = "hidden";
  1385. }
  1386. myLog("Mapillary Duel Canvas loaded");
  1387. }
  1388. }
  1389.  
  1390. // for Battle Royale and classic (change visibility)
  1391.  
  1392. function Google() {
  1393. let GOOGLE_MAPS_CANVAS = ""
  1394. if (isBattleRoyale) {
  1395. GOOGLE_MAPS_CANVAS = document.querySelector(".br-game-layout__panorama-canvas");
  1396. }
  1397. else {
  1398. GOOGLE_MAPS_CANVAS = document.querySelector(".game-layout__panorama-canvas");
  1399. }
  1400. if (nextPlayer === "Google") {
  1401. GOOGLE_MAPS_CANVAS.style.visibility = "";
  1402. document.getElementById("Main Button").google = true;
  1403. document.getElementById("switch").nextPlayer = "Google";
  1404. document.getElementById("switch").useGoogle = true;
  1405. myLog("Google Canvas loaded");
  1406. }
  1407. else {
  1408. GOOGLE_MAPS_CANVAS.style.visibility = "hidden";
  1409. document.getElementById("Main Button").google = false;
  1410. myLog("Google Canvas hidden");
  1411. }
  1412.  
  1413. }
  1414.  
  1415. function Baidu() {
  1416. let BAIDU_MAPS_CANVAS = document.getElementById("PanoramaMap");
  1417. // myLog("Baidu canvas");
  1418. document.getElementById("PanoramaMap").style.position = "absolute";
  1419. if (BAIDU_MAPS_CANVAS != null)
  1420. {
  1421. if (nextPlayer === "Baidu") {
  1422. BAIDU_MAPS_CANVAS.style.visibility = "";
  1423. document.getElementById("switch").nextPlayer = "Baidu";
  1424. document.getElementById("switch").useGoogle = false;
  1425. if (document.querySelector(".compass") !== null)
  1426. {
  1427. document.querySelector(".compass").style.visibility = "hidden";
  1428. }
  1429. myLog("Baidu Canvas loaded");
  1430. }
  1431. else {
  1432. if (document.querySelector(".compass") !== null)
  1433. {
  1434. document.querySelector(".compass").style.visibility = "";
  1435. }
  1436. BAIDU_MAPS_CANVAS.style.visibility = "hidden";
  1437. myLog("Baidu Canvas hidden");
  1438. }
  1439. }
  1440. else
  1441. {
  1442. setTimeout(Baidu, 250);
  1443. }
  1444.  
  1445. }
  1446.  
  1447. function Kakao() {
  1448. let KAKAO_MAPS_CANVAS = document.getElementById("roadview");
  1449. // myLog("Kakao canvas");
  1450. document.getElementById("roadview").style.position = "absolute";
  1451. if (KAKAO_MAPS_CANVAS != null)
  1452. {
  1453. if (nextPlayer === "Kakao") {
  1454. KAKAO_MAPS_CANVAS.style.visibility = "";
  1455. document.getElementById("switch").nextPlayer = "Kakao";
  1456. document.getElementById("switch").useGoogle = false;
  1457. myLog("Kakao Canvas loaded");
  1458. }
  1459. else {
  1460. KAKAO_MAPS_CANVAS.style.visibility = "hidden";
  1461. myLog("Kakao Canvas hidden");
  1462. }
  1463. }
  1464. else
  1465. {
  1466. setTimeout(Kakao, 250);
  1467. }
  1468.  
  1469. }
  1470.  
  1471. function Yandex() {
  1472. let YANDEX_MAPS_CANVAS = document.querySelector(".ymaps-2-1-79-panorama-screen");
  1473. if (YANDEX_MAPS_CANVAS != null)
  1474. {
  1475. // myLog("Yandex canvas");
  1476. document.querySelector(".ymaps-2-1-79-panorama-screen").style.position = "absolute";
  1477. // myLog("Yandex canvas");
  1478. /* myLog(YANDEX_MAPS_CANVAS); */
  1479. if (nextPlayer === "Yandex") {
  1480. YANDEX_MAPS_CANVAS.style.visibility = "";
  1481. document.getElementById("switch").nextPlayer = "Yandex";
  1482. document.getElementById("switch").useGoogle = false;
  1483. myLog("Yandex Canvas loaded");
  1484. }
  1485. else {
  1486. YANDEX_MAPS_CANVAS.style.visibility = "hidden";
  1487. myLog("Yandex Canvas hidden");
  1488. }
  1489. }
  1490. else
  1491. {
  1492. setTimeout(Yandex, 250);
  1493. }
  1494.  
  1495. }
  1496.  
  1497. function Mapillary()
  1498. {
  1499.  
  1500. let MAPILLARY_MAPS_CANVAS = document.getElementById("mly");
  1501. if (MAPILLARY_MAPS_CANVAS != null)
  1502. {
  1503. // myLog("Mapillary canvas");
  1504. MAPILLARY_MAPS_CANVAS.style.position = "absolute";
  1505. if (nextPlayer === "Mapillary") {
  1506. MAPILLARY_MAPS_CANVAS.style.visibility = "";
  1507. document.getElementById("switch").nextPlayer = "Mapillary";
  1508. document.getElementById("switch").useGoogle = false;
  1509. myLog("Mapillary Canvas loaded");
  1510. }
  1511. else {
  1512. MAPILLARY_MAPS_CANVAS.style.visibility = "hidden";
  1513. myLog("Mapillary Canvas hidden");
  1514. }
  1515. }
  1516. else
  1517. {
  1518. setTimeout(Mapillary, 250);
  1519. }
  1520.  
  1521. }
  1522.  
  1523. /**
  1524. * Adjust button placement
  1525. */
  1526.  
  1527. function ZoomControls() {
  1528. let style = `
  1529. .ymaps-2-1-79-panorama-gotoymaps {display: none !important;}
  1530. .game-layout__controls {bottom: 8rem !important; left: 1rem !important;}
  1531. `;
  1532.  
  1533. let style_element = document.createElement("style");
  1534. style_element.innerHTML = style;
  1535. document.body.appendChild(style_element);
  1536. }
  1537.  
  1538. /**
  1539. * Updates the compass to match Yandex Panorama facing
  1540. */
  1541. function updateCompass() {
  1542. if (!COMPASS) {
  1543. let compass = document.querySelector("img.compass__indicator");
  1544. if (compass != null) {
  1545. COMPASS = compass;
  1546. let direction = YandexPlayer.getDirection()[0] * -1;
  1547. COMPASS.setAttribute("style", `transform: rotate(${direction}deg);`);
  1548. }
  1549. }
  1550. else {
  1551. let direction = YandexPlayer.getDirection()[0] * -1;
  1552. COMPASS.setAttribute("style", `transform: rotate(${direction}deg);`);
  1553. }
  1554. }
  1555.  
  1556. /**
  1557. * Open next location in streetview player given next player and next coordinate
  1558. */
  1559.  
  1560. function goToLocation() {
  1561. myLog("Going to location");
  1562. if (nextPlayer === "Yandex") {
  1563. let options = {};
  1564. YandexPlayer.moveTo([global_lat, global_lng], options);
  1565. YandexPlayer.setDirection([0, 16]);
  1566. YandexPlayer.setSpan([10, 67]);
  1567. }
  1568. else if (nextPlayer === "Baidu") {
  1569. let a = new BMap.Point(global_lng, global_lat);
  1570. BaiduPlayer.setPov({ heading: -40, pitch: 6 });
  1571. BaiduPlayer.setPosition(a);
  1572. }
  1573. else if (nextPlayer === "Kakao") {
  1574. var roadviewClient = new kakao.maps.RoadviewClient();
  1575. var position = new kakao.maps.LatLng(global_lat, global_lng);
  1576. roadviewClient.getNearestPanoId(position, 500, function (panoId) {
  1577. KakaoPlayer.setPanoId(panoId, position);
  1578. KakaoPlayer.setViewpoint({ pan: global_heading, tilt: global_pitch, zoom: 0 })
  1579. });
  1580. }
  1581. else if (nextPlayer === "Mapillary") {
  1582. MapillaryPlayer.moveTo(mmKey).then(
  1583. image => { //myLog(image);
  1584. },
  1585. error => { myLog(error); });
  1586. }
  1587. else if (nextPlayer === "Google") {
  1588. handleMapillary({lat: global_lat, lng: global_lng}, {meters: 500, limit: 500});
  1589. }
  1590. document.getElementById("switch").lat = global_lat;
  1591. document.getElementById("switch").lng = global_lng;
  1592. }
  1593.  
  1594. /**
  1595. * Handle undo using the location history of the current round
  1596. */
  1597.  
  1598. function goToUndoMove(data) {
  1599. /* myLog(global_lat);
  1600. myLog(global_lng); */
  1601. let options = {};
  1602. let prevStep = null;
  1603. if (locHistory.length === 1) {
  1604. prevStep = locHistory[0];
  1605. }
  1606. else {
  1607. prevStep = locHistory.pop();
  1608. }
  1609. // myLog(prevStep);
  1610. // myLog(locHistory)
  1611. if (nextPlayer === "Yandex") {
  1612. defaultPanoIdChange = false;
  1613. YandexPlayer.moveTo([prevStep[0], prevStep[1]], options);
  1614. YandexPlayer.setDirection([prevStep[2], prevStep[3]]);
  1615. YandexPlayer.setSpan([10, 67]);
  1616. document.getElementById("switch").lat = prevStep[0];
  1617. document.getElementById("switch").lng = prevStep[1];
  1618. }
  1619. else if (nextPlayer === "Kakao") {
  1620. let btn = document.querySelector("button[data-qa='undo-move']");
  1621. btn.disabled = false;
  1622. btn.classList.remove('styles_disabled__W_k45');
  1623. defaultPanoIdChange = false;
  1624. let position = new kakao.maps.LatLng(prevStep[0], prevStep[1]);
  1625. KakaoPlayer.setPanoId(prevStep[2], position);
  1626. document.getElementById("switch").lat = prevStep[0];
  1627. document.getElementById("switch").lng = prevStep[1];
  1628. document.getElementById("switch").useGoogle = false;
  1629. document.getElementById("Main Button").google = false;
  1630. // myLog("Undo 1 step");
  1631. // myLog(locHistory);
  1632. }
  1633. else if (nextPlayer === "Baidu") {
  1634. // myLog(prevStep[1]);
  1635. let position = new BMap.Point(prevStep[1], prevStep[0]);
  1636. let pov = { heading: prevStep[2], pitch: prevStep[3] };
  1637. BaiduPlayer.setPosition(position);
  1638. BaiduPlayer.setPov(pov);
  1639. document.getElementById("switch").lat = prevStep[1];
  1640. document.getElementById("switch").lng = prevStep[0];
  1641. }
  1642. else if (nextPlayer === "Mapillary" ) {
  1643. // myLog(prevStep[1]);
  1644.  
  1645. MapillaryPlayer.moveTo(prevStep[2]).then(
  1646. image => {
  1647. //myLog(image);
  1648. document.getElementById("switch").lat = prevStep[1];
  1649. document.getElementById("switch").lng = prevStep[0];
  1650. },
  1651. error => { myLog(error); });
  1652. }
  1653.  
  1654. }
  1655.  
  1656. function BYKTeleport()
  1657. {
  1658. let teleportButtonBYK = document.getElementById("Main Button");
  1659. if (teleportButtonBYK)
  1660. {
  1661. teleportButtonBYK.addEventListener("click", () => {
  1662. if (!teleportButtonBYK.google)
  1663. {
  1664. // myLog("non-Google Teleport");
  1665. let prevStep = null;
  1666. if (locHistory.length === 1) {
  1667. prevStep = locHistory[0];
  1668. }
  1669. else {
  1670. prevStep = locHistory[locHistory.length - 1];
  1671. }
  1672. // myLog(prevStep);
  1673. let options = {};
  1674. let place, position, pID;
  1675. if (nextPlayer === "Yandex") {
  1676. place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[2]), teleportButtonBYK.distance * 0.001);
  1677. YandexPlayer.setDirection([prevStep[2], prevStep[3]]);
  1678. YandexPlayer.moveTo([place.lat, place.lng], options);
  1679. YandexPlayer.setSpan([10, 67]);
  1680. // locHistory.push([place.lat, place.lng, prevStep[2], prevStep[3]]);
  1681. }
  1682. else if (nextPlayer === "Kakao") {
  1683. // place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[3]), teleportButtonBYK.distance * 0.001);
  1684. // position = new kakao.maps.LatLng(place.lat, place.lng);
  1685. // pID = KakaoPlayer.getViewpointWithPanoId();
  1686. // KakaoPlayer.setPanoId(pID.panoId, position);
  1687. // locHistory.push([place.lat, place.lng, pID.panoId, prevStep[3]]);
  1688. var roadviewClient = new kakao.maps.RoadviewClient();
  1689. place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[3]), teleportButtonBYK.distance * 0.001);
  1690. position = new kakao.maps.LatLng(place.lat, place.lng);
  1691. roadviewClient.getNearestPanoId(position, 500, function (panoId) {
  1692. KakaoPlayer.setPanoId(panoId, position);
  1693. // myLog("Teleport 1 step");
  1694. // myLog(locHistory);
  1695. // locHistory.push([place.lat, place.lng, panoId, prevStep[3]]);
  1696. });
  1697. }
  1698. else if (nextPlayer === "Baidu") {
  1699. place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[2]), teleportButtonBYK.distance * 0.001);
  1700. position = new BMap.Point(place.lng, place.lat);
  1701. let pov = { heading: prevStep[2], pitch: prevStep[3] };
  1702. BaiduPlayer.setPosition(position);
  1703. BaiduPlayer.setPov(pov);
  1704. // locHistory.push([place.lat, place.lng, prevStep[2], prevStep[3]]);
  1705. }
  1706. else if (nextPlayer === "Mapillary" || nextPlayer === "Google") {
  1707. place = FindPointAtDistanceFrom(prevStep[0], prevStep[1], DegreesToRadians(prevStep[2]), teleportButtonBYK.distance * 0.001);
  1708. handleMapillary(place, {meters: 500, limit: 500});
  1709. // locHistory.push([place.lat, place.lng, prevStep[2], prevStep[3]]);
  1710. }
  1711. document.getElementById("switch").lat = place.lat;
  1712. document.getElementById("switch").lng = place.lng;
  1713. if (teleportButtonBYK.distance > 150)
  1714. {
  1715. teleportButtonBYK.distance = 100;
  1716. teleportButtonBYK.innerHTML = "Teleport " + teleportButtonBYK.distance + " m";
  1717. }
  1718. }
  1719. });
  1720. }
  1721. else
  1722. {
  1723. }
  1724. }
  1725.  
  1726. function SyncListener()
  1727. {
  1728. let googleKakaoButton = document.getElementById("switch");
  1729. googleKakaoButton.addEventListener("click", () => {
  1730. if (googleKakaoButton.useGoogle == false) {
  1731. // googleKakaoButton.useGoogle = true;
  1732. if (googleKakaoButton.nextPlayer === "Yandex") {
  1733. let options = {};
  1734. YandexPlayer.moveTo([googleKakaoButton.lat, googleKakaoButton.lng], options);
  1735. YandexPlayer.setDirection([document.getElementById("switch").heading, 0]);
  1736.  
  1737. // document.getElementById("switch").nextPlayer = "Yandex";
  1738. }
  1739. if (googleKakaoButton.nextPlayer === "Baidu") {
  1740. let CANVAS = document.getElementById("PanoramaMap");
  1741. if (!googleKakaoButton.small_canvas)
  1742. {
  1743. CANVAS.style.width = window.innerHeight + "px";
  1744. if (isBattleRoyale && !isDuel)
  1745. {
  1746. CANVAS.style.left = (window.innerWidth - window.innerHeight)*0.78 / 2 + "px";
  1747. }
  1748. else
  1749. {
  1750. CANVAS.style.left = (window.innerWidth - window.innerHeight) / 2 + "px";
  1751. }
  1752. googleKakaoButton.small_canvas = true;
  1753. document.getElementById("switch").innerHTML = "Widescreen";
  1754. }
  1755. else
  1756. {
  1757. CANVAS.style.width = window.innerWidth + "px";
  1758. CANVAS.style.left = "0px";
  1759. googleKakaoButton.small_canvas = false;
  1760. document.getElementById("switch").innerHTML = "More Viewing Area";
  1761. }
  1762. }
  1763. else if (googleKakaoButton.nextPlayer === "Kakao") {
  1764. let roadviewClient = new kakao.maps.RoadviewClient();
  1765. // myLog(googleKakaoButton.lat);
  1766. let position = new kakao.maps.LatLng(googleKakaoButton.lat, googleKakaoButton.lng);
  1767. roadviewClient.getNearestPanoId(position, 500, function (panoId) {
  1768. KakaoPlayer.setPanoId(panoId, position);
  1769. });
  1770. KakaoPlayer.setViewpoint({
  1771. pan: document.getElementById("switch").heading,
  1772. tilt: 0,
  1773. zoom: 0
  1774. });
  1775. // document.getElementById("switch").nextPlayer = "Kakao";
  1776. }
  1777. else if (googleKakaoButton.nextPlayer === "Mapillary" || googleKakaoButton.nextPlayer === "Google") {
  1778. // document.getElementById("switch").nextPlayer = "Kakao";
  1779. handleMapillary({lat: googleKakaoButton.lat, lng: googleKakaoButton.lng}, {meters: 100, limit: 100});
  1780. }
  1781. }
  1782. });
  1783.  
  1784. }
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790. /**
  1791. * Gets the seed data for the current game
  1792. *
  1793. * @returns Promise with seed data as object
  1794. */
  1795. function getSeed() {
  1796. // myLog("getSeed called");
  1797. return new Promise((resolve, reject) => {
  1798. let token = getToken();
  1799. let URL;
  1800. let cred = ""
  1801.  
  1802. const PATHNAME = window.location.pathname;
  1803.  
  1804. if (PATHNAME.startsWith("/game/")) {
  1805. URL = `https://www.geoguessr.com/api/v3/games/${token}`;
  1806. }
  1807. else if (PATHNAME.startsWith("/challenge/")) {
  1808. URL = `https://www.geoguessr.com/api/v3/challenges/${token}/game`;
  1809. }
  1810. else if (PATHNAME.startsWith("/battle-royale/")) {
  1811. URL = `https://game-server.geoguessr.com/api/battle-royale/${token}`;
  1812. }
  1813. else if (PATHNAME.startsWith("/duels/") || PATHNAME.startsWith("/team-duels/")) {
  1814. URL = `https://game-server.geoguessr.com/api/duels/${token}`;
  1815. }
  1816. if (isBattleRoyale) {
  1817. fetch(URL, {
  1818. // Include credentials to GET from the endpoint
  1819. credentials: 'include'
  1820. })
  1821. .then((response) => response.json())
  1822. .then((data) => {
  1823. resolve(data);
  1824. })
  1825. .catch((error) => {
  1826. reject(error);
  1827. });
  1828. }
  1829. else {
  1830. fetch(URL)
  1831. .then((response) => response.json())
  1832. .then((data) => {
  1833. resolve(data);
  1834. })
  1835. .catch((error) => {
  1836. reject(error);
  1837. });
  1838. }
  1839. });
  1840. }
  1841.  
  1842. /**
  1843. * Gets the token from the current URL
  1844. *
  1845. * @returns token
  1846. */
  1847. function getToken() {
  1848. const PATHNAME = window.location.pathname;
  1849. if (PATHNAME.startsWith("/game/")) {
  1850. return PATHNAME.replace("/game/", "");
  1851. }
  1852. else if (PATHNAME.startsWith("/challenge/")) {
  1853. return PATHNAME.replace("/challenge/", "");
  1854. }
  1855. else if (PATHNAME.startsWith("/battle-royale/")) {
  1856. return PATHNAME.replace("/battle-royale/", "");
  1857. }
  1858. else if (PATHNAME.startsWith("/duels/")) {
  1859. return PATHNAME.replace("/duels/", "");
  1860. }
  1861. else if (PATHNAME.startsWith("/team-duels/")) {
  1862. return PATHNAME.replace("/team-duels/", "");
  1863. }
  1864. }
  1865.  
  1866. /**
  1867. * Gets the round number from the ongoing game from the page itself
  1868. *
  1869. * @returns Round number
  1870. */
  1871. function getRoundFromPage() {
  1872. const roundData = document.querySelector("div[data-qa='round-number']");
  1873. if (roundData) {
  1874. let roundElement = roundData.querySelector("div:last-child");
  1875. if (roundElement) {
  1876. let round = parseInt(roundElement.innerText.charAt(0));
  1877. if (!isNaN(round) && round >= 1 && round <= 5) {
  1878. return round;
  1879. }
  1880. }
  1881. }
  1882. else {
  1883. return ROUND;
  1884. }
  1885. }
  1886.  
  1887.  
  1888. /**
  1889. * Injects Yandex Script
  1890. */
  1891. function injectYandexScript() {
  1892. return new Promise((resolve, reject) => {
  1893. if (!YANDEX_INJECTED) {
  1894. if (YANDEX_API_KEY === "") {
  1895. myLog("No Yandex Key")
  1896. reject();
  1897. }
  1898. else {
  1899. const SCRIPT = document.createElement("script");
  1900. SCRIPT.type = "text/javascript";
  1901. SCRIPT.async = true;
  1902. SCRIPT.onload = () => {
  1903. ymaps.ready(() => {
  1904. YANDEX_INJECTED = true;
  1905. myHighlight("Yandex API Loaded");
  1906. resolve();
  1907. });
  1908. }
  1909. SCRIPT.src = `https://api-maps.yandex.ru/2.1/?lang=en_US&apikey=${YANDEX_API_KEY}`;
  1910. document.body.appendChild(SCRIPT);
  1911. }
  1912. }
  1913. else {
  1914. resolve();
  1915. }
  1916. });
  1917. }
  1918.  
  1919. /**
  1920. * Injects Yandex Player and calls handleReturnToStart
  1921. */
  1922. function injectYandexPlayer() {
  1923. let lat = 41.321861;
  1924. let lng = 69.212920;
  1925.  
  1926. let options = {
  1927. "direction": [0, 16],
  1928. "span": [10, 67],
  1929. "controls": ["zoomControl"]
  1930. };
  1931. ymaps.panorama.createPlayer("player", [lat, lng], options)
  1932. .done((player) => {
  1933. YandexPlayer = player;
  1934. YandexPlayer.events.add("directionchange", (e) => {
  1935. updateCompass();
  1936. let pov = YandexPlayer.getDirection();
  1937. if (locHistory.length > 0 && nextPlayer == "Yandex") {
  1938. document.getElementById("switch").heading = pov[0];
  1939. locHistory[locHistory.length - 1][2] = pov[0];
  1940. locHistory[locHistory.length - 1][3] = pov[1];
  1941. }
  1942. });
  1943. YandexPlayer.events.add("panoramachange", (e) => {
  1944. if (defaultPanoIdChange) {
  1945. let num = YandexPlayer.getPanorama().getPosition();
  1946. let pov = YandexPlayer.getDirection();
  1947. // myLog(num);
  1948. // myLog(pov);
  1949. if (nextPlayer == "Yandex")
  1950. {
  1951. locHistory.push([num[0], num[1], pov[0], pov[1]]);
  1952. document.getElementById("switch").lat = num[0];
  1953. document.getElementById("switch").lng = num[1];
  1954. }
  1955. let btn = document.querySelector("button[data-qa='undo-move']");
  1956. if (locHistory.length > 1) {
  1957. btn.disabled = false;
  1958. btn.classList.remove('styles_disabled__W_k45');
  1959. }
  1960. // myLog(locHistory);
  1961. }
  1962. defaultPanoIdChange = true;
  1963.  
  1964. });
  1965. myLog("Yandex Player injected");
  1966. });
  1967.  
  1968. }
  1969.  
  1970.  
  1971. /**
  1972. * Injects Baidu script
  1973. */
  1974.  
  1975. function injectBaiduScript() {
  1976. return new Promise((resolve, reject) => {
  1977. if (!BAIDU_INJECTED) {
  1978. if (BAIDU_API_KEY === "") {
  1979. let canvas = document.getElementById("player");
  1980. myLog("No Baidu Key")
  1981. }
  1982. else {
  1983. const SCRIPT = document.createElement("script");
  1984. SCRIPT.type = "text/javascript";
  1985. SCRIPT.async = true;
  1986. SCRIPT.src = `https://api.map.baidu.com/api?v=3.0&ak=${BAIDU_API_KEY}&callback=init`;
  1987. document.body.appendChild(SCRIPT);
  1988.  
  1989. let canvas = document.createElement("bmap");
  1990. if (isBattleRoyale) {
  1991. if (isDuel)
  1992. {
  1993. canvas.innerHTML = `
  1994. <div id="PanoramaMap" class="inactive" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  1995. `;
  1996. }
  1997. else
  1998. {
  1999. canvas.innerHTML = `
  2000. <div id="PanoramaMap" class="br-game-layout__panorama" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  2001. `;
  2002. }
  2003. }
  2004. else {
  2005. canvas.innerHTML = `
  2006. <div id="PanoramaMap" class="game-layout__panorama" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  2007. `;
  2008. }
  2009.  
  2010. var div = document.getElementById("player");
  2011. div.appendChild(canvas);
  2012.  
  2013. SCRIPT.addEventListener('load', () => {
  2014. myHighlight("Baidu API Loaded");
  2015. // resolve(BMap);
  2016. let timeout = 0;
  2017. let interval = setInterval(() => {
  2018. if (timeout >= 40) {
  2019. reject();
  2020. clearInterval(interval);
  2021. }
  2022. if (typeof BMap.Panorama !== typeof undefined) {
  2023. BAIDU_INJECTED = true;
  2024. resolve(BMap);
  2025. clearInterval(interval);
  2026. }
  2027. timeout += 1;
  2028. }, 500);
  2029. })
  2030.  
  2031.  
  2032. }
  2033. }
  2034. else {
  2035. resolve();
  2036. }
  2037. });
  2038. }
  2039.  
  2040. /**
  2041. * Injects Baidu Player and calls handleReturnToStart
  2042. */
  2043. function injectBaiduPlayer() {
  2044. injectBaiduScript().then(BMap => {
  2045. BaiduPlayer = new BMap.Panorama('PanoramaMap');
  2046. BaiduPlayer.setPov({ heading: -40, pitch: 6 });
  2047. BaiduPlayer.setPosition(new BMap.Point(0, 0));
  2048. if (!eventListenerAttached && !povListenerAttached) {
  2049. myLog("position_listener attached");
  2050. BaiduPlayer.addEventListener('position_changed', function (e) {
  2051. eventListenerAttached = true;
  2052. myLog('position_changed')
  2053. let num = BaiduPlayer.getPosition();
  2054. let pov = BaiduPlayer.getPov();
  2055. if (nextPlayer == "Baidu" && num.lat != 0)
  2056. {
  2057. locHistory.push([num.lat, num.lng, pov.heading, pov.pitch]);
  2058. }
  2059. if (!isBattleRoyale || isDuel)
  2060. {
  2061. let btn = document.querySelector("button[data-qa='undo-move']");
  2062. if (locHistory.length > 1) {
  2063. btn.disabled = false;
  2064. btn.classList.remove('styles_disabled__W_k45');
  2065. }
  2066. }
  2067. // myLog(locHistory);
  2068. })
  2069.  
  2070. BaiduPlayer.addEventListener('pov_changed', function (e) {
  2071. // myLog("pov_listener attached");
  2072. povListenerAttached = true;
  2073. // myLog('pov_changed')
  2074. let pov = BaiduPlayer.getPov();
  2075. if (locHistory.length > 0 && nextPlayer == "Baidu") {
  2076. locHistory[locHistory.length - 1][2] = pov.heading;
  2077. locHistory[locHistory.length - 1][3] = pov.pitch;
  2078. }
  2079. // myLog(locHistory);
  2080. })
  2081. }
  2082. });
  2083. }
  2084.  
  2085. /**
  2086. * Injects Kakao script
  2087. */
  2088.  
  2089. function injectKakaoScript() {
  2090. return new Promise((resolve, reject) => {
  2091. if (!KAKAO_INJECTED) {
  2092. if (KAKAO_API_KEY === "") {
  2093. myLog("No Kakao Key")
  2094. }
  2095. else {
  2096.  
  2097. let canvas = document.createElement("kmap");
  2098. if (isBattleRoyale) {
  2099. if (isDuel)
  2100. {
  2101. canvas.innerHTML = `
  2102. <div id="roadview" class="inactive" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  2103. `;
  2104. }
  2105. else
  2106. {
  2107. canvas.innerHTML = `
  2108. <div id="roadview" class="br-game-layout__panorama" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  2109. `;
  2110. }
  2111. }
  2112. else {
  2113. canvas.innerHTML = `
  2114. <div id="roadview" class="game-layout__panorama" style="zIndex: 99999,position: "absolute", top: 0, left: 0, width: '100%', height: '100%',"> </div>
  2115. `;
  2116. }
  2117.  
  2118. var div = document.getElementById("player");
  2119. div.appendChild(canvas);
  2120.  
  2121. const SCRIPT = document.createElement("script");
  2122. SCRIPT.async = true;
  2123. // SCRIPT.type = "text/javascript";
  2124. SCRIPT.src = `//dapi.kakao.com/v2/maps/sdk.js?appkey=${KAKAO_API_KEY}&autoload=false`;
  2125. document.body.appendChild(SCRIPT);
  2126. SCRIPT.onload = () => {
  2127. kakao.maps.load(function () {
  2128. var position = new kakao.maps.LatLng(33.450701, 126.560667);
  2129. let roadviewContainer = document.getElementById('roadview');
  2130. KakaoPlayer = new kakao.maps.Roadview(roadviewContainer);
  2131. var panoId = 1023434522;
  2132. KakaoPlayer.setPanoId(panoId, position);
  2133. KAKAO_INJECTED = true;
  2134. // Remove the compass from Kakao
  2135. kakao.maps.event.addListener(KakaoPlayer, 'init', () => {
  2136. const compassContainer = roadviewContainer.querySelector('div[id*="_box_util_"]');
  2137. if (compassContainer) compassContainer.style.display = 'none';
  2138. });
  2139. kakao.maps.event.addListener(KakaoPlayer, 'panoid_changed', function() {
  2140. if (defaultPanoIdChange) {
  2141. let latlng = KakaoPlayer.getPosition();
  2142. let lat = latlng.getLat();
  2143. let lng = latlng.getLng();
  2144. let pID = KakaoPlayer.getViewpointWithPanoId();
  2145. if (nextPlayer == "Kakao" && lat != 33.45047613915499)
  2146. {
  2147. // myLog("push");
  2148. locHistory.push([lat, lng, pID.panoId, pID.pan]);
  2149. document.getElementById("switch").lat = lat;
  2150. document.getElementById("switch").lng = lng;
  2151. document.getElementById("switch").heading = pID.pan;
  2152. }
  2153. let btn = document.querySelector("button[data-qa='undo-move']");
  2154. if (locHistory.length > 1 && (btn != null)) {
  2155. btn.disabled = false;
  2156. btn.classList.remove('styles_disabled__W_k45');
  2157. }
  2158. // myLog(locHistory);
  2159. }
  2160. defaultPanoIdChange = true;
  2161. });
  2162. kakao.maps.event.addListener(KakaoPlayer, 'viewpoint_changed', function() {
  2163. // myLog("pov_listener attached");
  2164. let pID = KakaoPlayer.getViewpointWithPanoId();
  2165. if (locHistory.length > 0 && nextPlayer == "Kakao") {
  2166. document.getElementById("switch").heading = pID.pan;
  2167. locHistory[locHistory.length - 1][3] = pID.pan;
  2168. }
  2169. if (GooglePlayer) {
  2170. const { heading, pitch } = GooglePlayer.getPov()
  2171. if (!almostEqual(pID.pan, heading) || !almostEqual(pID.tilt, pitch)) {
  2172. // Updating the google street view POV will update the compass
  2173. GooglePlayer.setPov({ heading: pID.pan, pitch: pID.tilt })
  2174. }
  2175. }
  2176. // myLog(locHistory);
  2177. })
  2178. myHighlight("Kakao API Loaded");
  2179. resolve();
  2180. });
  2181. };
  2182.  
  2183. }
  2184. }
  2185. else {
  2186. resolve();
  2187. }
  2188. });
  2189. }
  2190.  
  2191.  
  2192.  
  2193. function injectMapillaryPlayer() {
  2194. return new Promise((resolve, reject) => {
  2195. if (!MAPILLARY_INJECTED) {
  2196. if (MAPILLARY_API_KEY === "") {
  2197. let canvas = document.getElementById("player");
  2198. myLog("No Mapillary Key")
  2199. }
  2200. else {
  2201. const SCRIPT = document.createElement("script");
  2202. SCRIPT.type = "text/javascript";
  2203. SCRIPT.async = true;
  2204. SCRIPT.src = `https://unpkg.com/mapillary-js@4.0.0/dist/mapillary.js`;
  2205. document.body.appendChild(SCRIPT);
  2206. document.querySelector('head').innerHTML += '<link href="https://unpkg.com/mapillary-js@4.0.0/dist/mapillary.css" rel="stylesheet"/>';
  2207. let canvas = document.createElement("mmap");
  2208. if (isBattleRoyale) {
  2209. if (isDuel)
  2210. {
  2211.  
  2212. canvas.innerHTML = `<div id="mly" class="inactive" style="zIndex: 99999, position: 'absolute', top: 0, left: 0, width: '100%', height: '100%'"></div>`;
  2213. }
  2214. else
  2215. {
  2216. canvas.innerHTML = `<div id="mly" class="br-game-layout__panorama" style="zIndex: 99999, position: 'absolute', top: 0, left: 0, width: '100%', height: '100%'"></div>`;
  2217. }
  2218. }
  2219. else {
  2220. canvas.innerHTML = `<div id="mly" class="game-layout__panorama" style="zIndex: 99999, position: 'absolute', top: 0, left: 0, width: '100%', height: '100%'"></div>`;
  2221. }
  2222.  
  2223. var div = document.getElementById("player");
  2224. div.appendChild(canvas);
  2225.  
  2226. SCRIPT.addEventListener('load', () => {
  2227. myHighlight("Mapillary API Loaded");
  2228. // resolve(BMap);
  2229. var {Viewer} = mapillary;
  2230.  
  2231. MapillaryPlayer = new Viewer({
  2232. accessToken: MAPILLARY_API_KEY,
  2233. container: 'mly', // the ID of our container defined in the HTML body
  2234. });
  2235.  
  2236. MapillaryPlayer.on('position', async (event) => {
  2237. MapillaryPlayer.getImage().then(image => {
  2238. let pos = image.originalLngLat;
  2239. let cond = true;
  2240. for (const element of locHistory) {
  2241. if (element[2] == image.id)
  2242. {
  2243. cond = false;
  2244. }
  2245. }
  2246. if (cond)
  2247. {
  2248. document.getElementById("switch").lat = pos.lat;
  2249. document.getElementById("switch").lng = pos.lng;
  2250. document.getElementById("switch").heading = image.compassAngle;
  2251. // myLog(pos);
  2252. locHistory.push([pos.lat, pos.lng, image.id, image.compassAngle]);
  2253. }
  2254. let btn = document.querySelector("button[data-qa='undo-move']");
  2255. if (btn !== null && locHistory.length > 1)
  2256. {
  2257. btn.disabled = false;
  2258. btn.classList.remove('styles_disabled__W_k45');
  2259. }
  2260. });
  2261. });
  2262.  
  2263. MAPILLARY_INJECTED = true;
  2264. resolve();
  2265. })
  2266.  
  2267.  
  2268. }
  2269. }
  2270. else {
  2271. resolve();
  2272. }
  2273. });
  2274. }
  2275.  
  2276.  
  2277. function handleMapillary(latlng, options)
  2278. {
  2279. myLog("handleMapillary")
  2280. handleMapillaryHelper(latlng, options).then((data) => {
  2281. //myLog(data.data)
  2282. let idToSet = 0;
  2283. let curDist = 100000000;
  2284. for (const element of data.data) {
  2285. // myLog(element)
  2286. try {
  2287. let rCord = element.computed_geometry["coordinates"];
  2288. let dist = distance(latlng.lat,latlng.lng,rCord[1],rCord[0])
  2289. if (dist < curDist)
  2290. {
  2291. idToSet = element.id;
  2292. curDist = dist
  2293. }
  2294. } catch (e) {
  2295. // statements to handle any exceptions
  2296. myLog("Error")
  2297. }
  2298. }
  2299. if (idToSet !== 0)
  2300. {
  2301. MapillaryPlayer.moveTo(idToSet).then(
  2302. image => { //myLog(image);
  2303. },
  2304. error => { myLog(error); });
  2305. }}).catch((error) => {
  2306. myLog(error);
  2307. });
  2308. }
  2309.  
  2310. function handleMapillaryHelper(latlng, options)
  2311. {
  2312. return new Promise((resolve, reject) => {
  2313. let bbox = getBBox(latlng, options.meters);
  2314. 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)
  2315. //myLog(URL)
  2316. fetch(URL)
  2317. .then((response) => {resolve(response.json())})
  2318. .catch((error) => {myLog(error);});
  2319. });
  2320. }
  2321.  
  2322. function moveFrom(coords, angle, distance){
  2323. const R_EARTH = 6378.137;
  2324. const M = (1 / ((2 * Math.PI / 360) * R_EARTH)) / 1000;
  2325. let radianAngle = -angle * Math.PI / 180;
  2326. let x = 0 + (distance * Math.cos(radianAngle));
  2327. let y = 0 + (distance * Math.sin(radianAngle));
  2328.  
  2329. let newLat = coords.lat + (y * M);
  2330. let newLng = coords.lng + (x * M) / Math.cos(coords.lat * (Math.PI / 180));
  2331. return { lat: newLat, lng: newLng };
  2332. }
  2333.  
  2334. function getBBox(coordinates, meters){
  2335. let SW = moveFrom(coordinates, 135, meters);
  2336. let NE = moveFrom(coordinates, 315, meters);
  2337. return `${SW.lng},${SW.lat},${NE.lng},${NE.lat}`;
  2338. }
  2339.  
  2340.  
  2341. function distance(lat1, lon1, lat2, lon2) {
  2342. var p = 0.017453292519943295; // Math.PI / 180
  2343. var c = Math.cos;
  2344. var a = 0.5 - c((lat2 - lat1) * p)/2 +
  2345. c(lat1 * p) * c(lat2 * p) *
  2346. (1 - c((lon2 - lon1) * p))/2;
  2347.  
  2348. return 1000 * 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
  2349. }