BetterFrindCount now uses patching instead of observing
This commit is contained in:
parent
7d53f85d78
commit
4ceac380e3
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
class BetterFriendCount {
|
class BetterFriendCount {
|
||||||
initConstructor () {
|
initConstructor () {
|
||||||
|
this.patchModules = {
|
||||||
|
"TabBar":"componentDidMount",
|
||||||
|
"NameTag":["componentWillMount","componentWillUnmount"]
|
||||||
|
};
|
||||||
|
|
||||||
this.css = `
|
this.css = `
|
||||||
${BDFDB.idCNS.friends + BDFDB.dotCNS.friendstabbaritem + BDFDB.dotCN.badge}:not(.betterfriendcount-badge),
|
${BDFDB.idCNS.friends + BDFDB.dotCNS.friendstabbaritem + BDFDB.dotCN.badge}:not(.betterfriendcount-badge),
|
||||||
${BDFDB.idCNS.friends + BDFDB.dotCNS.friendstabbaritem + BDFDB.dotCN.badgewrapper}:not(.betterfriendcount-badge) {
|
${BDFDB.idCNS.friends + BDFDB.dotCNS.friendstabbaritem + BDFDB.dotCN.badgewrapper}:not(.betterfriendcount-badge) {
|
||||||
|
@ -19,7 +24,7 @@ class BetterFriendCount {
|
||||||
|
|
||||||
getDescription () {return "Shows the amount of total and online friends and blocked users in the friends tab.";}
|
getDescription () {return "Shows the amount of total and online friends and blocked users in the friends tab.";}
|
||||||
|
|
||||||
getVersion () {return "1.0.7";}
|
getVersion () {return "1.0.8";}
|
||||||
|
|
||||||
getAuthor () {return "DevilBro";}
|
getAuthor () {return "DevilBro";}
|
||||||
|
|
||||||
|
@ -45,46 +50,14 @@ class BetterFriendCount {
|
||||||
if (typeof BDFDB === "object") {
|
if (typeof BDFDB === "object") {
|
||||||
BDFDB.loadMessage(this);
|
BDFDB.loadMessage(this);
|
||||||
|
|
||||||
var observer = null;
|
|
||||||
|
|
||||||
observer = new MutationObserver((changes, _) => {
|
|
||||||
changes.forEach(
|
|
||||||
(change, i) => {
|
|
||||||
if (change.addedNodes) {
|
|
||||||
change.addedNodes.forEach((node) => {
|
|
||||||
if (node && node.tagName && node.querySelector(BDFDB.dotCN.friendscolumn)) {
|
|
||||||
this.addCountNumbers();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (change.removedNodes) {
|
|
||||||
change.removedNodes.forEach((node) => {
|
|
||||||
if (node && node.tagName && node.querySelector(BDFDB.dotCN.friendscolumn)) {
|
|
||||||
this.addCountNumbers();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
BDFDB.addObserver(this, BDFDB.idCN.friends, {name:"friendListObserver",instance:observer}, {childList:true, subtree:true});
|
|
||||||
|
|
||||||
observer = new MutationObserver((changes, _) => {
|
|
||||||
changes.forEach(
|
|
||||||
(change, i) => {
|
|
||||||
this.addCountNumbers();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
BDFDB.addObserver(this, BDFDB.dotCN.friendsonline, {name:"friendCountObserver",instance:observer}, {childList:true, subtree:true, characterData:true});
|
|
||||||
|
|
||||||
this.FriendUtils = BDFDB.WebModules.findByProperties("getFriendIDs", "getRelationships");
|
this.FriendUtils = BDFDB.WebModules.findByProperties("getFriendIDs", "getRelationships");
|
||||||
this.UserMetaStore = BDFDB.WebModules.findByProperties("getStatus", "getOnlineFriendCount");
|
this.UserMetaStore = BDFDB.WebModules.findByProperties("getStatus", "getOnlineFriendCount");
|
||||||
var RelationshipTypes = BDFDB.WebModules.findByProperties("RelationshipTypes").RelationshipTypes;
|
let RelationshipTypes = BDFDB.WebModules.findByProperties("RelationshipTypes").RelationshipTypes;
|
||||||
for (let type in RelationshipTypes) {
|
for (let type in RelationshipTypes) {
|
||||||
this.relationshipTypes[RelationshipTypes[type]] = type;
|
this.relationshipTypes[RelationshipTypes[type]] = type;
|
||||||
}
|
}
|
||||||
this.addCountNumbers();
|
|
||||||
|
BDFDB.WebModules.forceAllUpdates(this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
|
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
|
||||||
|
@ -93,30 +66,32 @@ class BetterFriendCount {
|
||||||
|
|
||||||
stop () {
|
stop () {
|
||||||
if (typeof BDFDB === "object") {
|
if (typeof BDFDB === "object") {
|
||||||
document.querySelectorAll(".betterfriendcount-badge").forEach(counter => {counter.remove();});
|
BDFDB.removeEles(".betterfriendcount-badge");
|
||||||
|
|
||||||
BDFDB.unloadMessage(this);
|
BDFDB.unloadMessage(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSwitch () {
|
|
||||||
this.addCountNumbers();
|
|
||||||
|
|
||||||
BDFDB.addObserver(this, BDFDB.idCN.friends, {name:"friendListObserver"}, {childList:true, subtree:true});
|
|
||||||
}
|
|
||||||
|
|
||||||
// begin of own functions
|
// begin of own functions
|
||||||
|
|
||||||
addCountNumbers () {
|
processTabBar (instance, wrapper) {
|
||||||
var friendstabbar = document.querySelector(BDFDB.idCNS.friends + BDFDB.dotCN.friendstabbar);
|
if (instance.props && instance.props.children && instance.props.children[0].key == "ADD_FRIEND") this.addCountNumbers(wrapper);
|
||||||
if (!friendstabbar) return;
|
}
|
||||||
friendstabbar.querySelectorAll(".betterfriendcount-badge").forEach(counter => {counter.remove();});
|
|
||||||
|
processNameTag (instance, wrapper) {
|
||||||
|
if (wrapper.parentElement && wrapper.parentElement.classList && wrapper.parentElement.classList.contains(BDFDB.disCN.friendscolumn)) this.addCountNumbers();
|
||||||
|
}
|
||||||
|
|
||||||
|
addCountNumbers (wrapper = document.querySelector(BDFDB.idCNS.friends + BDFDB.dotCN.friendstabbar)) {
|
||||||
|
if (!wrapper) return;
|
||||||
|
let tabitems = wrapper.querySelectorAll(BDFDB.dotCN.friendstabbaritem);
|
||||||
|
if (!tabitems || tabitems.length < 5) return;
|
||||||
|
BDFDB.removeEles(".betterfriendcount-badge");
|
||||||
|
|
||||||
var relationships = this.FriendUtils.getRelationships(), relationshipCount = {};
|
let relationships = this.FriendUtils.getRelationships(), relationshipCount = {};
|
||||||
for (let type in this.relationshipTypes) {relationshipCount[this.relationshipTypes[type]] = 0;}
|
for (let type in this.relationshipTypes) relationshipCount[this.relationshipTypes[type]] = 0;
|
||||||
for (let id in relationships) {relationshipCount[this.relationshipTypes[relationships[id]]]++;}
|
for (let id in relationships) relationshipCount[this.relationshipTypes[relationships[id]]]++;
|
||||||
|
|
||||||
var tabitems = friendstabbar.querySelectorAll(BDFDB.dotCN.friendstabbaritem);
|
|
||||||
$(`<div class="${BDFDB.disCN.badgewrapper} betterfriendcount-badge friendcount">${relationshipCount.FRIEND}</div>`).appendTo(tabitems[1]);
|
$(`<div class="${BDFDB.disCN.badgewrapper} betterfriendcount-badge friendcount">${relationshipCount.FRIEND}</div>`).appendTo(tabitems[1]);
|
||||||
$(`<div class="${BDFDB.disCN.badgewrapper} betterfriendcount-badge onlinefriendcount">${this.UserMetaStore.getOnlineFriendCount()}</div>`).appendTo(tabitems[2]);
|
$(`<div class="${BDFDB.disCN.badgewrapper} betterfriendcount-badge onlinefriendcount">${this.UserMetaStore.getOnlineFriendCount()}</div>`).appendTo(tabitems[2]);
|
||||||
$(`<div class="${BDFDB.disCN.badgewrapper} betterfriendcount-badge requestincount">${relationshipCount.PENDING_INCOMING}</div>`).appendTo(tabitems[3]);
|
$(`<div class="${BDFDB.disCN.badgewrapper} betterfriendcount-badge requestincount">${relationshipCount.PENDING_INCOMING}</div>`).appendTo(tabitems[3]);
|
||||||
|
|
|
@ -23,6 +23,7 @@ class EditUsers {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-left: 1ch;
|
margin-left: 1ch;
|
||||||
}
|
}
|
||||||
|
${BDFDB.dotCN.friendscolumn} ${BDFDB.dotCN.bottag},
|
||||||
${BDFDB.dotCN.memberusername} ~ ${BDFDB.dotCN.bottag} {
|
${BDFDB.dotCN.memberusername} ~ ${BDFDB.dotCN.bottag} {
|
||||||
top: 0px;
|
top: 0px;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +318,7 @@ class EditUsers {
|
||||||
this.createNoticeTooltip(event);
|
this.createNoticeTooltip(event);
|
||||||
})
|
})
|
||||||
.on("mouseleave", "#input-userurl", (event) => {
|
.on("mouseleave", "#input-userurl", (event) => {
|
||||||
$(BDFDB.dotCN.tooltips).find(".notice-tooltip").remove();
|
BDFDB.removeEles(BDFDB.dotCNS.tooltips + ".notice-tooltip");
|
||||||
$(event.target).removeClass("hovering");
|
$(event.target).removeClass("hovering");
|
||||||
})
|
})
|
||||||
.on("click", ".btn-save", (event) => {
|
.on("click", ".btn-save", (event) => {
|
||||||
|
@ -370,7 +371,7 @@ class EditUsers {
|
||||||
$(e.target)
|
$(e.target)
|
||||||
.removeClass("valid")
|
.removeClass("valid")
|
||||||
.removeClass("invalid");
|
.removeClass("invalid");
|
||||||
if ($(e.target).hasClass("hovering")) $(BDFDB.dotCNS.tooltips + ".notice-tooltip").remove();
|
if ($(e.target).hasClass("hovering")) BDFDB.removeEles(BDFDB.dotCNS.tooltips + ".notice-tooltip");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let request = require("request");
|
let request = require("request");
|
||||||
|
@ -391,7 +392,7 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
createNoticeTooltip (e) {
|
createNoticeTooltip (e) {
|
||||||
$(BDFDB.dotCN.tooltips).find(".notice-tooltip").remove();
|
BDFDB.removeEles(BDFDB.dotCNS.tooltips + ".notice-tooltip");
|
||||||
|
|
||||||
var input = e.currentTarget;
|
var input = e.currentTarget;
|
||||||
var disabled = input.disabled;
|
var disabled = input.disabled;
|
||||||
|
@ -405,7 +406,6 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
processChannelTextArea (instance, wrapper) {
|
processChannelTextArea (instance, wrapper) {
|
||||||
if (!wrapper) return;
|
|
||||||
if (instance.props && instance.props.type == "normal" && instance.props.channel && instance.props.channel.type == 1) {
|
if (instance.props && instance.props.type == "normal" && instance.props.channel && instance.props.channel.type == 1) {
|
||||||
let user = this.UserUtils.getUser(instance.props.channel.recipients[0]);
|
let user = this.UserUtils.getUser(instance.props.channel.recipients[0]);
|
||||||
if (user) {
|
if (user) {
|
||||||
|
@ -416,7 +416,6 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
processNameTag (instance, wrapper) {
|
processNameTag (instance, wrapper) {
|
||||||
if (!wrapper) return;
|
|
||||||
let username = wrapper.parentElement.querySelector("." + (wrapper.classList && wrapper.classList.contains(BDFDB.disCN.userpopoutheadertagwithnickname) ? BDFDB.disCN.userpopoutheadernickname : instance.props.usernameClass).replace(/ /g, "."));
|
let username = wrapper.parentElement.querySelector("." + (wrapper.classList && wrapper.classList.contains(BDFDB.disCN.userpopoutheadertagwithnickname) ? BDFDB.disCN.userpopoutheadernickname : instance.props.usernameClass).replace(/ /g, "."));
|
||||||
this.changeName(instance.props.user, username);
|
this.changeName(instance.props.user, username);
|
||||||
this.changeAvatar(instance.props.user, this.getAvatarDiv(wrapper));
|
this.changeAvatar(instance.props.user, this.getAvatarDiv(wrapper));
|
||||||
|
@ -424,7 +423,6 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
processPopout (instance, wrapper) {
|
processPopout (instance, wrapper) {
|
||||||
if (!wrapper) return;
|
|
||||||
let fiber = instance._reactInternalFiber;
|
let fiber = instance._reactInternalFiber;
|
||||||
if (fiber.return && fiber.return.memoizedProps && fiber.return.memoizedProps.message) {
|
if (fiber.return && fiber.return.memoizedProps && fiber.return.memoizedProps.message) {
|
||||||
let username = wrapper.querySelector(BDFDB.dotCN.messageusername);
|
let username = wrapper.querySelector(BDFDB.dotCN.messageusername);
|
||||||
|
@ -437,7 +435,6 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
processAuditLog (instance, wrapper) {
|
processAuditLog (instance, wrapper) {
|
||||||
if (!wrapper) return;
|
|
||||||
if (instance.props && instance.props.log && instance.props.log.user) {
|
if (instance.props && instance.props.log && instance.props.log.user) {
|
||||||
let hooks = wrapper.querySelectorAll(BDFDB.dotCN.auditloguserhook);
|
let hooks = wrapper.querySelectorAll(BDFDB.dotCN.auditloguserhook);
|
||||||
let guildid = instance._reactInternalFiber.return.memoizedProps.guildId;
|
let guildid = instance._reactInternalFiber.return.memoizedProps.guildId;
|
||||||
|
@ -454,7 +451,6 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
processDirectMessage (instance, wrapper) {
|
processDirectMessage (instance, wrapper) {
|
||||||
if (!wrapper) return;
|
|
||||||
if (instance.props && instance.props.channel && instance.props.channel.type == 1) {
|
if (instance.props && instance.props.channel && instance.props.channel.type == 1) {
|
||||||
let user = this.UserUtils.getUser(instance.props.channel.recipients[0]);
|
let user = this.UserUtils.getUser(instance.props.channel.recipients[0]);
|
||||||
if (user) {
|
if (user) {
|
||||||
|
@ -468,7 +464,6 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
processCallAvatar (instance, wrapper) {
|
processCallAvatar (instance, wrapper) {
|
||||||
if (!wrapper) return;
|
|
||||||
if (instance.props && instance.props.id) {
|
if (instance.props && instance.props.id) {
|
||||||
let user = this.UserUtils.getUser(instance.props.id);
|
let user = this.UserUtils.getUser(instance.props.id);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
@ -485,7 +480,6 @@ class EditUsers {
|
||||||
}
|
}
|
||||||
|
|
||||||
processPrivateChannel (instance, wrapper) {
|
processPrivateChannel (instance, wrapper) {
|
||||||
if (!wrapper) return;
|
|
||||||
if (instance.props && instance.props.user) {
|
if (instance.props && instance.props.user) {
|
||||||
let username = wrapper.querySelector(BDFDB.dotCN.dmchannelname);
|
let username = wrapper.querySelector(BDFDB.dotCN.dmchannelname);
|
||||||
this.changeName(instance.props.user, username.firstElementChild ? username.firstElementChild : username);
|
this.changeName(instance.props.user, username.firstElementChild ? username.firstElementChild : username);
|
||||||
|
@ -670,7 +664,7 @@ class EditUsers {
|
||||||
|
|
||||||
addTag (info, wrapper, selector = "") {
|
addTag (info, wrapper, selector = "") {
|
||||||
if (!info || !wrapper || !wrapper.parentElement || wrapper.classList.contains(BDFDB.disCN.accountinfodetails) || wrapper.classList.contains("discord-tag")) return;
|
if (!info || !wrapper || !wrapper.parentElement || wrapper.classList.contains(BDFDB.disCN.accountinfodetails) || wrapper.classList.contains("discord-tag")) return;
|
||||||
wrapper.querySelectorAll(".EditUsers-tag").forEach((tag) => tag.remove());
|
BDFDB.removeEles(wrapper.querySelectorAll(".EditUsers-tag"));
|
||||||
let data = BDFDB.loadData(info.id, this, "users");
|
let data = BDFDB.loadData(info.id, this, "users");
|
||||||
if (data && data.tag) {
|
if (data && data.tag) {
|
||||||
let member = data.ignoreTagColor ? (this.MemberUtils.getMember(this.LastGuildStore.getGuildId(), info.id) || {}) : {};
|
let member = data.ignoreTagColor ? (this.MemberUtils.getMember(this.LastGuildStore.getGuildId(), info.id) || {}) : {};
|
||||||
|
|
Loading…
Reference in New Issue