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