Idle Pixel Rocket Tracker

Adds moon and sun distance notifications.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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