Idle Pixel Rocket Tracker

Adds moon and sun distance notifications.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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)
})();