Geoguessr Unity Script

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

当前为 2022-01-22 提交的版本,查看 最新版本

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