Maximise the useable game area and reorder elements
当前为
// ==UserScript==
// @name AWBW Maximise
// @version 1.26
// @description Maximise the useable game area and reorder elements
// @author Truniht
// @match https://awbw.amarriner.com/game.php?games_id=*
// @icon https://awbw.amarriner.com/terrain/ani/gemegatank.gif
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// @namespace https://awbw.amarriner.com/
// @run-at document-start
// @license MIT
// ==/UserScript==
(function() {
'use strict';
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
var settings = GM_getValue('AWBWMaximise') || {};
var styleAdded = false;
function addStyle() {
if (styleAdded) return;
styleAdded = true;
addGlobalStyle(`
html {
image-rendering: pixelated;
scrollbar-width: thin;
}
body {
overflow-x: hidden;
transform: translateZ(0);
}
.AWBWMaximise #left-side-menu-container {display: none;}
.AWBWMaximise #outer {margin: 0; width: 100%; background: none;}
.AWBWMaximise #main {min-height: 100vh; box-shadow: none;}
.AWBWMaximise #game-header-table {
position: absolute;
top: -500px;
}
.AWBWMaximise #live-queue-popup {
position: absolute;
}
.AWBWMaximise #zoom-in,
.AWBWMaximise #zoom-out,
.AWBWMaximise #game-menu-controls > section:first-child > .game-tools-btn:nth-child(4) {
display: none;
}
.AWBWMaximise .menu-follow {
display: none !important;
}
.AWBWMaximise .game-header-day {
position: fixed !important;
right: 20px;
border: 1px solid grey;
background: white;
padding: 5px; width: 72px;
transform: scale(1.5);
transform-origin: top left;
}
.AWBWMaximise #fixed-header-wrapper {
display: none;
}
.AWBWMaximise#main>.small_text_11 {
display: none;
}
.AWBWMaximise #game-menu-controls:not(:hover) section > *:not(#coords):not(#game-map-menu),
.AWBWMaximise #game-menu-controls:not(:hover) #game-map-menu>.game-tools-btn
{
opacity: 0.2;
}
.game-tools-btn-text.small_text {
pointer-events: none;
}
.AWBWMaximise #game-map-menu-dropdown-info {
left: auto !important;
right: 100px !important;
transform: scale(1.5);
transform-origin: right;
}
.AWBWMaximise #gamemap-container {
margin-left: -350px;
margin-bottom: 0;
}
.AWBWMaximise #main > span {
display: none;
}
.AWBWMaximise #map-controls-container {
position: fixed;
right: 0;
z-index: 100;
}
.AWBWMaximise #game-menu-controls {
justify-content: end;
z-index: 10;
width: 240px;
}
.AWBWMaximise .replay-controls {
background: none;
z-index: 200;
padding: 0;
border: 1px solid rgba(128, 128, 128, 0.2);
top: auto !important;
}
.AWBWMaximise #game-menu-controls:hover .replay-controls {
border: 1px solid grey;
}
.AWBWMaximise:not(.AWBWMaximise8players) .game-player-info {
transform: scale(1.5);
transform-origin: top left;
}
.AWBWMaximise .game-player-info {
z-index: 120;
pointer-events: none;
}
.AWBWMaximise .player-username {
max-width: 110px;
display: inline-block;
}
.AWBWMaximise .game-player-info * {
pointer-events: all;
}
.AWBWMaximise #coords {
position: fixed;
margin-left: -1px;
margin-top: 2px;
height: 19px !important;
right: 0;
top: -149px;
background: none;
border: 0;
color: white;
transform: scale(1.2);
}
.AWBWMaximise .tile-info {
left: 100% !important;
margin-left: 4px;
transform: scale(1.5);
transform-origin: top left;
bottom: auto !important;
padding-top: 10px;
}
.AWBWMaximise .end-game-screen {
transform: scale(1.5);
}
.AWBWMaximise .replay-download {
display: none !important;
}
.AWBWMaximise .game-actions {
position: absolute;
transform: scale(1.5);
transform-origin: top right;
margin: 0;
top: -145px;
right: 0;
}
.AWBWMaximise .game-actions * {
opacity: 1 !important;
}
.AWBWMaximise #calculator {
transform: scale(1.5);
transform-origin: top left;
}
.AWBWMaximise .italic {
font-style: normal !important;
}
.AWBWMaximise .replay-day-selector {
position: absolute; right: 188px;
top: -146px;
opacity: 1 !important;
transform: scale(1.5);
background: white;
border: 1px solid gray;
width: 82px;
padding-left: 6px;
transform-origin: top right;
height: 31px;
}
.AWBWMaximise .replay-day-selector:before {
content: "Day";
padding-right: 8px;
}
.AWBWMaximise .replay-day-selector select {
font-size: 16px;
border: 0;
background: transparent;
color: black;
font-weight: bold;
outline: none;
}
.AWBWMaximise .replay-controls>* {
opacity: 1;
}
.AWBWMaximise .player-overview-info {
min-width: 80px;
}
.AWBWMaximise .game-tools-bg .norm2 .small_text {
display: none;
}
.AWBWMaximise #game-map-menu .game-tools-btn {
width: 60px !important;
}
.AWBWMaximise .game-player-info textarea {
display: none;
}
html:not(.AWBWMaximise) .AWBWMaxmiseButton {
border-left: 0;
}
`);
}
function maximise() {
if (!settings.active) return;
if (!styleAdded) addStyle();
document.documentElement.classList.add('AWBWMaximise');
//We always start from scale one to achieve consistent results
unsafeWindow.scale = 1;
unsafeWindow.applyScale(0);
//Calculate the correct resizing setting
var container = document.getElementById('gamemap-container');
var containerWidth = container.offsetWidth / unsafeWindow.scale;
var containerHeight = container.offsetHeight / unsafeWindow.scale;
var scaleFactor = Math.min( (window.innerWidth - 350) / containerWidth, (window.innerHeight - 4) / containerHeight); //Keep 350px for the player element on the right side
unsafeWindow.scale = Math.floor(scaleFactor * 10) / 10; //The scaling rounds to tenths so we need to do so as well
unsafeWindow.applyScale(0);
moveElements(); //Reposition elements
}
function reset() {
document.documentElement.classList.remove('AWBWMaximise');
document.getElementById('map-controls-container').style.top = '';
document.getElementById('map-controls-container').style.right = '';
document.querySelector('.game-header-day').style.left = '';
document.querySelector('.game-header-day').style.top = '';
document.querySelector('.game-header-day').style.display = '';
document.querySelector('.tile-info').style.top = '';
var coord = document.querySelector('#coords');
coord.style.display = '';
coord.style.left = '';
coord.style.top = '';
unsafeWindow.scale = settings.oldZoom;
unsafeWindow.applyScale(0);
lastPosition = 0;
}
var lastPosition = 0;
function moveElements() {
if (!settings.active) return;
var scrollY = window.scrollY;
//Get the positions of the map and the player container
var players = document.body.querySelectorAll('.player-overview-container');
var lastPlayer = players[players.length - 1].getBoundingClientRect();
var mapRect = document.querySelector('#gamemap-container').getBoundingClientRect();
var mapControl = document.querySelector('#map-controls-container');
var newRight = window.innerWidth - lastPlayer.right;
if (Math.abs(newRight - lastPosition) > 15) {
lastPosition = newRight;
//Move the menu buttons
mapControl.style.right = newRight + 'px';
}
mapControl.style.top = (lastPlayer.bottom + 160 + scrollY) + 'px';
//Move the day counter
var header = document.querySelector('.game-header-day');
header.style.left = lastPlayer.left + 'px';
header.style.top = Math.min(window.innerHeight - 100, (lastPlayer.bottom + 10 + scrollY)) + 'px';
//Move the tile info / hover info
var tileInfo = document.querySelector('.tile-info');
tileInfo.style.top = Math.min(window.innerHeight - 100 - mapRect.top, lastPlayer.bottom + 75 - mapRect.top) + 'px';
var tileB = tileInfo.getBoundingClientRect();
//Place the coordinate info on top of the tile info
var coord = document.querySelector('#coords');
if (!tileB.width) {
coord.style.display = 'none';
}
else {
coord.style.display = '';
coord.style.left = tileB.left + 'px';
coord.style.top = (tileB.top + scrollY) + 'px';
}
if (document.querySelector('.replay-controls').style.display == 'flex') {
header.style.display = 'none';
}
else {
header.style.display = '';
}
var replayFixed = document.querySelector('.replay-controls-fixed');
if (replayFixed) {
document.querySelector('#game-menu-controls').appendChild(replayFixed);
replayFixed.classList.remove('replay-controls-fixed');
}
}
function buttonClick() {
if (!settings.active) settings.oldZoom = unsafeWindow.scale;
settings.active = !settings.active;
if (settings.active) maximise();
else reset();
GM_setValue('AWBWMaximise', settings);
}
unsafeWindow.addEventListener('scroll', moveElements);
unsafeWindow.addEventListener('resize', maximise);
document.addEventListener('DOMContentLoaded', function() {
//Create the maximise button
var button = document.createElement('div');
button.className = 'game-tools-btn AWBWMaxmiseButton';
button.innerText = '🗖';
var buttonDescription = document.createElement('span');
buttonDescription.innerText = 'Maximise';
buttonDescription.className = 'game-tools-btn-text small_text';
button.appendChild(buttonDescription);
button.onclick = buttonClick;
var ele = document.getElementById('game-map-menu');
ele.parentNode.insertBefore(button, document.querySelector('.game-tools-btn:nth-child(4)').nextElementSibling);
if (Object.keys(playersInfo).length >= 5) document.documentElement.classList.add('AWBWMaximise8players');
if (settings.active) {
document.documentElement.classList.add('AWBWMaximise');
maximise();
}
setInterval(moveElements, 200); //Not the most efficient way, but very reliable
}, false);
if (settings.active) {
addStyle();
document.documentElement.classList.add('AWBWMaximise');
}
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址