Move Painter with Middle Mouse Button

Allows you to drag the Painter with the Middle Mouse Button

Від 27.06.2021. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Move Painter with Middle Mouse Button
// @namespace    http://tampermonkey.com/
// @version      1.0
// @description  Allows you to drag the Painter with the Middle Mouse Button
// @author       MTP3
// @match        http://manyland.com/*
// @icon         http://manyland.com/favicon.ico
// @grant        none
// ==/UserScript==

let replacePainter = () => {
	if (ig.game.painter.movable)
	{
		ig.game.sounds.success.play();
		return;
	}

	let teleportElement = (element, x, y) => {
		if (!element)
			return;

		jQuery(element).css("left", x + "px");
		jQuery(element).css("top", y + "px");
	};

	let offsetElement = (element, x, y) => {
		if (!element)
			return;

		let pos = jQuery(element).position();

		teleportElement(element, x + pos.left, y + pos.top);
	};

	ig.game.painter.updateCursorPos = (e) => {
		if (!ig.game.painter.isRunning)
			ig.game.painter.moving = false;

		if (!ig.game.painter.moving)
			return;

		let painter = ig.game.painter;

		let pos = jQuery(ig.game.painter.canvas).position();
		let x = e.movementX;
		let y = e.movementY;

		offsetElement(ig.game.painter.canvas, x, y);
		offsetElement($(".painterInputBox")[0], x, y);

		ig.game.painter.oldMouseX = e.offsetX;
		ig.game.painter.oldMouseY = e.offsetY;
	};

	document.addEventListener('mousemove', ig.game.painter.updateCursorPos);

	document.addEventListener('mousedown', (e) => {
		if (e.button == 1)
			ig.game.painter.moving = true;
	});

	document.addEventListener('mouseup', (e) => {
		if (e.button == 1)
			ig.game.painter.moving = false;
	});

	ig.game.painter.movable = true;

	ig.game.sounds.success.play();
};

(() => {
	let loading = setInterval(() => {
		if      (ig === undefined) return;
        else if (ig.input === undefined) return;
        else if (ig.game === undefined) return;
        else if (ig.game.painter === undefined) return;

        clearInterval(loading);
		replacePainter();
    }, 250);
})();