From a79cf31f35fd0c163814e13344acb62f984c2ba6 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 7 Jan 2016 09:39:01 +0200 Subject: [PATCH] Custom game plugin allows user to set custom game as status --- Plugins/CustomGame.plugin.js | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Plugins/CustomGame.plugin.js diff --git a/Plugins/CustomGame.plugin.js b/Plugins/CustomGame.plugin.js new file mode 100644 index 0000000..ea71237 --- /dev/null +++ b/Plugins/CustomGame.plugin.js @@ -0,0 +1,81 @@ +//META{"name":"customGamePlugin"}*// + +function customGamePlugin() {} + +customGamePlugin.prototype.load = function() { +}; + +customGamePlugin.prototype.unload = function() { +}; + +customGamePlugin.prototype.start = function() { + var self = this; + this.enabled = true; + this.interval = setInterval(function() { + self.setPlaying(); + }, 60000); + this.setPlaying(); +}; + +customGamePlugin.prototype.stop = function() { + var gp = this.game; + this.game = ""; + this.setPlaying(); + this.game = gp; + clearInterval(this.interval); + this.enabled = false; +}; + +customGamePlugin.prototype.getName = function() { + return "Custom Game"; +}; + +customGamePlugin.prototype.getDescription = function() { + return "Set custom game as your playing status"; +}; + +customGamePlugin.prototype.getVersion = function() { + return "1.0"; +}; + +customGamePlugin.prototype.getAuthor = function() { + return "Jiiks"; +}; + +customGamePlugin.prototype.getSettingsPanel = function() { + if(this.game == null) this.game = ""; + return ' ' + + '' + + ''; +}; + +customGamePlugin.prototype.setGame = function(game) { + if(game == null) { + game = document.getElementById("cgPluginGame").value; + } + this.game = game; + this.setPlaying(); +}; + +customGamePlugin.prototype.setPlaying = function() { + if(!this.enabled) return; + if(this.uid == null) this.uid = $(".account .avatar-small").css("background-image").match(/\d+/); + + if(this.game == null) this.game = ""; + + var minner = $('.channel-members .member[data-reactid*="'+this.uid+'"]').find(".member-inner") + var mgame = minner.find(".member-game"); + if(this.game != "") { + if(mgame.length) { + mgame.find("strong").text(this.game); + } else { + minner.append('
Playing: '+this.game+'
'); + } + } else { + if(mgame.length) { + mgame.remove(); + } + } + + BdApi.setPlaying(this.game); +}; \ No newline at end of file