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.

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

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