Skip to content

Instantly share code, notes, and snippets.

@WiBla
Last active November 28, 2016 17:19
Show Gist options
  • Save WiBla/877d6961cbdd6ef28a36fd5ae8b7e791 to your computer and use it in GitHub Desktop.
Save WiBla/877d6961cbdd6ef28a36fd5ae8b7e791 to your computer and use it in GitHub Desktop.
Auto change your avatar (every 3.5s) & badge (on message sent) from your plug.dj's inventory.

Auto change your avatar (every 3.5s) & badge (on message sent) from your plug.dj's inventory.

##How to use

Simply put this code in a new bookmark's url (name it how you want) :
It will even auto update !

javascript:(function(){$.getScript('https://rawgit.com/WiBla/877d6961cbdd6ef28a36fd5ae8b7e791/raw/magic.js');})();

Click the bookmark when browsing Plug.dj and voilà !
cough With my extension, you can load any script automaticly. Just saying.. cough

##How to stop it

The most common way to do it is by refreshing your browser (f5 or ctrl + r)
You also have the /stopAvatar and /stopBadge commands..

##Boring stuff

       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
               Version 2, December 2004

Copyright (C) 2004 Sam Hocevar sam@hocevar.net

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  1. You just DO WHAT THE FUCK YOU WANT TO.
$.ajax({
type: 'GET',
url: '/_/store/inventory',
success: function(data) {
let inventory = data.data;
let badges = [];
let avatars = [];
inventory.forEach(function(item, i, a) {
if (item.type === "badges") {
badges.push(item.id);
} else if (item.type === "avatars") {
avatars.push(item.id);
}
});
window.changeBadge = function(msg) {
if (msg.uid !== API.getUser().id) return;
let badge = badges[Math.floor(Math.random() * badges.length)];
$.ajax({
type: 'PUT',
url: '/_/users/badge',
data: JSON.stringify({
id: badge
}),
success: function(data) {
console.log('Badge changed !');
},
error: function(err) {
console.error(err);
},
dataType: 'json',
contentType: 'application/json'
});
}
API.on(API.CHAT, window.changeBadge);
window.avatarInterval = setInterval(function() {
let avatar = avatars[Math.floor(Math.random() * avatars.length)];
$.ajax({
type: 'PUT',
url: '/_/users/avatar',
data: JSON.stringify({
id: avatar
}),
error: function(err) {
console.error(err);
},
dataType: 'json',
contentType: 'application/json'
});
}, 3500);
API.on(API.CHAT_COMMAND, function(cmd) {
if (cmd === "/stopAvatar") {
clearInterval(window.avatarInterval);
} else if (cmd === "/stopBadge") {
API.off(API.CHAT, window.changeBadge);
}
});
},
error: function(err) {
console.error(err);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment