Resizable Canvas

Change the size of the canvas

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Resizable Canvas
// @namespace   Violentmonkey Scripts
// @match       https://sketchful.io/
// @grant       none
// @version     3.1
// @author      Bell
// @description Change the size of the canvas
// jshint esversion: 6
// ==/UserScript==

const maxWidth = '110vw';
const headerOn = false;

const canvas = document.querySelector('#gameCanvas');
const gameParent = document.querySelector('.gameParent');
const header = document.querySelector('.gameHeader');
const playersList = document.querySelector('#gamePlayersList');
const innerCanvas = document.querySelector('#canvas');
const columnRight = document.querySelector('.columnRight');

const canvasObserver = new MutationObserver(() => {
	if (canvas.style.display !== 'none') {
		gameParent.style.maxWidth = maxWidth;
		gameParent.style.width = localStorage.gameParentWidth || '180vh';
		gameParent.style.resize = 'horizontal';
	}
	else {
		gameParent.style.maxWidth = '';
		gameParent.style.resize = '';
	}
});

function onResize() {
	fixHeader();
	if (gameParent.classList.contains('gameParentSettings')) return;
	localStorage.gameParentWidth = gameParent.style.width;
}

function fixHeader() {
	const height = gameParent.getBoundingClientRect().height;
	const canvasHeight =
		innerCanvas.getBoundingClientRect().height ||
		columnRight.getBoundingClientRect().height;
	playersList.style.maxHeight = `${canvasHeight}px`;
	if (window.innerHeight - height > 180 && headerOn) header.style.display = '';
	else header.style.display = 'none';
}

(function init() {
	header.remove();
	document.querySelector('.game').appendChild(header);
	document.querySelector('.gameContainer').style.marginTop = '0px';
	gameParent.setAttribute('style',
		`overflow: hidden; left: 50%; top: 50%; 
		 transform: translate(-50%, -50%); position: absolute;
		 padding-top: 12px`
	);

	new ResizeObserver(onResize).observe(gameParent);
	canvasObserver.observe(document.querySelector('.game'), { attributes: true });
	canvasObserver.observe(canvas, { attributes: true });
	$('[id^="money"]').remove();
})();

const interface = document.querySelector("#gameInterface");
interface.style.cursor = "move";
interface.addEventListener('mousedown', (e) => {
	if (e.target !== interface) return;
	startDrag();
});

function startDrag() {
	document.addEventListener('mouseup', finishDrag);
	document.addEventListener('mousemove', moveGameParent);
}

function moveGameParent(e) {
	gameParent.style.top = (gameParent.offsetTop + e.movementY) + "px";
}

function finishDrag() {
	document.removeEventListener('mouseup', finishDrag);
	document.removeEventListener('mousemove', moveGameParent);
}