//META {"name": "OnlineFriendCount", "source": "https://github.com/Zerthox/BetterDiscord-Plugins/blob/master/v1/OnlineFriendCount.plugin.js"} *//

/**
 * @author Zerthox
 * @version 1.0.5
 * @return {class} OnlineFriendCount plugin class
 */
const OnlineFriendCount = (() => {

	// Api constants
	const {React} = BdApi;

	/** Module storage */
	const Module = {
		Status: BdApi.findModuleByProps("getStatus", "getOnlineFriendCount"),
		Guilds: BdApi.findModule((m) => m.displayName === "Guilds")
	};

	/** Selector storage */
	const Selector = {
		guildsWrapper: BdApi.findModuleByProps("wrapper", "unreadMentionsBar"),
		guilds: BdApi.findModuleByProps("listItem", "friendsOnline")
	};

	/** Storage for Patches */
	const Patches = {};

	// return plugin class
	return class OnlineFriendCount {

		/**
		 * @return {string} Plugin name
		 */
		getName() {
			return "OnlineFriendCount";
		}
		
		/**
		 * @return {string} Plugin description
		 */
		getDescription() {
			return React.createElement("span", {"white-space": "pre-line"},
				"Add the old online friend count back to guild list. Because nostalgia."
			);
		}
		
		/**
		 * @return {string} Plugin version
		 */
		getVersion() {
			return "1.0.5";
		}
		
		/**
		 * @return {string} Plugin author
		 */
		getAuthor() {
			return React.createElement("a", {href: "https://github.com/Zerthox", target: "_blank"}, "Zerthox");
		}

		/**
		 * Log a message in Console
		 * @param {string} msg message
		 */
		log(msg) {
			console.log(`%c[${this.getName()}] %c(v${this.getVersion()})%c ${msg}`, "color: #3a71c1; font-weight: 700;", "color: #666; font-size: .8em;", "");
		}
		
		/**
		 * Plugin start function
		 */
		start() {
			
			// patch guilds render function
			Patches.guilds = BdApi.monkeyPatch(Module.Guilds.prototype, "render", {silent: true, after: (d) => {

				// get return value
				const r = d.returnValue;

				// find scroller
				const l = r.props.children.find((e) => e.type && e.type.displayName === "VerticalScroller").props.children;

				// check if online friends count is not inserted yet
				if (!l.find((e) => e.props && e.props.children && e.props.children.props && e.props.children.props.className === Selector.guilds.friendsOnline)) {

					// insert online friends count before dms
					l.splice(l.indexOf(l.find((e) => e.type && e.type.displayName === "TransitionGroup")), 0,
						React.createElement("div", {className: Selector.guilds.listItem},
							React.createElement("div", {className: Selector.guilds.friendsOnline, style: {"margin": 0}}, `${Module.Status.getOnlineFriendCount()} Online`)
						)
					);
				}

				// return modified return value
				return r;
			}});
			this.log("Patched render of Guilds component");
			
			// force update
			this.forceUpdateAll();
			
			// console output
			this.log("Enabled");
		}
		
		/**
		 * Plugin stop function
		 */
		stop() {

			// revert all patches
			for (const k in Patches) {
				Patches[k]();
				delete Patches[k];
			}
			this.log("Unpatched all");

			// force update
			this.forceUpdateAll();

			// console output
			this.log("Disabled");
		}

		/**
		 * Force update the "Guilds" component state nodes
		 */
		forceUpdateAll() {

			// force update guilds wrapper
			for (const e of document.getElementsByClassName(Selector.guildsWrapper.wrapper)) {
				const i = BdApi.getInternalInstance(e);
				i && i.return.stateNode.forceUpdate();
			}
		}

	}
})();
@@ -179,17 +179,17 @@
 ion 1.0.
-5
+6
 %0A * @ret
@@ -976,69 +976,8 @@
 urn 
-React.createElement(%22span%22, %7B%22white-space%22: %22pre-line%22%7D,%0A%09%09%09%09
 %22Add
@@ -1048,13 +1048,8 @@
 ia.%22
-%0A%09%09%09)
 ;%0A%09%09
@@ -1138,9 +1138,9 @@
 1.0.
-5
+6
 %22;%0A%09
@@ -1222,89 +1222,8 @@
 turn
- React.createElement(%22a%22, %7Bhref: %22https://github.com/Zerthox%22, target: %22_blank%22%7D,
  %22Ze
@@ -1228,17 +1228,16 @@
 Zerthox%22
-)
 ;%0A%09%09%7D%0A%0A%09
@@ -2067,24 +2067,29 @@
 sOnline)) %7B%0A
+%09%09%09%09%09
 %0A%09%09%09%09%09// ins

Fix OnlineFriendCount author & description