Geoguessr Unity Script

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

目前为 2022-01-21 提交的版本。查看 最新版本

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