Skip to content

Instantly share code, notes, and snippets.

@rauenzi
Last active July 24, 2017 20:18
Show Gist options
  • Save rauenzi/dd262d03b250f5bcd0469f65145bae1b to your computer and use it in GitHub Desktop.
Save rauenzi/dd262d03b250f5bcd0469f65145bae1b to your computer and use it in GitHub Desktop.
Fix for ColoredVoice & ColoredTyping
//META{"name":"ColoredTyping"}*//
var ColoredTyping = function() {};
ColoredTyping.prototype.data = {};
ColoredTyping.prototype.dataVersion = "1";
ColoredTyping.prototype.defaultData = function() {
return {
version: "1"
};
}
ColoredTyping.prototype.loadData = function() {
this.data = (bdStorage.get('ColoredTyping')) ? JSON.parse(bdStorage.get('ColoredTyping')) : {
version: '0'
};
if (this.data.version != this.dataVersion) {
// wew lad we're using a new way to save our data
this.data = this.defaultData();
this.saveData();
};
};
ColoredTyping.prototype.saveData = function() {
bdStorage.set('ColoredTyping',JSON.stringify(this.data));
};
ColoredTyping.prototype.colorize = function() {
var self = this;
$(".typing strong").each(function(index) {
var username = $(this).text();
if (self.data[username]) $(this).css("color", self.data[username]);
});
};
ColoredTyping.prototype.decolorize = function() {
$(".typing strong").each(function(index) {
$(this).css("color", "");
});
};
// unused
ColoredTyping.prototype.load = function() {};
ColoredTyping.prototype.unload = function() {};
// unused
ColoredTyping.prototype.onMessage = function() {
var username = $(".message .user-name").last().text();
var color = $(".message .user-name").last().css("color");
this.data[username] = color;
this.saveData();
};
ColoredTyping.prototype.start = function() {
this.loadData();
this.colorize();
};
ColoredTyping.prototype.stop = function() {
this.decolorize();
this.saveData();
};
ColoredTyping.prototype.onSwitch = function() {
var self = this;
$('.member-username-inner').each(function(index) {
var username = $(this).text();
var color = this.style.color;
if (color) self.data[username] = color;
});
this.saveData();
this.decolorize();
this.colorize();
};
ColoredTyping.prototype.observer = function(e) {
if (!e.addedNodes.length) return;
var elem = $(e.addedNodes[0])
if (elem.find("strong").length || elem.find(".spinner").length || elem.hasClass(".typing") || elem.prop("tagName") == "STRONG") {
this.colorize();
}
if (elem.find(".member-username-inner").length) {
var self = this;
$('.member-username-inner').each(function(index) {
var username = $(this).text();
var color = this.style.color;
if (color) self.data[username] = color;
});
this.decolorize();
this.colorize();
}
};
ColoredTyping.prototype.getSettingsPanel = function() {
return "";
};
ColoredTyping.prototype.getName = function() {
return "Colored Typing";
};
ColoredTyping.prototype.getDescription = function() {
return "Make the text color of the \"typing...\" text same as role color";
};
ColoredTyping.prototype.getVersion = function() {
return "1.2.0";
};
ColoredTyping.prototype.getAuthor = function() {
return "Anxeal, Zerebos";
};
//META{"name":"ColoredVoice"}*//
var ColoredVoice = function() {};
ColoredVoice.prototype.data = {};
ColoredVoice.prototype.dataVersion = "1";
ColoredVoice.prototype.defaultData = function() {
return {
version: "1"
};
}
ColoredVoice.prototype.loadData = function() {
// using the same data as ColoredTyping
this.data = (bdStorage.get('ColoredTyping')) ? JSON.parse(bdStorage.get('ColoredTyping')) : {
version: '0'
}
if (this.data.version != this.dataVersion) {
// wew lad we're using a new way to save our data
this.data = this.defaultData();
this.saveData();
};
};
ColoredVoice.prototype.saveData = function() {
bdStorage.set('ColoredTyping',JSON.stringify(this.data));
};
ColoredVoice.prototype.colorize = function() {
var self = this;
$(".containerDefault-7RImuF .avatarContainer-303pFz").siblings().each(function(index) {
var username = $(this).text();
if (self.data[username]) $(this).css("color", self.data[username]);
});
};
ColoredVoice.prototype.decolorize = function() {
$(".containerDefault-7RImuF .avatarContainer-303pFz").siblings().each(function(index) {
$(this).css("color", "");
});
};
// unused
ColoredVoice.prototype.load = function() {};
ColoredVoice.prototype.unload = function() {};
// unused
ColoredVoice.prototype.onMessage = function() {
var username = $(".message .user-name").last().text();
var color = $(".message .user-name").last().css("color");
this.data[username] = color;
this.saveData();
};
ColoredVoice.prototype.start = function() {
this.loadData();
this.colorize();
};
ColoredVoice.prototype.stop = function() {
this.decolorize();
this.saveData();
};
ColoredVoice.prototype.onSwitch = function() {
var self = this;
$('.member-username-inner').each(function(index) {
var username = $(this).text();
var color = this.style.color;
if (color) self.data[username] = color;
});
this.saveData();
this.decolorize();
this.colorize();
};
ColoredVoice.prototype.observer = function(e) {
if (!e.addedNodes.length) return;
var elem = $(e.addedNodes[0])
if (elem.find(".containerDefault-7RImuF").length || elem.find(".avatarContainer-303pFz").length) {
this.decolorize();
this.colorize();
}
if (elem.find(".member-username-inner").length) {
var self = this;
$('.member-username-inner').each(function(index) {
var username = $(this).text();
var color = this.style.color;
if (color) self.data[username] = color;
});
this.decolorize();
this.colorize();
}
};
ColoredVoice.prototype.getSettingsPanel = function() {
return "";
};
ColoredVoice.prototype.getName = function() {
return "Colored Voice";
};
ColoredVoice.prototype.getDescription = function() {
return "Make the text color of the names in the voice channel same as role color";
};
ColoredVoice.prototype.getVersion = function() {
return "1.2.0";
};
ColoredVoice.prototype.getAuthor = function() {
return "Anxeal, Zerebos";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment