Easy Easter (PDA)

Detects any eggs on the page and embeds a navigator to jump to any pages. Quick and dirty in classic Kwack fashion

当前为 2024-04-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Easy Easter (PDA)
// @namespace    dev.kwack.torn.easy-easter
// @version      1.0.2
// @description  Detects any eggs on the page and embeds a navigator to jump to any pages. Quick and dirty in classic Kwack fashion
// @author       Kwack [2190604]
// @match        https://www.torn.com/*
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at 		 document-end
// ==/UserScript==

const eggRootSelector = "div#easter-egg-hunt-root";
const eggButtonSelector = "button";

(async () => {
	const makeEggEasyMode = (egg) => egg.addClass("kw--egg-easy-mode");

	addStyles();
	checkForEggs();
	addNavigator();

	async function checkForEggs() {
		const eggRoot = $(eggRootSelector);
		if (!eggRoot.length) return;
		const eggs = await waitForEggSpawn(eggRoot);
		if (eggs.length) {
			const shouldMakeEasyMode = confirm(
				`${eggs.length} egg${eggs.length > 1 ? "s" : ""} detected on the current page! ` +
					"Do you want to enable easy mode? \n" +
					"Warning: this may decrease the number of spawns you receive, use at your own risk."
			);
			if (shouldMakeEasyMode) eggs.each((_, egg) => makeEggEasyMode($(egg)));
		} else console.error("kw--egg: eggs resolved but no eggs found");
	}

	async function waitForEggSpawn(container) {
		return new Promise((resolve, reject) => {
			setTimeout(() => reject("kw--egg: egg spawn timeout"), 5000);
			let eggs = container.find(eggButtonSelector);
			if (eggs[0]) resolve(eggs);
			const observer = new MutationObserver(() => {
				eggs = container.find(eggButtonSelector);
				if (eggs[0]) {
					observer.disconnect();
					resolve(eggs);
				}
			});
			observer.observe(container[0], { childList: true, subtree: true });
		});
	}

	function addNavigator() {
		class NavigationController {
			#urls = [];
			constructor(urls) {
				this.#urls = urls;
			}

			get index() {
				const value = GM_getValue("kw--egg-url-index") || 0;
				if (isNaN(value)) return 0;
				return value % this.#urls.length;
			}

			set index(value) {
				if (value < 0) throw new Error("Invalid index setter");
				GM_setValue("kw--egg-url-index", value % this.#urls.length);
			}

			get nextUrl() {
				return this.#urls[this.index];
			}

			handleClick() {
				this.index++;
				window.location.href = "https://www.torn.com/" + this.nextUrl;
			}
		}

		const controller = new NavigationController(getAllLinks());
		addButton(controller.index, controller.handleClick.bind(controller));

		function addButton(index, onclick) {
			$("<button>", { id: "kw--egg-navigator", text: `Next Page: ${++index}` })
				.on("click", onclick)
				.appendTo(document.body);
		}
	}

	function addStyles() {
		GM_addStyle(`
		.kw--egg-easy-mode {
			position: fixed !important;
			top: 0 !important;
			bottom: 0 !important;
			right: 0 !important;
			left: 0 !important;
			height: 100vh !important;
			width: 100vw !important;
			z-index: 999999998;
		}
	
		.kw--egg-easy-mode img {
			height: 100% !important;
			width: 100% !important;
		}

		button#kw--egg-navigator {
			position: fixed;
			bottom: 0;
			left: 0;
			margin: 1.5rem;
			background-color: #fff;
			color: #000;
			padding: 0.5rem;
			border-radius: 0.5rem;
			z-index: 999999999;
			cursor: pointer;
		}

		body.dark-mode button#kw--egg-navigator {
			background-color: #000;
			color: #fff;
		}
	`);
	}
})();

function getAllLinks() {
	// This array was pulled from Heasley's Egg Navigator, available at https://greasyfork.org/en/scripts/463484-heasley-s-egg-navigator
	return [
		"index.php",
		"city.php",
		"jobs.php",
		"gym.php",
		"properties.php",
		"properties.php#/p=yourProperties",
		"properties.php#/p=spousesProperties",
		"education.php",
		"crimes.php",
		"loader.php?sid=missions",
		"newspaper.php",
		"jailview.php",
		"hospitalview.php",
		"casino.php",
		"halloffame.php",
		"factions.php",
		"competition.php",
		"friendlist.php",
		"blacklist.php",
		"messages.php",
		"page.php?sid=events",
		"awards.php",
		"points.php",
		"rules.php",
		"staff.php",
		"credits.php",
		"citystats.php",
		"committee.php",
		"bank.php",
		"donator.php",
		"page.php?sid=stocks",
		"fans.php",
		"museum.php",
		"loader.php?sid=racing",
		"church.php",
		"dump.php",
		"loan.php",
		"travelagency.php",
		"amarket.php",
		"bigalgunshop.php",
		"shops.php?step=bitsnbobs",
		"shops.php?step=cyberforce",
		"shops.php?step=docks",
		"shops.php?step=jewelry",
		"shops.php?step=nikeh",
		"shops.php?step=pawnshop",
		"shops.php?step=pharmacy",
		"pmarket.php",
		"shops.php?step=postoffice",
		"shops.php?step=super",
		"shops.php?step=candy",
		"shops.php?step=clothes",
		"shops.php?step=recyclingcenter",
		"shops.php?step=printstore",
		"imarket.php",
		"estateagents.php",
		"bazaar.php?userId=1",
		"calendar.php",
		"token_shop.php",
		"freebies.php",
		"comics.php",
		"joblist.php",
		"newspaper_class.php",
		"personals.php",
		"chronicles.php",
		"bounties.php",
		"trade.php",
		"usersonline.php",
		"profiles.php?XID=1",
		"page.php?sid=log",
		"page.php?sid=ammo",
		"loader.php?sid=itemsMods",
		"displaycase.php#display/",
		"crimes.php?step=criminalrecords",
		"archives.php#/",
		"archives.php#/TheBirthOfTorn",
		"archives.php#/Factions",
		"archives.php#/Employment",
		"archives.php#/TheMarkets",
		"archives.php#/RealEstate",
		"page.php?sid=factionWarfare",
		"page.php?sid=factionWarfare#/ranked",
		"page.php?sid=factionWarfare#/raids",
		"page.php?sid=factionWarfare#/chains",
		"page.php?sid=factionWarfare#/dirty-bombs",
		"bringafriend.php",
		"index.php?page=fortune",
		"page.php?sid=bunker",
		"church.php?step=proposals",
		"dump.php#/trash",
		"messageinc.php",
		"preferences.php",
		"messageinc2.php#!p=main",
		"userimages.php?XID=1",
		"personalstats.php?ID=1",
		"properties.php?step=rentalmarket",
		"properties.php?step=sellingmarket",
		"forums.php",
		"forums.php#/p=forums&f=1",
		"forums.php#/p=forums&f=67",
		"forums.php#/p=forums&f=2",
		"page.php?sid=slots",
		"page.php?sid=roulette",
		"page.php?sid=highlow",
		"page.php?sid=keno",
		"page.php?sid=craps",
		"page.php?sid=bookie",
		"page.php?sid=lottery",
		"page.php?sid=blackjack",
		"page.php?sid=holdem",
		"page.php?sid=russianRoulette",
		"page.php?sid=spinTheWheel",
		"page.php?sid=spinTheWheelLastSpins",
		"page.php?sid=slotsStats",
		"page.php?sid=slotsLastRolls",
		"page.php?sid=rouletteStatistics",
		"page.php?sid=rouletteLastSpins",
		"page.php?sid=highlowStats",
		"page.php?sid=highlowLastGames",
		"page.php?sid=kenoStatistics",
		"page.php?sid=kenoLastGames",
		"page.php?sid=crapsStats",
		"page.php?sid=crapsLastRolls",
		"page.php?sid=bookie#/stats/",
		"page.php?sid=lotteryTicketsBought",
		"page.php?sid=lotteryPreviousWinners",
		"page.php?sid=blackjackStatistics",
		"page.php?sid=blackjackLastGames",
		"page.php?sid=holdemStats",
		"loader.php?sid=viewRussianRouletteLastGames",
		"loader.php?sid=viewRussianRouletteStats",
		"messageinc2.php#!p=viewall",
		"bazaar.php#/add",
		"blacklist.php#p=add",
		"bazaar.php#/personalize",
		"factions.php?step=your#/tab=crimes",
		"staff.php#/p=helpapp",
		"factions.php?step=your#/tab=rank",
		"friendlist.php#p=add",
		"page.php?sid=events#onlySaved=true",
		"factions.php?step=your#/tab=controls",
		"factions.php?step=your#/tab=info",
		"messages.php#/p=ignorelist",
		"messages.php#/p=outbox",
		"factions.php?step=your#/tab=upgrades",
		"messages.php#/p=saved",
		"messages.php#/p=compose",
		"displaycase.php#add",
		"displaycase.php#manage",
		"factions.php?step=your#/tab=armoury",
		"bazaar.php#/manage",
		"itemuseparcel.php",
		"index.php?page=rehab",
		"index.php?page=people",
		"christmas_town.php",
		"christmas_town.php#/mymaps",
		"christmas_town.php#/parametereditor",
		"christmas_town.php#/npceditor",
		"page.php?sid=UserList",
		"index.php?page=hunting",
		"old_forums.php",
		"donatordone.php",
		"revive.php",
		"pc.php",
		"loader.php?sid=attackLog",
		"loader.php?sid=attack&user2ID=1",
		"loader.php?sid=crimes",
		"loader.php?sid=crimes#/searchforcash",
		"loader.php?sid=crimes#/bootlegging",
		"loader.php?sid=crimes#/graffiti",
		"loader.php?sid=crimes#/shoplifting",
		"loader.php?sid=crimes#/pickpocketing",
		"loader.php?sid=crimes#/cardskimming",
		"loader.php?sid=crimes#/burglary",
		"loader.php?sid=crimes#/hustling",
		"loader.php?sid=crimes#/disposal",
		"loader.php?sid=crimes#/cracking",
		"loader.php?sid=crimes#/forgery",
		"/war.php?step=rankreport&rankID=69",
		"/war.php?step=warreport&warID=420",
		"/war.php?step=raidreport&raidID=69",
		"/war.php?step=chainreport&chainID=69420",
		"page.php?sid=crimes2",
	];
}