Skip to content

Instantly share code, notes, and snippets.

@Xyvyrianeth
Last active February 18, 2017 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xyvyrianeth/6849abceee315ee7680fe66c0a7e0fb4 to your computer and use it in GitHub Desktop.
Save Xyvyrianeth/6849abceee315ee7680fe66c0a7e0fb4 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Vidkunssonn's Name Database
// @author Vikdunssonn
// @version 2.0
// @grant 2017
// @description Records the name of every person that goes into the same room you're in and organizes them by _ids.x
// @namespace http://www.multiplayerpiano.com/
// @match http://www.multiplayerpiano.com/
// @include http://www.multiplayerpiano.com/*
// @include http://www.ourworldofpixels.com/piano/*
// ==/UserScript==
//If you don't already have dataBase created, this creates it for you.
if (!localStorage.dataBase) {
dataBase = {"totalnames":0};
} else {
dataBase = JSON.parse(localStorage.dataBase);
}
//Function for adding names (Thanks, Delan, luv u!).
var addName = pp => {
if (pp.name !== "Anonymous") {
if (!dataBase[pp._id]) {
dataBase[pp._id] = [pp.name];
dataBase.totalnames += 1;
} else {
if (!dataBase[pp._id].includes(pp.name)) {
dataBase[pp._id].push(pp.name);
}
}
}
};
//When someone joins the room, this records their name.
MPP.client.on("participant added", addName);
//When someone leaves the room, this records their name.
MPP.client.on("participant removed", addName);
//When someone changes their name, this records it.
MPP.client.on("participant update", addName);
//Save DataBase
MPP.client.on('a', m => {
if (m.a == '!dbsave') {
if (m.p._id == MPP.client.getOwnParticipant()._id) {
localStorage.dataBase = JSON.stringify(dataBase);
MPP.chat.send("Database saved to localStorage. Names for " + dataBase.totalnames + " unique _ids are currently stored.");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment