Skip to content

Instantly share code, notes, and snippets.

@PkmnQ
Created February 11, 2023 04:15
Show Gist options
  • Save PkmnQ/bc0a10229c45f43016ea0e4756ddf523 to your computer and use it in GitHub Desktop.
Save PkmnQ/bc0a10229c45f43016ea0e4756ddf523 to your computer and use it in GitHub Desktop.
Marble Run Addons
// ==UserScript==
// @name Marble Run Addons
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Adds things to marblerun.at.
// @author PkmnQ
// @match https://www.marblerun.at/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=marblerun.at
// @grant none
// ==/UserScript==
(function() {
'use strict';
var onloadRun = false;
let normalOnload = window.onload;
window.onload = () => {
if (!onloadRun) {
onloadRun = true;
normalOnload();
let contentLoader = window.contentLoader;
document.head.innerHTML += "<style>html {height: 1746px;} a.customEditorButton {width: 65px;} a.customEditorButton:active {background-position: 0 -30px !important;} div#lengthDisplayEditor, div#lengthDisplayShowroom {background: url(../images/editor-meter-background.png?1610987863) no-repeat; width: 78px; height: 18px; float: left; color: #EBE63F; padding: 12px 0 0 5px; font-family: 'Courier New', Courier, monospace; font-size: 13px; letter-spacing: 13px; margin-left: 2px;}</style>"
function placeBrick(brick, row, col, rot) {
const brickSize = window.Brick.SIZE;
const field = contentLoader.editor.field;
brick.setRotation(rot * Math.PI/2);
brick.cell = {row: row, col: col};
brick.parent = field;
brick.x = field.x + col * brickSize;
brick.y = field.y + row * brickSize;
brick.width = brick.height = brickSize;
field.bricks.push(brick);
field.renderNew = true;
brick.createBody(field.world);
}
function removeBrick(row, col) {
const field = contentLoader.editor.field;
let brickToRemove = field.bricks.findLastIndex(a => a.cell.row === row && a.cell.col === col);
if (brickToRemove !== -1) {
field.bricks.pop(brickToRemove);
field.renderNew = true;
}
}
window.placeBrick = placeBrick;
window.removeBrick = removeBrick;
let normalGetTrack = window.Field.prototype.getTrack;
window.Field.prototype.getTrack = function () {
let track = normalGetTrack.call(this);
for (let i = 0; i < this.bricks.length; i++) {
let brick = this.bricks[i];
track.bricks[brick.cell.row * this.cols + brick.cell.col].rotation = (brick.rotation / (Math.PI/2)) % 4;
}
return track;
}
// editor
let editorControls = document.querySelector("#editorControlsBottom");
editorControls.querySelector(".editor-non-float-container").insertAdjacentHTML("afterend",
"<div class='editor-non-float-container'>" +
"<strong style='color: black; font-size: 8px; letter-spacing: 1px;'>ADD/REMOVE BRICKS</strong>" +
"<form><input style='float: left;' id='brickRow' placeholder='ROW'><input style='float: left;' id='brickCol' placeholder='COLUMN'><input style='float: left;' id='brickRot' placeholder='ROTATION'></form>" +
"<br><br><br><br>" +
"<a class='editorButton customEditorButton' id='addBrickButton' style='background: url(https://u.cubeupload.com/PkmnQ/addbutton.png) no-repeat;'>ADD</a>" +
"<a class='editorButton customEditorButton' id='removeBrickButton' style='background: url(https://u.cubeupload.com/PkmnQ/removebutton.png) no-repeat;'>REMOVE</a>" +
"<br>" +
"</div>"
);
editorControls.querySelector("#addBrickButton").addEventListener("click", function () {
let brickType = contentLoader.editor.selectElement?.brick?.constructor;
if (brickType) {
let brick = new brickType();
placeBrick(brick, Number(editorControls.querySelector("#brickRow").value), Number(editorControls.querySelector("#brickCol").value), Number(editorControls.querySelector("#brickRot").value))
}
});
editorControls.querySelector("#removeBrickButton").addEventListener("click", function () {
removeBrick(Number(editorControls.querySelector("#brickRow").value), Number(editorControls.querySelector("#brickCol").value));
});
let normalBuildMode = contentLoader.createBuildMode;
contentLoader.createBuildMode = function (content, visibleList) {
normalBuildMode.call(contentLoader, content, visibleList);
};
// showroom
let showroomControls = document.querySelector("#showroomControlsBottom");
showroomControls.querySelector("#autoButton").insertAdjacentHTML("afterend",
"<br><br>" +
"<div id='lengthDisplayShowroom'>0000</div>"
);
let normalBallUpdate = window.Ball.prototype.update;
window.Ball.prototype.update = function () {
normalBallUpdate.call(this);
if (this.parent === contentLoader.showroom.field) window.$('lengthDisplayShowroom').update(this.getFormatString(this.parent.trackLength * 10));
}
let normalShowMode = contentLoader.createShowMode;
contentLoader.createShowMode = function (content) {
normalShowMode.call(contentLoader, content);
};
}
};
window.onload();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment