Idle Pixel Rocket Tracker

Adds moon and sun distance notifications.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Idle Pixel Rocket Tracker
// @namespace    none
// @version      1.3
// @description  Adds moon and sun distance notifications.
// @license      MIT
// @author       Cullen
// @match        https://idle-pixel.com/login/play/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=idle-pixel.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let currentMoonDistance, currentSunDistance, checkingRocketDistance = false;

	const doRocketStuff = () => {
		const oldModalsFunction = Modals.open_send_rocket_dialogue;

		Modals.open_send_rocket_dialogue = (moonDistance, sunDistance) => {
			console.log('dists: ', moonDistance, sunDistance)

			if (currentMoonDistance != moonDistance) {
				currentMoonDistance = moonDistance;
				const moonLabel = document.querySelector('#notification-moon_distance-label');
				moonLabel.innerText = ` ${Number(currentMoonDistance).toLocaleString()} KM`;
				moonLabel.parentElement.style.display = "inline-block";
			}
			if (currentSunDistance != sunDistance) {
				currentSunDistance = sunDistance;
				const sunLabel = document.querySelector('#notification-sun_distance-label')
				sunLabel.innerText = ` ${Number(currentSunDistance).toLocaleString()} KM`;
				sunLabel.parentElement.style.display = "inline-block";
			}

			if (!checkingRocketDistance) {
				oldModalsFunction(moonDistance, sunDistance);
			} else {
				checkingRocketDistance = false;
			}
		}

		addRocketNotifications('moon');
		addRocketNotifications('sun');

		checkRocketDist();

		const rocketStuffInterval = setInterval(checkRocketDist, 3000);
	}

	const checkRocketDist = () => {
		if(Items.getItem('rocket_km') > 0) {
			document.querySelector('#notification-moon_distance').style.display = "none";
			document.querySelector('#notification-sun_distance').style.display = "none";
			return;
		}
		checkingRocketDistance = true;
		websocket.send('CLICKS_ROCKET=0');
	};

	const addRocketNotifications = (label) => {
		const notifDiv = document.createElement('div');
		notifDiv.id = `notification-${label}_distance`;
		notifDiv.className='notification hover';
		notifDiv.style='margin-right: 10px; display: none';

		const notifIcon = document.querySelector(`img[title="${label}"]:not([id*="label"])`);
		notifIcon.className = 'w20'

		const notifDivLabel = document.createElement('span');
		notifDivLabel.id = `notification-${label}_distance-label`;
		notifDivLabel.innerText = ' Loading... ';
		notifDivLabel.className = 'color-white'

		notifDiv.onclick = () => {
			navigator.clipboard.writeText(`${label} distance: ${notifDivLabel.innerText}`);
		}

		notifDiv.append(notifIcon, notifDivLabel)
		document.querySelector('#notifications-area').prepend(notifDiv)
	}


	const doingRocketStuff = setInterval(()=>{
		if(websocket.connected_socket.readyState == 1) {
			clearInterval(doingRocketStuff);
			doRocketStuff();
		}
	}, 100)
})();