IdlePixel SlapChop - Gathering Code

Split off of IdlePixel Slapchop for all Gathering Code.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greasyfork.org/scripts/483546/1304242/IdlePixel%20SlapChop%20-%20Gathering%20Code.js

// ==UserScript==
// @name         IdlePixel SlapChop - Gathering Code
// @namespace    godofnades.idlepixel
// @version      0.1.1
// @description  Split off of IdlePixel Slapchop for all Gathering Code.
// @author       GodofNades
// @license      MIT
// @match        *://idle-pixel.com/login/play/
// @grant        none
// ==/UserScript==

(function () {
	"use strict";

    let singleOverride;

	const IMAGE_URL_BASE = document
    .querySelector("itembox[data-item=copper] img")
    .src.replace(/\/[^/]+.png$/, "");

	const LOOT_BAGS = $(`itembox[data-item^="gathering_loot_bag_"]`)
		.toArray()
		.map((el) => el.getAttribute("data-item"));

	function quickGather(bag, alt) {
		let n = IdlePixelPlus.getVarOrDefault(bag, 0, "int");
		singleOverride =
			IdlePixelPlus.plugins.slapchop.getConfig("autoSingleEnabled");
		if (alt || singleOverride) {
			n--;
		}
		if (n > 0) {
			IdlePixelPlus.sendMessage(
				`OPEN_GATHERING_LOOT=${bag.replace("gathering_loot_bag_", "")}~${n}`
			);
		}
	}

	function initQuickGather() {
		window.LOOT_BAGS.forEach((item) => {
			$(`itembox[data-item="${item}"]`).on("contextmenu", (event) => {
				if (
					IdlePixelPlus.plugins.slapchop.getConfig(
						"quickGatherRightClickEnabled"
					)
				) {
					const primary = window.isPrimaryActionSlapchop(event);
					const alt = window.isAltActionSlapchop(event);
					if (primary || alt) {
						window.quickGather(item, !primary);
						event.stopPropagation();
						event.preventDefault();
						return false;
					}
				}
				return true;
			});
		});
	}

	window.initQuickGather = initQuickGather;
	window.quickGather = quickGather;
    window.LOOT_BAGS = LOOT_BAGS;
})();