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-17 提交的版本。查看 最新版本

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