Skip to content

Instantly share code, notes, and snippets.

@ingochris
Forked from anonymous/BackgroundChanger.user.js
Last active October 9, 2016 22:04
Show Gist options
  • Select an option

  • Save ingochris/820b71bd3ab81cfbc913 to your computer and use it in GitHub Desktop.

Select an option

Save ingochris/820b71bd3ab81cfbc913 to your computer and use it in GitHub Desktop.
/**
* Created by Umcookies on a potarto.
*/
API.on(API.chatLog("Use /background to set your new background and /player /vote /join /avatar to change the position of the respective UI elements", 1));
API.on(API.chatLog("You can use /move if any UI part's move, it wont prompt for any inputs. You can also use /keeppos which will check every second if a UI element has moved (recommended)"));
API.on(API.CHAT_COMMAND, awesomethings);
//variables
var backgroundurl = "https://cdn.plug.dj/_/static/images/community/background.ae45269504d5329fb78e47e9bd4be2da0698f284.jpg";
var playerWhereX = document.getElementById("playback").style.left.replace("px", "");
var playerWhereY = "54";
var voteWhereX = document.getElementById("vote").style.left.replace("px", "");
var voteWhereY = document.getElementById("vote").style.top.replace("px", "");
var joinWhereX = document.getElementById("dj-button").style.left.replace("px", "");
var joinWhereY = document.getElementById("dj-button").style.top.replace("px", "");
var avatarsWhereX = document.getElementById("avatars-container").style.left.replace("px", "");
var avatarsWhereY = document.getElementById("avatars-container").style.left.replace("px", "");
var loopKeeppos = '0';
//functions
function awesomethings(data) {
var commands = data;
if (commands == "/background") {
backgroundurl = prompt("Please input the URL of the picture you would like to use");
API.chatLog("It'll take a few seconds to load the picture, if you entered a valid picture please be patient");
document.getElementsByClassName("room-background")[0].setAttribute('style', 'background: url(' + backgroundurl + ')');
}
if (commands == "/player") {
playerWhereX = prompt("Please input how many pixels from the left of the screen you would like the player", "585");
playerWhereY = prompt("Please input how many pixels from the top of the screen you would like the player", "54");
document.getElementById("playback").setAttribute('style', 'left:' + playerWhereX + 'px; top: ' + playerWhereY + 'px;');
}
if (commands == "/vote") {
voteWhereX = prompt("How many pixels from the left hand side of the screen would you like the vote buttons to be ?", "945.5");
voteWhereY = prompt("How many pixels from the top of the screen would you like the vote buttons to be ?", "772");
document.getElementById("vote").setAttribute('style', 'left: ' + voteWhereX + 'px; top: ' + voteWhereY + 'px;')
}
if (commands == "/join") {
joinWhereX = prompt("How many pixels from the left hand side of the screen would you like the waitlist buttons to be ?", "398.5");
joinWhereY = prompt("How many pixels from the top of the screen would you like the waitlist button to be ?", "772");
document.getElementById("dj-button").setAttribute('style', 'left: ' + joinWhereX + 'px; top: ' + voteWhereY + 'px;')
}
if (commands == "/avatars") {
avatarsWhereX = prompt("How many pixels from the left hand side of the screen would you like the avatars to be ?", "385");
avatarsWhereY = prompt("How many pixels from the top of the screen would you like the avatars to be ?", "544");
document.getElementById("avatars-container").setAttribute('style', 'left: ' + avatarsWhereX + 'px; top: ' + avatarsWhereY + 'px;')
}
if (commands == "/move") {
document.getElementById("playback").setAttribute('style', 'left:' + playerWhereX + 'px; top: ' + playerWhereY + 'px;');
document.getElementById("avatars-container").setAttribute('style', 'left: ' + avatarsWhereX + 'px; top: ' + avatarsWhereY + 'px;');
document.getElementById("dj-button").setAttribute('style', 'left: ' + joinWhereX + 'px; top: ' + voteWhereY + 'px;');
document.getElementById("vote").setAttribute('style', 'left: ' + voteWhereX + 'px; top: ' + voteWhereY + 'px;');
}
if (commands == "/ivychan") {
document.getElementsByClassName("room-background")[0].setAttribute('style', 'background: url("http://i.imgur.com/mLtyWE1.jpg")');
playerWhereX = "30";
playerWhereY = "70";
voteWhereX = "130";
voteWhereY = "400";
joinWhereX = "140";
joinWhereY = "500";
avatarsWhereX = "-500";
avatarsWhereY = "-500";
loopKeeppos = '1';
loopCheck();
API.chatLog("You are now running the best of layouts :D")
}
if (commands == "/keeppos") {
if (loopKeeppos == '0') {
loopKeeppos = '1';
loopCheck();
API.chatLog("UI element positions are now being automatically fixed")
}
else if (loopKeeppos == '1') {
loopKeeppos = '0';
API.chatLog("UI element positions are no longer being automatically fixed")
}
}
if (commands == "/savepos") {
var saveName = prompt("Please enter the name you would like to save everything under", "default");
var umcookiesBgArray = [backgroundurl, playerWhereX, playerWhereY, voteWhereX, voteWhereY, joinWhereX, joinWhereY, avatarsWhereX, avatarsWhereY, loopKeeppos]
localStorage.setItem(saveName, JSON.stringify(umcookiesBgArray))
}
}
function loopCheck() {
setTimeout(function () {
if (loopKeeppos == '1') {
document.getElementById("playback").setAttribute('style', 'left:' + playerWhereX + 'px; top: ' + playerWhereY + 'px;');
document.getElementById("avatars-container").setAttribute('style', 'left: ' + avatarsWhereX + 'px; top: ' + avatarsWhereY + 'px;');
document.getElementById("dj-button").setAttribute('style', 'left: ' + joinWhereX + 'px; top: ' + joinWhereY + 'px;');
document.getElementById("vote").setAttribute('style', 'left: ' + voteWhereX + 'px; top: ' + voteWhereY + 'px;');
loopCheck();
}
}, 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment