sandboxels/mods/background_changer.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

// This mod has been deprecated in favor of the base game's Background setting.
/*
2025-12-07 19:46:57 -05:00
function setCanvasBG(url, color) {
2025-11-22 19:05:43 -05:00
delete settings.bg;
let canvas = document.getElementById("game");
canvas.style.backgroundColor = "";
canvas.style.backgroundImage = `url(${url})`;
canvas.style.backgroundRepeat = "no-repeat";
canvas.style.backgroundSize = "cover";
canvas.style.backgroundPosition = "bottom";
settings.bgimg = url;
2025-12-07 19:46:57 -05:00
if (color) settings.bgimgcolor = color;
else delete settings.bgimgcolor;
if (color) document.head.insertAdjacentHTML("beforeend", `<style id="canvasBGStyles">* {background-color:${color}} body, html {background-color:${color}!important}</style>`);
else document.getElementById("canvasBGStyles")?.remove();
2025-11-22 19:05:43 -05:00
saveSettings()
}
2025-12-07 19:46:57 -05:00
function clearCanvasBG() {
delete settings.bgimg;
let canvas = document.getElementById("game");
canvas.style.backgroundImage = "";
canvas.style.backgroundRepeat = "";
canvas.style.backgroundSize = "";
canvas.style.backgroundPosition = "";
document.getElementById("canvasBGStyles")?.remove();
}
2025-11-22 19:05:43 -05:00
2025-12-07 19:46:57 -05:00
function setCanvasBGPrompt() {
2025-11-22 19:05:43 -05:00
promptInput("Enter an image URL. Leave blank to clear background.", (url) => {
if (!url) {
2025-12-07 19:46:57 -05:00
clearCanvasBG();
2025-11-22 19:05:43 -05:00
}
setCanvasBG(url);
}, "Background")
}
2025-12-07 19:46:57 -05:00
keybinds.KeyB = () => {
setCanvasBGPrompt()
}
2025-11-22 19:05:43 -05:00
document.addEventListener("load", () => {
if (settings.bgimg) {
2025-12-07 19:46:57 -05:00
setCanvasBG(settings.bgimg, settings.bgimgcolor)
2025-11-22 19:05:43 -05:00
}
})
runAfterReset(() => {
if (settings.bgimg) {
2025-12-07 19:46:57 -05:00
setCanvasBG(settings.bgimg, settings.bgimgcolor)
2025-11-22 19:05:43 -05:00
}
})
*/