From b9c778746580381db32c1afde38947243e5152b7 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Fri, 11 Mar 2016 17:36:04 +0200 Subject: [PATCH] Disabled customgame and added custom role colour plugin --- Plugins/CustomGame.plugin.js | 2 + Plugins/customRoleColour.plugin.js | 85 ++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Plugins/customRoleColour.plugin.js diff --git a/Plugins/CustomGame.plugin.js b/Plugins/CustomGame.plugin.js index 7981ba6..04348da 100644 --- a/Plugins/CustomGame.plugin.js +++ b/Plugins/CustomGame.plugin.js @@ -9,6 +9,7 @@ customGamePlugin.prototype.unload = function() { }; customGamePlugin.prototype.start = function() { + return; var self = this; this.enabled = true; this.interval = setInterval(function() { @@ -18,6 +19,7 @@ customGamePlugin.prototype.start = function() { }; customGamePlugin.prototype.stop = function() { + return; var gp = this.game; this.game = ""; this.setPlaying(); diff --git a/Plugins/customRoleColour.plugin.js b/Plugins/customRoleColour.plugin.js new file mode 100644 index 0000000..8510c1d --- /dev/null +++ b/Plugins/customRoleColour.plugin.js @@ -0,0 +1,85 @@ +//META{"name":"crr"}*// + +function crr() {} + +crr.prototype.start = function () { + this.crrMt = new MutationObserver(function(mutations) { + if($(".roles").length > 0) { + if($("#ccpicker").length < 1) { + + var selectedRole = $(".roles").find("li.selected"); + var roleId = selectedRole.data("reactid").split("$").slice(-1)[0]; + var serverId = $(".guilds .active").data("reactid").split("$").slice(-1)[0]; + var rgb = selectedRole.css("color").match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/); + + function hex(x) { + return ("0" + parseInt(x).toString(16)).slice(-2); + } + var curColour = "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); + + var picker = $("", { + type: "color", + class: "swatch default", + id: "ccpicker" + }); + + $(".color-picker .swatches").append(picker); + picker.prop("value", curColour); + + picker.on("change", function() { + + var token = localStorage["token"].replace(/"/g, ""); + var newColour = parseInt($(this).prop("value").slice(1), 16); + $.ajax({ + type: 'GET', + url: 'https://discordapp.com/api/guilds/'+serverId+'/roles?token='+token, + success: function(data) { + for(var i = 0 ; i < data.length ; i++) { + if(data[i]["id"] == roleId) { + var request = new XMLHttpRequest(); + request.open('PATCH', 'https://discordapp.com/api/guilds/'+serverId+'/roles/'+roleId+'?token='+localStorage["token"].replace(/"/g, ""), false); + request.setRequestHeader("Content-type","application/json"); + request.send('{"color": '+newColour+', "hoist": '+data[i]["hoist"]+', "name": "'+data[i]["name"]+'", "permissions": '+data[i]["permissions"]+'}'); + break; + } + } + } + }); + }); + + } + } + }); + this.crrMt.observe(document, {childList:true, subtree:true}) +}; +crr.prototype.stop = function () { + this.crrMt.disconnect(); +}; + +crr.prototype.load = function () { + //Called when plugin is loaded +}; + +crr.prototype.unload = function () { + //Called when plugin is unloaded +}; + +crr.prototype.getName = function () { + return "Custom Role Colours"; +}; + +crr.prototype.getDescription = function () { + return "Set custom role colours"; +}; + +crr.prototype.getVersion = function () { + return "1.0"; +}; + +crr.prototype.getAuthor = function () { + return "Jiiks, Pohky"; +}; + +crr.prototype.getSettingsPanel = function () { + return ''; +}; \ No newline at end of file