Geoguessr Unity Script

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

目前为 2021-12-19 提交的版本。查看 最新版本

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